ID:162393
 
I've seem to have forgotten how to do movement delays... could someone help me out?
Modify the Move() proc. Use a variable to check if you are walking, and return if true.
mob
var/tmp/nextmove = 0
var/movespeed = 5

client
Move() //called when you press a movement key
//check if we can make a movement
if(world.time < mob.nextmove)
//return 0 if we can't
return 0
//otherwise
else
//set the time for our next movement
mob.nextmove = world.time + mob.movespeed
//perform the default action (and return its value)
return ..()
In response to Garthor
That doesn't work >_>
In response to Kaiochao2536
mob/var
canwalk=1
client
Move()
if(usr.canwalk==1)
usr.canwalk=0
sleep(2)
usr.canwalk=1
return ..()



Will this work?
Those others are overcomplicating a simple thing, just use this.
mob/var/moving
mob/Move()
if(!moving)
moving=1
..()
spawn(10) moving=0

[edit] I originally put "var/moving" instead of "mob/var/moving", it was a typo, I see why you all were saying it was "global" and such now.
In response to Dragonn
Garthor's isn't overcomplicated. Not only is it more readable (but that's just a matter of preference, I suppose), it also provides more flexibility (e.g. you can cause a player to freeze in place for a given time by simply changing a variable, once.)

If you meant GohanIdz's, it's basically a flawed version of your example (which was flawed to begin with), but it may be preferable in times because it <code>return</code>s the result at the end of the movement, so you can check if it was successful or not.
In response to Dragonn
Dragonn wrote:
Those others are overcomplicating a simple thing, just use this.
> var/moving
> mob/Move()
> if(!moving)
> moving=1
> ..()
> spawn(10) moving=0


You forgot a rather obvious item, which is returning the value of ..(). That's quite important in a Move() override. Plus, this spawn() method is fairly sloppy.

Garthor's code is cleaner and better. Why in the world would you tell someone to use sloppy, non-working code instead of well-commented, good code?

Lummox JR
In response to Lummox JR
I think the most fun thing about that code right there is that the moving variable is global. So, every second, only one person may move.

Unless if somebody moves and, before that second's up, their mob is deleted. In which case nobody can move.
In response to GohanIdz
Sorry, that was a typo: I used > instead of <, which caused the whole thing to work backwards. I fixed that.
In response to Lummox JR
Lummox JR wrote:
Dragonn wrote:
Those others are overcomplicating a simple thing, just use this.
> > mob/var/moving
> > mob/Move()
> > if(!moving)
> > moving=1
> > ..()
> > spawn(10) moving=0

You forgot a rather obvious item, which is returning the value of ..(). That's quite important in a Move() override. Plus, this spawn() method is fairly sloppy.

Garthor's code is cleaner and better. Why in the world would you tell someone to use sloppy, non-working code instead of well-commented, good code?

Lummox JR

It does work <_<i've been using it for a long time. And it does have ..() in there. I dont understand why you say spawn() is sloppy but your the professional (as far as I know), it takes up only one line whereas sleep would cause usage of two lines, I say mine is better only because: 1) It functions. 2) Its short. Those are the only two aspects of coding I currently value (although I dont know all aspects), shortness and performing its desired function.
<br/> Also .debug profile says that it takes up 0% cpu (rounded) so I dont know how you can get much better.
In response to Dragonn
Well, the main problem I am seeing is that your code is global...meaning only 1 thing can be affected at a time...which is fine for low population games...but it would really suck if you had alot of mobs and users.
In response to Zuglilth
Zuglilth wrote:
Well, the main problem I am seeing is that your code is global...meaning only 1 thing can be affected at a time...which is fine for low population games...but it would really suck if you had alot of mobs and users.

Well my code is per individual, so I think you mean Garthor's code, but you posted under my post so Im guessing you mean my code. But either way, my code works per individual.

[Edit] OH duh! Typo. "mob/var/moving" is what I meant to put, I see what you all are saying now, I better fix it.
In response to Dragonn
Dragonn wrote:
Zuglilth wrote:
Well, the main problem I am seeing is that your code is global...meaning only 1 thing can be affected at a time...which is fine for low population games...but it would really suck if you had alot of mobs and users.

Well my code is per individual, so I think you mean Garthor's code, but you posted under my post so Im guessing you mean my code. But either way, my code works per individual.

Just because you aren't able to read your own code doesn't mean everybody else can't. Zuglilth is entirely correct in pointing out that your variable is global and so only one player is allowed to move each second.