Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-29-2012, 03:36 AM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
Multiple KeyPresses

Can someone tell me why this won't work? And how to fix it.
I want it so you have to press all three keys for it to do the action.

PHP Code:
//#CLIENTSIDE
function onKeyPressed(codekey)

 if (
key "b"
 {
  if (
key "v")
  {
    if (
key "c")
    {
     
player.chat "Activate";
     }
    }
   }
  } 
Reply With Quote
  #2  
Old 05-29-2012, 04:13 AM
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
The event is only called once per keypress. The variable is not going to change values midway through the function. You'd have to keep track of which keys are being pressed:

PHP Code:
function GraalControl.onKeyDown(temp.codetemp.key) {
  if (! 
this.key.(@ temp.key)) {
    
this.key.(@ temp.key) = true;
    
    if (
temp.key in {"b""v""c"} && this.key.&& this.key.&& this.key.c) {
      
player.chat "combo attack!!";
    }
  }
}

function 
GraalControl.onKeyUp(temp.codetemp.key) {
  
this.key.(@ temp.key) = false;

Also, for comparison, you need to use == instead of =. One equals sign is used only for assignment.
__________________
Reply With Quote
  #3  
Old 05-29-2012, 12:44 PM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
How can I make it use a direction key too? this isn't working. And also, you have to press them one at a time til they are all pressed. You can't hit them at same time for some reason.

PHP Code:
//#CLIENTSIDE
function GraalControl.onKeyDown(temp.codetemp.key) {
  if (! 
this.key.(@ temp.key)) {
    
this.key.(@ temp.key) = true;
    
    if (
temp.key in {"c", (keydown(3)), "v"} && this.key.&& this.(keydown(3)) && this.key.v) {
      
player.chat "combo attack!!";
    }
  }
}

function 
GraalControl.onKeyUp(temp.codetemp.key) {
  
this.key.(@ temp.key) = false;

Reply With Quote
  #4  
Old 05-29-2012, 07:47 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
You're confusing variables/methods/values and would probably benefit from reading a starting guide.

You will have to do the same thing for the arrow keys, either using their 'code' value, or ideally using keydown (so that it uses the key configured by players in the options).

This is obviously not going to work:

PHP Code:
this.(keydown(3)) 
because keydown(3) gets evaluated into either 1 or 0, and then it's checking the value of either this.1 or this.0, which doesn't make any sense.

Instead you'll want to keep track of when the direction keys are pressed.
__________________
Reply With Quote
  #5  
Old 05-31-2012, 12:49 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Wouldn't keydown3 on a timeout be better?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #6  
Old 05-31-2012, 01:48 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Gunderak View Post
Wouldn't keydown3 on a timeout be better?
And why? Its not necessary since you call GraalControl.onKeyDown() everytime the key is pressed and keydown() checks which key has been pressed. Just like
PHP Code:
if (temp.key == "c"
__________________
MEEP!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:13 PM.


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