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.
ID:171875
![]() Jul 29 2004, 4:24 pm
|
|
JohnReaper wrote:
Don't forget to call ReplenishStamina! Perhaps it's best to do it at Login()? Nope. New(). |
JohnReaper wrote:
It's all about the Move() procedure! You'll want a few variables as so: 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 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
|
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.
|
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 |
Teal687 wrote:
proc/ReplenishStamina(mob/M) //A proc to recover stamina 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 |
var This good? |
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!