ID:155468
 
so basically i just made a hp/mp regen proc and figured out i had to add the following under my Login

spawn() Regen()

my problem now is, with the following proc for Regen, it will do one untill max THEN the other depending on which happened first :/

mob/proc
Regen()
while(src.HP<MaxHP)
src.HP+=1
sleep(40)
while(src.MP<MaxMP)
src.MP+=1
sleep(40)
spawn(1)Regen()


would anybody plz tell me How-To make it so both MP/HP will regen simultaneously (not one then the other other)

(like if im already regenerating HP cuz i got hit, but then i use MP, i want it to also start regen the MP while the HP regen is still going too)

hopefully this makes sense to somebody n they can help me out :D

PS:i feel like a forums hog i got one here now, and one in code problems about my item seller xD
This may help you:

http://www.byond.com/members/ BYONDAnime?command=view_post&post=98823

Basically though, I'd extend the restricted_number concept to have regeneration:

restricted_number/regen_number
var/regenerating = 0

reduce(var/number as num)
..()
src.regenerate()

proc/regenerate()
if (!src.regenerating)
src.regenerating = 1
spawn()
while (!src.at_max())
src.increase(1)
sleep(40)
src.regenerating = 0


Then basically, whenever you reduce the person's stat, it will automatically regenerate up to their maximum, then stop as appropriate. Same goes, once you've set up one of these on login, you could make it regenerate by overriding New().

I hope that helps a little.
In response to Stephen001
well ive got no clue how to impliment what youve shown me...

Heres the errors i got and how i set it up

World.dm:87:error: src.regenerating: undefined var
World.dm:88:error: src.regenerating: undefined var
World.dm:90:error: src.at_max: undefined proc
World.dm:91:error: src.increase: undefined proc
World.dm:93:error: src.regenerating: undefined var

mob/proc
regenerate()
if (!src.regenerating)
src.regenerating = 1
spawn()
while (!src.at_max())
src.increase(1)
sleep(40)
src.regenerating = 0


but idk where to put this code u showed me:
restricted_number/regen_number
var/regenerating = 0

reduce(var/number as num)
..()
src.regenerate()
In response to Bordakius
You're meant to read the article I linked ;). I'm afraid I will not give you drop in code, my friend.
In response to Bordakius
What Stephen is saying is that we will not code your game for you. It's your job to learn. And it's clear you're just looking for code here.

As for your issue, you could handle it with a datum, and LummoxJR has a really nifty tutorial that helps understand them too. Here is the link http://www.byond.com/members/ DreamMakers?command=view_post&post=35530 (Yes, you are supposed to READ that too)

An alternative is to use a spawn() Regen proc upon login.

Although in all honesty why we're not storing variables like Hp/Stamina in datums is beyond me.
In response to Stephen001
hehe read the article, cant understand how to use any of that for what im trying to do though, btw the game im making is just for my own personal learning of DM language
so... u could drop me that code if u want :D

Learning by EXAMPLE FTW? :D
In response to Bordakius
Well, the article provides a few pretty good examples here and I've taken you 90% of the way there.

What did you understand from that article?
spawn() allows the code to continue whatever follows it, while the code that's inside spawn() will run almost like it's own procedure. If you look inside spawn() everything will read in the order a normal proc would, if you try reading your code as a computer would, you would notice that first it starts in the while loop, sleeps and heals for a while, and after it's done that, it goes on to the next while loop, which in this case is your MP, once it's done with that loop it will spawn() Regen again.

Hopefully you understood why your HP and MP won't regenerate at the same time. Think of a work around, be weary of mistakes, but don't worry too much if you get stuck on something. Do take note, that once your HP/MP is at full health Regen() will repeat endlessly ever tick, preferably you don't want that, try recalling Regen() when you receive damage and use magic.
couldnt this be abused?

Oh no i'm about to die, relog!?!?