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 04-27-2009, 07:40 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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
Reply With Quote
  #2  
Old 04-27-2009, 07:59 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
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).
Reply With Quote
  #3  
Old 04-27-2009, 08:21 PM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by [email protected] View Post
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]++;

__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #4  
Old 04-28-2009, 11:58 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Zone uses this, right?
Reply With Quote
  #5  
Old 04-28-2009, 05:57 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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
Reply With Quote
  #6  
Old 04-28-2009, 06:29 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Quote:
Originally Posted by Chompy View Post
Use GraalControl.onMouseDown() and GraalControl.onMouseUp()?
hmm- I mean the keys not mouse. =O
Reply With Quote
  #7  
Old 04-28-2009, 06:39 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by [email protected] View Post
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


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

__________________
Reply With Quote
  #8  
Old 04-28-2009, 07:48 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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
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 12:26 PM.


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