Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Dashing/Running (https://forums.graalonline.com/forums/showthread.php?t=85345)

[email protected] 04-27-2009 07:40 PM

Dashing/Running
 
I've been trying to make a running/dashing for the player, I've managed to do it by holding down a key (which is easy) but I found it difficult if you had to press the two keys in a sequence (pushing right x 2 would make the player sprint), has anyone found a way around this?
thanks

Gambet 04-27-2009 07:59 PM

I suppose you could add a timer for when the player presses a directional button and give them X amount of time to press it again to be considered a double-tap sprint (would need some type of counter that reads if the player has pressed that button before and then run your checks to see if they pressed it fast enough).

Programmer 04-27-2009 08:21 PM

Quote:

Originally Posted by [email protected] (Post 1487173)
I've been trying to make a running/dashing for the player, I've managed to do it by holding down a key (which is easy) but I found it difficult if you had to press the two keys in a sequence (pushing right x 2 would make the player sprint), has anyone found a way around this?
thanks

Suggest you record the number of keystrokes for a certain key in a certain time (using a procedure in onTimeout() perhaps?), and clear it when the time is up. In my coding, I have an array of 256 keystrokes, all set to 0. When a user presses the key, the corresponding keystroke in the array is increased by one. Repeat, until the reset time is reached (usually, I go for about 500 ms). To detect if the user pressed the key twice, simply do if (this.keyStrokes[KeyIdentifier] >= 2) { ... }.

Note, this is probably a more complex explanation than Gambet's. Good luck :)

I'm a bit rusty in my GraalScript, but I created this. It'll give you an idea. Don't critique me on it, I didn't even test it. It should give you an idea though. >_<
PHP Code:

function onCreated()
{
  
// The array of keystrokes, of course.
  
this.keyStrokes = new[0xFF];
  
// How long before the array resets itself.
  
this.keyStrokeTime 500;
  
// Don't touch.
  
this.keyStrokeLastTime 0;
}

function 
onTimeout()
{
  
// Yadda yadda
  
  // Check if 500 milliseconds have passed since the last reset.
  
if ((timevar2 this.keyStrokeTime) > this.keyStrokeLastTime)
  {
    
// Reset!
    
for (temp.0temp.this.keyStrokes.size(); temp.i++) this.keyStrokes[temp.i] = 0;
    
this.keyStrokeLastTime timevar2;
  }
  
  
// Check for any keystroke you need for values equal to or above 2.
  
if (this.keyStrokes[/* whatever key code you want to check here */] >= 2)
  {
    
// Dash code here
  
}
  
  
// Yadda yadda
}

function 
GraalControl.onKeyDown(temp.keyCodetemp.keyStringtemp.scanCode)
{
  
// Adds one keystroke to the array.
  
this.keyStrokes[temp.keyCode]++;



Pelikano 04-28-2009 11:58 AM

Zone uses this, right?

[email protected] 04-28-2009 05:57 PM

HTML Code:

function onKeyPressed() {
  for (temp.k = 0; temp.k < 4; temp.k++;) {
    if (!keydown(temp.k)) continue;

    this.("dash_" @ temp.k)++;
    if (this.("dash_" @ temp.k) =>
2) {
      player.chat = "Doing Dash!" SPC this.("dash_" @ temp.k);
    }
      //Clear the attempt... this.("dash_" @ temp.k) = null;
    scheduleevent(0.1, "onResetDash", temp.k);
    break;
  }
}

Should work, but the onKeyPressed is being sent about 30 times during this procedure.... x-x

[email protected] 04-28-2009 06:29 PM

Quote:

Originally Posted by Chompy (Post 1487419)
Use GraalControl.onMouseDown() and GraalControl.onMouseUp()?

hmm- I mean the keys not mouse. =O

Chompy 04-28-2009 06:39 PM

Quote:

Originally Posted by [email protected] (Post 1487423)
hmm- I mean the keys not mouse. =O

Oh sorry, I have no idea why I posted that o.o

Anyways, onKeyPressed() goes into a loop if you hold down the key if I'm not wrong.

I was thinking of these btw :p


function GraalControl.
NPC Code:

onKeyDown(keycode,keystring,scancode) - a key has been pressed while the control had the input focus (makeFirstResponder())
onKeyUp(keycode,keystring,scancode) - the key has been released


[email protected] 04-28-2009 07:48 PM

HTML Code:

function GraalControl.onKeyDown(keycode) {
  if (timevar2 < this.keydash) {
    if (player.olddir == player.dir) {
      player.movemode = WALKDASH;
    }
  }
}

function GraalControl.onKeyUp() {
  this.keydash = timevar2 + 0.1;
}

With the movement system I am using, it works a charm. Thanks Chompy =D


All times are GMT +2. The time now is 01:27 PM.

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