ID:167484
 
I need a code that lets you sleep until u decide to get up that wont let you move. I am thinking about using move() and taking and adding a tick that heals 1 hp per second.
You should really make a new thread for separate concepts. ;)

I'll assume you are relying on spawns and sleeps for timing. (I prefer an lifecycle or event loop, but that's a whole new topic. Check out http://developer.byond.com/hub/Deadron/EventLoop for details.)

#define SLEEPING    1
#define JUST_WOKE 2

mob
var/tmp // these vars won't save to file
sleep_flags = 0 /* This var will track 2 flags:
SLEEPING - set is this mob is asleep
JUST_WOKE - set for 15 ticks after the mob woke to let old
sleep cycles finish before starting a new one
If you are unfamiliar with bit flags, you can find introductions at
http://www.byondscape.com/ascape.dmb/UnknownPerson.2005-1231/ or
http://developer.byond.com/hub/sapphiremagus/Bit-Flags.GEM
*/


verb/rest()
if(sleep_flags&SLEEPING) // the mob is asleep
view() << "[src] wakes up."
sleep_flags &= ~SLEEPING // clear the SLEEPING flag
sleep_flags |= JUST_WOKE // set the JUST_WOKE flag
spawn(15) // wait 1.5 seconds
sleep_flags &= ~JUST_WOKE // clear the JUST_WOKE flag
else if(sleep_flags&JUST_WOKE)
src << "You just woke up and don't feel sleepy. Try again in a moment."
else
view() << "[src] goes to sleep."
sleep_flags |= SLEEPING // set the SLEEPING flag
spawn() // start a new execution thread so this proc can return
while(sleep_flags&SLEEPING) // keep looping until they stop sleeping
sleep(10)
if(sleep_flags&SLEEPING) // in case they stop mid cycle
hp = min(hp+1, maxhp)