Thread: keypressed
View Single Post
  #8  
Old 04-05-2002, 01:47 AM
mikepg mikepg is offline
Registered User
Join Date: Nov 2001
Location: VA, USA
Posts: 501
mikepg is on a distinguished road
Send a message via AIM to mikepg Send a message via Yahoo to mikepg
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.
__________________
~War Lord Mpg2
Bravo Online's Asst. Staff Manager

"Sittin by the tree, sippin eggnog, waitin on christmas gifts"
Reply With Quote