Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   key combo! (https://forums.graalonline.com/forums/showthread.php?t=134266513)

greggiles 05-25-2012 04:11 PM

key combo!
 
I was looking to step out the regular onKeyPressed(code, key) boundaries.

How would you do a combination, or sequence to preform an action?

example 'A' 'A' 'S' then action is preformed. or
example 'down' 'right' 'A' then action is preformed

so you HAVE to hit the keys in that order for the "if" statement to be true to run the actions after it.

Crow 05-25-2012 06:48 PM

You'll have to cache key strokes for that. For "A A S", start by checking if the player hits A. The next time he hits a key, check if it's "A" again and if the time passed since the last key stroke is not too long (some sort of timeout, up to you). Do that again but this time for the "S". If everything's fine, do whatever you want to do.

DustyPorViva 05-25-2012 07:11 PM

Something like this should work:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.cheatcode = {"A","A","D","S","A","D","D"};
  
this.keycache = new[0];
}

function 
onKeyPressed(code,key) {
  
this.keycache.add(key);
  if (@
this.keycache == @this.cheatcode) {
    
player.chat "Cheat Activated!";
    
onTimeout();
  } else 
setTimer(1);
}

function 
onTimeout() {
  
this.keycache = new[0];


I think the timer in an NPC is a single variable, so in theory this would work. Whenever you hit a key it resets the timer, and you have one second to push the next key before it clears the cache.

cbk1994 05-25-2012 07:13 PM

Quote:

Originally Posted by DustyPorViva (Post 1695609)
I think the timer in an NPC is a single variable, so in theory this would work. Whenever you hit a key it resets the timer, and you have one second to push the next key before it clears the cache.

That's right.


All times are GMT +2. The time now is 01:31 AM.

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