Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   keydown||pressed (https://forums.graalonline.com/forums/showthread.php?t=55824)

xAndrewx 10-27-2004 04:36 PM

keydown||pressed
 
Well, I was wondering if there is a way to check if the player presses a specific button down twice..
How would I do this?

Like if they press up once and then press it again they start running etc

thx

R0bin 10-27-2004 05:09 PM

Just check for the key and count to see if it were pressed twice, but you'd need to reset it if they didnt press the key again after a certain amount of time.

xAndrewx 10-27-2004 06:07 PM

How would I check to see if they pressed it twice?

Set a flag the first time and do a statement checking if it's already pressed?

I'm also a bit confused on how to check after a period of time, would I use a timeout throughout the script?

Slash-P2P 10-27-2004 09:20 PM

This probably isnt the best way...but...
NPC Code:

//#CLIENTSIDE
if (created || initialized) { // Main block
setstring this.key,a; // Key that can be hit twice [needs different script for arrow keys]
this.time = .3; // Time before the pressed thing expires.
timeout = .05; // Start our loop!
}
if (timeout) { // Self explanitory...
timeout = .05; // Timeout loop
if (this.presstime > 0) { // See how long since you pressed the key
this.presstime -= .05; // Take time out of the variable
} else {
this.presstime = 0; // Make sure we dont have negative time
if (this.pressnumber > 0) this.pressnumber = 0; // Timed out
}
if (keydown2(keycode(#s(this.key)),true)) { // Check if our key is pressed
if (this.keydown == false) { // Only work if the key is not held down
this.keydown = true; // Tell the script the key is held down
if (this.pressnumber == 0) { // Do stuff if number is this blah blah
this.pressnumber = 1; // set the pressed index to 1
this.presstime = this.time; // Time before key pressed resets
} else {
this.pressnumber=0; // Reset press index
this.presstime = 0; // Reset press time
doactions(); // Output
}
}
} else {
this.keydown = false; // Say its not being held down anymore
}
}
function doactions() { // Code for what happens when you hit a key twice.
setplayerprop #c,I hit a key twice! I'm a genious!; // omg kid, you rock!
}



Heres something I thought might help...I don't know if this works, I didn't test it.

Edit:
Tested it and fixed bugs.

xAndrewx 10-27-2004 11:07 PM

Ah!, thanks for the definitions too, you've really helped me :)!

Thanks again

Slash-P2P 10-28-2004 12:51 AM

Quote:

Originally Posted by xAndrewx
Ah!, thanks for the definitions too, you've really helped me :)!

Thanks again

If your going to use that for arrow keys, your going to have to change it a lot. You should be able to change it to arrow keys by putting a for loop in there with keydown.

xAndrewx 10-28-2004 10:25 AM

Ah, okay :)

I havn't tested it myself yet, but I will do when I get home, i'll also play with it like you've said.

Slash-P2P 10-28-2004 07:26 PM

Quote:

Originally Posted by xAndrewx
Ah, okay :)

I havn't tested it myself yet, but I will do when I get home, i'll also play with it like you've said.

I tested it and the script I gave you works.

R0bin 10-29-2004 03:48 AM

Quote:

Originally Posted by Slash-P2P
This probably isnt the best way...but...
NPC Code:

snip code



Heres something I thought might help...I don't know if this works, I didn't test it.

Edit:
Tested it and fixed bugs.

Quote:

Originally Posted by Lance
2) Likewise, don't post whole scripts for people. Post wordy solutions, certainly, but not things that people can just copy & paste into their levels without any effort.

^^

xAndrewx 10-29-2004 03:23 PM

It was a example, I needed help.

Dach 10-29-2004 10:52 PM

it's too bloated for real use anyway (granted that's not the point of the rule)

hey, why is R0bin back?

Slash-P2P 10-29-2004 11:54 PM

Bloated? Yeah I'm sure you could shorten it but I wouldn't use the term 'Bloated'.

xAndrewx 10-30-2004 11:26 AM

I'll be editing it majorly anyway :)
I'll just say that it's a V 1.0 going through to V 5.0, hopefully.


All times are GMT +2. The time now is 07:08 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.