ID:171875
 
Ok, I'm making a new RPG game and I'm trying to put a "Run" verb in it. I can make the verb and I plan on putting in a "Stamina" stat that has a limit of 100. So normally you have a delay while you're moving and when you turn on "Run" then there isn't any delay which makes the person go faster than usual. And when you turn on "Run" and move while it's on then I want the stamina to decrease and when it is zero then you have the walking delay again.

But I don't know how to put in that the stamina only goes down if you move since I don't want the stamina to decrease when you are standing still... can someone help me out? I know this is probably a newbish question but I have no clue how to do this.
It's all about the Move() procedure! You'll want a few variables as so:

var
Stamina=100
Moving=0
WalkingDelay=5
Status="Walking"
StaminaRecoverRate=2

Then, what you'll want to do is define the Move() procedure to check if you're Status is "Walking", or "Running" and execute the delay.

client/Move()
if(Status=="Walking")
if(!Moving)
Moving++
spawn(WalkingDelay)
..()
Moving=0
else if(Status=="Running")
if(Stamina)
Stamina--
..()

I don't like commenting anything, so you'll have to figure that on your own. >:| Next, you'll want something that replenishes your stamina!

proc/ReplenishStamina(mob/M)
if(M.Stamina<100)
spawn(M.StaminaRecoverRate)
Stamina++
ReplenishStamina(M)

Don't forget to call ReplenishStamina! Perhaps it's best to do it at Login()?

mob/Login()
ReplenishStamina(src)

If you have any questions or concerns, post them here!
In response to JohnReaper
JohnReaper wrote:
Don't forget to call ReplenishStamina! Perhaps it's best to do it at Login()?

mob/Login()
ReplenishStamina(src)

Nope. New().
In response to Garthor
Most people like to have these 'title screens' now-a-days, so Login() would be safer in most cases.
In response to JohnReaper
JohnReaper wrote:
It's all about the Move() procedure! You'll want a few variables as so:

var
Stamina=100
Moving=0
WalkingDelay=5
Status="Walking"
StaminaRecoverRate=2

Then, what you'll want to do is define the Move() procedure to check if you're Status is "Walking", or "Running" and execute the delay.

client/Move()
if(Status=="Walking")
if(!Moving)
Moving++
spawn(WalkingDelay)
..()
Moving=0
else if(Status=="Running")
if(Stamina)
Stamina--
..()

I'd just like to point out that when you call ..() in Move(), you're supposed to use the return value. .=..() is the correct way to do that.

It's also worth pointing out that you should have called .=..() before the spawn(), not after.

Also your Stamina test is brittle. It should be if(Stamina>0) instead. And in fact, this test should occur before all others, because you'll want to revert to walking state if stamina runs out.

Here's a better way to do that.
mob
var/nextmovetime

Move()
if(Status == "Running")
if(Stamina-- > 0)
return ..()
Status == "Walking"
// walking from here out
if(nextmovetime && world.time < nextmovetime)
return // do not move
. = ..()
if(.)
nextmovetime = world.time + WalkingDelay
The spawn() is well-intentioned but you don't actually need it. A simple timing var does the trick.

Lummox JR
In response to Lummox JR
There's Lummox with the optimizing! Be sure to take all his advice into account, as he would smite you if you didn't. >;-S
In response to JohnReaper
Login() doesn't get called for NPCs.
In response to Garthor
You wouldn't think the average new BYONDer would have the creativity for something so simple.
In response to JohnReaper
That doesn't even make sense.
In response to Garthor
Oddly it didn't include the whole post! What I meant to say was that many people don't think of making their NPCs even move, let alone having them toggle through running and walking in certain circumstances. Therefore clueing out having NPCs replenish their stamina unless it has another use not mentioned.
In response to JohnReaper
k...
Thx guys for ur help! ^_^
I didn't even know Move() existed! ^_^
here is the code i made... i dont know if it works cuz i cant test it yet since i didnt finish the title screen.

var
Stamina= 100 //The default stamina
Moving=0 //Tells if you are moving or not
WalkingDelay= 4 //How much delay you want in your speed
Status="Walking" //So you normally walk until you want to run
StaminaRR= 2 //How fast your stamina recovers


