ID:268756
 
client
inactivity()
for(var/mob/M)
M.staminaregen++
if(M.staminaregen>=10)
M.staminaregen=0
M.stamina++
if(M.stamina >= M.maxstamina)
M.stamina = M.maxstamina

_>
I just learned it's not a process, so that won't work.
So, is there anyother way to do that?
Thanks for taking your time to read this post. ;D
Hell Ramen wrote:
> client
> inactivity()
> for(var/mob/M)
> M.staminaregen++
> if(M.staminaregen>=10)
> M.staminaregen=0
> M.stamina++
> if(M.stamina >= M.maxstamina)
> M.stamina = M.maxstamina

_>
I just learned it's not a process, so that won't work.
So, is there anyother way to do that?
Thanks for taking your time to read this post. ;D



Maybe this will work? I never did figure it out but that was a while back..
client
proc
inactivity()
while(src.client.inactivty)
for(var/mob/M)
M.staminaregen++
if(M.staminaregen>=10)
M.staminaregen=0
M.stamina++
if(M.stamina >= M.maxstamina)
M.stamina = M.maxstamina


Try that (Not sure if itll work, untested). If it is totally wrong someone please tell me.
In response to XxDohxX
:o
Then I would have to edit client/New() to make it an infinite loop?
In response to Hell Ramen
Don't listen to his suggestion at all. It is completely useless. First of all, every client would be giving every other mob in the world stamina for every millisecond between moves.

Basically, don't listen to Doh, he has no idea what he's talking about on a 9 post out of 10 basis.
In response to Ter13
Ter13 wrote:
Basically, don't listen to Doh, he has no idea what he's talking about on a 9 post out of 10 basis.


How ironic.

Hohoho...ho...ho.


Da da dush.
I actually use a system that records both loss and gain of stamina over a small period of time. Here's what I tend to do:

mob
var
stamina = 0
max_stamina = 0
activity = 0
proc
stamina_loop()
var/regain = round(src.max_stamina/100)
if(regain<=0)
regain = 1
regain -= round(src.activity/5)
if(src.stamina+regain>src.max_stamina)
src.stamina = src.max_stamina
else if(src.stamina+regain>0)
src.stamina += regain
else
src.stamina = 0
src.activity = 0 //forgot this line
spawn(60)
src.stamina_loop()
Login()
//call stamina loop in login() you don't want NPCs gobbling CPU!
..()
spawn()
src.stamina_loop()


To get the activity variable to change, we have to create an add_activity() procedure, and put it in all procedures that would modify the activity of the player. Let's put it in the move procedure.

mob
proc
add_activity(var/ammount)
src.activity += ammount
Move()
. = ..()
if(.==1)
src.add_activity(0.5)
return .


To make other procedures work, you should put the add_activity() in when you make the procedure. Good luck, I haven't tested this, so if there are bugs, just let me know. I doubt there are any.

I usually don't give out code snippets, enjoy it.
In response to Ter13
._.
It takes away Stamina, let me look over it and see if I can find it.
Thank you.
[Edit]Found it, thanks.
In response to Hell Ramen
Uh... mind running that by me again?
In response to Ter13
Ter13 wrote:
Uh... mind running that by me again?
if(regain<=0)
regain = 1
regain -= round(src.activity/5)

Made the stamina decrease, it was:
regain -= round(src.activity/5)
if(regain<=0)
regain = 1
:o
In response to Hell Ramen
No. You want this to be able to subtract from the stamina. This is your entire stamina system. This handles BOTH the subtraction and the restoration of stamina.
In response to Ter13
I've already made stamina subtraction, by every 7 steps, and by doing it your way, it never regains.
So it'd be forever stuck on -1.
In response to Hell Ramen
No, it always regains. If you look at my code, it regains one percent of your max stamina every 6 seconds, minimum being 1. You wanted this to only regain when the player has not done anything. My method allows it to regain if there has been VERY LITTLE activity relative to the user's stamina.

Though, I did make a mistake with it. I forgot to clear the activity variable. Take a look at it now.
In response to Ter13
Ter13 wrote:
No, it always regains. If you look at my code, it regains one percent of your max stamina every 6 seconds, minimum being 1. You wanted this to only regain when the player has not done anything. My method allows it to regain if there has been VERY LITTLE activity relative to the user's stamina.

Though, I did make a mistake with it. I forgot to clear the activity variable. Take a look at it now.

Well, there was a much shorter way to do it:
mob
proc
regen()
while(1)
sleep(10)
if(client.inactivity/10 >= 1)
src.stamina += 1
if(src.stamina >= src.staminamax)
src.stamina = src.staminamax
In response to Hell Ramen
there is a lot wrong with that procedure.

First: The infinite loop. Infinite loops can make a mess of your game.

Second: You are calling sleep() a lot of regen() procedures running at the same time would cause some lag.

Third: You aren't taking into account any kind of activity. Some people can do less strenuous activities, such as talking or walking, or looking around without losing a lot of energy.

My method was not an absolute, if you don't like it, just say so, it looks like you solved your problem, but you caused about a dozen more potential ones.
In response to Ter13
That was just a test, and it does work. =/
I fixed it up so it works fine.
In response to Ter13
Eh I am trying to guess on the things I dont know and maybe I get them right, so those 9 out of 10 posts you see, I guess. Heh.