ID:179196
 
When you hold down an arrow key, the character shoots off in that direction. I was wondering if ne1 could help me with this problem. Thanks, Ryan
ECheese2 wrote:
When you hold down an arrow key, the character shoots off in that direction. I was wondering if ne1 could help me with this problem. Thanks, Ryan

Please describe what you want to do in detail.
Clipped from an Ensya Archive tutorial:

<FONT SIZE=5>Setting Mob Speeds</FONT>
~~~~~~~~~~~~~~~~~~~~~~~
To start with we have a basic movement code as shown here:
<FONT COLOR=silver>
mob/var/walk = 1
mob/Move()
        if(src.walk)
                src.walk = 0
                sleep(10)
                src.walk = 1
        else return
</FONT>This is telling the Move() proc to check and see if the mob's "walk" variable is equal to 1, and if so, set it to 0. Then, sleep() tells the proc to wait for one second (10 ticks), then set the "walk" variable to 1 again.

It does this so that when the mob moves, if the proc is set to 1 then it allows them to move and sets movement to 0 for ten ticks. If the mob tries to move but the "walk" variable equals 0, it will return, or cancel the proc so that the mob will be unable to move. Once the proc sets the "walk" variable back to 1, then they will be able to move again.

Now you get a bit of an option, although it really doesn't make that much difference, but it's up to you anyway. If you introduce the ..() right after the "if(usr.walk)" line, you will have the mob move, then if it tried to move again after that, it won't let it, until the sleep timer runs out and it is allowed to move again. On the other hand, if you put the ..() right after the "usr.walk = 1" line, there will be a delay every time you tell it to move, before the mob actually does anything. Since the latter can often be misinterprited as Lag, I'm going to go with the first case.

<FONT COLOR=silver>
mob/var/walk = 1
mob/Move()
        if(usr.walk)
                ..()
                usr.walk = 0
                sleep(10)
                usr.walk = 1
        else return
</FONT>Now, to add a little more customizability to this proc, I'm going to introduce a new mob variable called "speed". "Speed" effects the delay time between movement, so we'll change the "sleep(10)" into "sleep(speed)" so that the delay time is now equap to the mob's speed variable.

<FONT COLOR=silver>
mob/var/speed = 10 // declare the new variable
mob/var/walk = 1
mob/Move()
        if(usr.walk)
                ..()
                usr.walk = 0
                sleep(speed)
                usr.walk = 1
        else return
</FONT>Now you have a fully functional Move() proc, assuming you also have a walk var, that adds a delay to movement based on the mob's speed variable. So, change the speed variable whenever you want the mob to speed up, or slow down.

~~~~~~~~~~~~~~~~~~~~~~~

This is an alternative format for setting mob speeds, taken from the Byond FAQ, which might be of some use to you if you're looking for a faster, more efficient way to set mob speeds.
<FONT COLOR=silver>
mob/var/tmp/time = 0
mob/var/tmp/delay = 10

mob/Move()
        if (world.time >= next_move_time)
                time = world.time + delay
                return ..()
        else return 0


In response to Foomer
I use something simular to this in RancerZero, but AGI (agility) is coded into the equation too, making people with higher agility move faster, a neat affect :) (Just giving you pointers).
In response to Deadron
Thanks Deadron, but my problem was solved. Since Dantom = Dan and Tom, Are you a dead guy named ron?
In response to ECheese2
ECheese2 wrote:
Thanks Deadron, but my problem was solved. Since Dantom = Dan and Tom, Are you a dead guy named ron?

http://www.deadron.com/Games/DeadName.html
In response to Dreq
This is just the basic ideas. It wouldn't be hard to do:

sleep(speed-agility)

If that's what you needed.
But that's not my problem, that's theirs :oP
In response to Deadron
Hmmm I always thought Deadron was made because your last name is Hayden... and that kinda seems like Haydes (the dude of the underworld -Greek Mythology-, not sure if I spelled it right either). Just seems that Dead would fit in... lol

-Raven-
In response to Raven01
Raven01 wrote:
Hmmm I always thought Deadron was made because your last name is Hayden... and that kinda seems like Haydes (the dude of the underworld -Greek Mythology-, not sure if I spelled it right either). Just seems that Dead would fit in... lol

I just recently found out that when I chose the name Hayden, my ultra-religious-parents from whom I was irrevocably separating assumed it was because it sounded like Hades.

Little did they know it was because of looking through the phone book for the name most phonetically the opposite of Engstrom (five consonents in a row...yuck).