Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-25-2012, 04:11 PM
greggiles greggiles is offline
Registered User
greggiles's Avatar
Join Date: Sep 2007
Posts: 149
greggiles has a spectacular aura about
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.
Reply With Quote
  #2  
Old 05-25-2012, 06:48 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
Reply With Quote
  #3  
Old 05-25-2012, 07:11 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #4  
Old 05-25-2012, 07:13 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:24 PM.


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