client/Move() //When you move...
if(Status=="Walking") //If you are walking...
if(!Moving)
Moving++
spawn(WalkingDelay) //Then you have a delay in your walking speed
..()
Moving=0
else if(Status=="Running") //Or if you are running
if(Stamina)
Stamina-- //Then subtract stamina
..()


proc/ReplenishStamina(mob/M) //A proc to recover stamina
if(M.Stamina<100) //If your stamina is lower than 100...
spawn(StaminaRR) //Then recover your stamina
Stamina++
ReplenishStamina(M)

proc/Tired(mob/M) //A proc to stop running if you are too tired
if(M.Stamina<1) //If your stamina is less than 1...
usr << "You are too tired to run!" //Tell the user you are too tired...
Status= "Walking" //and start walking.

mob/verb/Run(mob/M) //An action to run.
set category= "Actions" //Put it into the actions category
if(Status=="Walking") //If you were walking before you pressed on "Run"...
usr << "You start running!" //Tell the user that he starts running
Status= "Running" //Then start running
else if(Status=="Running") //Or if you were running before you pressed on "Run"...
usr << "You stop running!" //Tell the user that he stops running
Status= "Walking" //And start to walk
In response to JohnReaper
That wasnt really Optimizing, that was fixing :P. LummLumm was right.
In response to Teal687
Teal687 wrote:
proc/ReplenishStamina(mob/M)  //A proc to recover stamina
if(M.Stamina<100) //If your stamina is lower than 100...
spawn(StaminaRR) //Then recover your stamina
Stamina++
ReplenishStamina(M)

proc/Tired(mob/M) //A proc to stop running if you are too tired
if(M.Stamina<1) //If your stamina is less than 1...
usr << "You are too tired to run!" //Tell the user you are too tired...
Status= "Walking" //and start walking.

Both of those are wrong.

Both procs should be implemented as mob/proc instead of just regular procs, and you should ditch the M argument because you don't need it. Instead of M within the proc, you'd just use src.

And the second proc should not have usr in it. You made the mistake of saying "the user", which got you in the mindset of thinking usr is always "the player". Problem is, there is no "the player" in a multiplayer game environment; there's "a player". src was still the correct choice there, not usr.

The best rule of thumb to follow is: No put usr in proc. Ungh.

Lummox JR
In response to Lummox JR
var
Stamina= 100 //The default stamina
Moving=0 //Tells if you are moving or not
WalkingDelay= 4 //How much delay you want in your speed
Status="Walking" //So you normally walk until you want to run
StaminaRR= 2 //How fast your stamina recovers


client/Move() //When you move...
if(Status=="Walking") //If you are walking...
if(!Moving)
Moving++
spawn(WalkingDelay) //Then you have a delay in your walking speed
..()
Moving=0
else if(Status=="Running") //Or if you are running
if(Stamina)
Stamina-- //Then subtract stamina
..()


proc/ReplenishStamina(mob/proc) //A proc to recover stamina
if(Stamina<100) //If your stamina is lower than 100...
spawn(StaminaRR) //Then recover your stamina
Stamina++
ReplenishStamina()

proc/Tired(mob/proc) //A proc to stop running if you are too tired
if(Stamina<1) //If your stamina is less than 1...
src << "You are too tired to run!" //Tell the user you are too tired...
Status= "Walking" //and start walking.

mob/verb/Run(mob/M) //An action to run.
set category= "Actions" //Put it into the actions category
if(Status=="Walking") //If you were walking before you pressed on "Run"...
src << "You start running!" //Tell the user that he starts running
Status= "Running" //Then start running
else if(Status=="Running") //Or if you were running before you pressed on "Run"...
src << "You stop running!" //Tell the user that he stops running
Status= "Walking" //And start to walk

This good?
In response to Teal687
No! You have mob/proc in a few arguments! BAD.
In response to JohnReaper
...
...
...
then can someone fix it pls? ^_^
In response to Teal687
You can fix it yourself, I'll tell you the problem, what to do. If you get spoon-fed all the time, then you won't learn.
In the arguments of your procedures (inside the brackets is where you put your arguments), you shouldn't have "mob/proc". Simply use a different variable name for mob.