Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Multiple KeyPresses (https://forums.graalonline.com/forums/showthread.php?t=134266534)

blackbeltben 05-29-2012 03:36 AM

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";
     }
    }
   }
  } 


cbk1994 05-29-2012 04:13 AM

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.

blackbeltben 05-29-2012 12:44 PM

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;



cbk1994 05-29-2012 07:47 PM

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.

Gunderak 05-31-2012 12:49 PM

Wouldn't keydown3 on a timeout be better?

callimuc 05-31-2012 01:48 PM

Quote:

Originally Posted by Gunderak (Post 1696049)
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"



All times are GMT +2. The time now is 10:26 AM.

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