Aller au contenu

Photo

How to tell if the player (or creature) is moving?


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
FergusM

FergusM
  • Members
  • 460 messages
I'm trying to figure out a way to tell in scripting if a creature is currently moving. Preferably I'd also be able to break it down by running vs walking.

I was thinking about using GetCommandByIndex(0) but the description says this will be the command at the top of the queue that is not yet being run; I need to tell if the command currently being done is a move. Furthermore, I'm not sure how movement controlled by WASD ties into this; is it a constant stream of commands each unit of time that W is held down?

An approach I'm thinking about is using the creature script and each time EVENT_TYPE_COMMAND_PENDING is fired, check if it's a walk/run and if so setting a flag on the creature. Then when EVENT_TYPE_COMMAND_COMPLETE fires, I unset the flag. Is PENDING fired just before the command starts, or when it is first issued?

#2
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages
I have never tried it, but there is a function called
IsMoving()

Modifié par _L_o_B_o_, 03 août 2010 - 10:26 .


#3
FergusM

FergusM
  • Members
  • 460 messages
Ah yes, I forgot about that. Doesn't seem to distinguish between running and walking though.

#4
yamaeda

yamaeda
  • Members
  • 1 messages
Could it use a parameter, like IsMoving(run)?

#5
FergusM

FergusM
  • Members
  • 460 messages
It just takes the creature as a parameter and the return type is true/false.

#6
Languard

Languard
  • Members
  • 126 messages
Hmm, just brainstorming, but once IsMoving returns true, you could grab the location, wait for 1-2 heartbeats, and grab the new location. If the delta is > than the walk distance, then it was running. Not sure how easy/hard this would be to script though.

#7
FergusM

FergusM
  • Members
  • 460 messages
I've contemplated doing this, but it is a little messy, especially if the player is running in circles. :P (or running stop start, etc).