Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   keypressed (https://forums.graalonline.com/forums/showthread.php?t=26941)

amonrabr 04-04-2002 08:42 AM

keypressed
 
I know, its easy use: "for" with oldkeys arrays to make "keypressed" and not keydown..
But the graal should have something fast as:
"if(keypressed(i)) blah blah blah"

Slaktmaster 04-04-2002 08:47 AM

Why?

royce 04-04-2002 08:58 AM

Re: keypressed
 
Quote:

Originally posted by amonrabr
I know, its easy use: "for" with oldkeys arrays to make "keypressed" and not keydown..
But the graal should have something fast as:
"if(keypressed(i)) blah blah blah"

So basically you want keypressed instead of keydown? I think your insane. Just think of it as another language.

amonrabr 04-04-2002 11:14 AM

¬¬'' ..no comments...
:rolleyes:

Keypressed you have to RELEASE the key!!!

try this script and u will understand..
timeout=.05;
if (keydown(5)&&this.mode==0){this.mode=1}
if (keydown(5)&&this.mode==1){this.mode=0}
if (this.mode==1){setplayerprop #c,1;}else setplayerprop #c,2;

I wanna press S and say 1.. if I press S again say 2.. but the timeout is too fast and will be showing {1,2,1,2,1,2,1,2,1... very fast}..
There is an easy way to do release keys..

setarray this.key,10;
setarray this.oldkey,10;
for (i=0;i<10;i++)
{this.key[i]=this.oldkey[i];
this.oldkey[i]=keydown(i);}

¬¬'' Did u get now???
Did u see somewhere menus where you press D to open, S to the first choise and A to the second choise? the guy that made it didnt know the script that I said..

royce 04-04-2002 12:16 PM

Quote:

Originally posted by amonrabr
¬¬'' ..no comments...
:rolleyes:

Keypressed you have to RELEASE the key!!!

try this script and u will understand..
timeout=.05;
if (keydown(5)&&this.mode==0){this.mode=1}
if (keydown(5)&&this.mode==1){this.mode=0}
if (this.mode==1){setplayerprop #c,1;}else setplayerprop #c,2;

I wanna press S and say 1.. if I press S again say 2.. but the timeout is too fast and will be showing {1,2,1,2,1,2,1,2,1... very fast}..
There is an easy way to do release keys..

setarray this.key,10;
setarray this.oldkey,10;
for (i=0;i<10;i++)
{this.key[i]=this.oldkey[i];
this.oldkey[i]=keydown(i);}

¬¬'' Did u get now???
Did u see somewhere menus where you press D to open, S to the first choise and A to the second choise? the guy that made it didnt know the script that I said..

I understand now.;) Need to explain more thorough next time ;) . Can't you withdo with what we have already...? I think what we have now is enough rather than a keypress.

AlexH 04-04-2002 01:08 PM

couldnt you just do while (keydown(#)) {stuff}

Spanko 04-04-2002 07:19 PM

Not necesarry, so I see no real point in adding it.

mikepg 04-05-2002 01:47 AM

umm
 
from what I read....

you have a problem of going straight from one number to the other...having an "if (keypressed(#))" wont solve anything, because that would be a one-time action that is sent, like playerchats.

If youve ever done
NPC Code:

if (timeout) {
if (playerchats) {message AHH!;
}
timeout = .1;
}



You'll notice nothing ever happens when you speak...because the chance of the player chatting at the right time (when the timeout loop reaches the IF), are like 1 billion to 1, so if (keypressed(#)) wont work for that reason.

but, to make it so the player doesnt need to have 0.05 second reflexes, you can add a function, like:
NPC Code:

if (timeout) {
if (keydown(5)) { modechange();
}
timeout = 0.5;
}

function modechange() {
this.mode=1-this.mode;
sleep .5;
}


*Note : this can be done without a function, but functions are more organized*
that way the program only waits when a key is pressed...or...you can do this:

NPC Code:

if (timeout) {
if (this.wait>0) this.wait-=1;
if (keydown(5)&&this.wait=0) {this.mode=1-this.mode; this.wait=10;}
timeout = 0.05;
}



that will make it so the NPC will not respond to the s key until .5 seconds have passed since the last press.

konidias 04-05-2002 01:15 PM

Yes, it's called using timers and making a wait variable. That is how most all the scripts are done that use keydown in that manner.

I thought this was a topic for like, if a key is being held down, as that might be more useful for key combinations of things.. like for example, the ingame inventory dropping system (holding S and pressing A to cycle through items) That might be more helpful, even though it's possible to do anyway.

There are lots of commands that would be helpful, but most all commands that people request can be done with the current scripting, plus you get the advantage of being able to do more things with a script then having a simple command that is limited to certain things.

Kaimetsu 04-05-2002 02:31 PM

Quote:

Originally posted by konidias
Yes, it's called using timers and making a wait variable. That is how most all the scripts are done that use keydown in that manner.
:confused:

I know I've never done it that way. I can't even imagine what you're describing.

Spanko 04-05-2002 06:19 PM

Quote:

Originally posted by Kaimetsu


:confused:

I know I've never done it that way. I can't even imagine what you're describing.

NPC Code:
if (created||timeout) {
if (keydown(4)&&this.temp==0) {
this.bleh=1-this.bleh;
this.temp=1;
}
else this.temp=0;
timeout=0.05;
}

Is what he means. Probably.


All times are GMT +2. The time now is 03:49 AM.

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