ID:2168409
 
(See the best response by Darker Emerald.)
Code:
area/InfectionZone
icon='InfectionZone.dmi'
name="Airborne Plague"
layer=6
Click()
Text(usr,"An airborne strain of the plague. I better stay clear if I want to stay alive.")
Entered()
if(usr)
InfectionStart()
return


proc/InfectionStart()
if(usr.PlagueProtection<=3)
usr<<"<font color=green><i>The plague infection builds up in your veins."
usr.Infection=TRUE
usr.infectionlevel+=10
usr.PvPFlag = TRUE
spawn(600)
InfectionStart()
if(usr.infectionlevel>=50)
usr.overlays+='InfectionOverlay.dmi'
if(usr.infectionlevel>=100)
sleep(100)
view(6)<<"<font color=green><b>The plague has claimed [usr]."
usr.loc=locate(usr.SpawnPoint)
usr.dir = SOUTH
usr.infectionlevel=0
usr.Infection=FALSE
usr.overlays-='InfectionOverlay.dmi'
usr.PvPFlag = FALSE
InfectionStart(null)


Problem description: Sometimes it works, sometimes it doesn't up until a few days ago. And upon death the player is still infected. I feel like I'm missing something or that the proc isn't properly being canceled.

Sometimes it properly loops, and again sometimes it just won't and kill the player quicker than it should. I have no ideas what's wrong.



Best response
Try this one,

area/InfectionZone
name = "Airborne Plague"
icon = 'InfectionZone.dmi'
layer = 6
Click()
..()
Text(usr, "An airborne strain of the plague. I better stay clear if I want to stay alive.")
Entered(var/atom/movable/A)
..()
if(ismob(A))
var/mob/M = A
M.InfectionStart()

mob

proc/InfectionStart()
if(src.PlagueProtection <= 3)
if(!src.Infection) // If not infected

src.Infection = TRUE
src.PvPFlag = TRUE
src.infectionlevel += 10
src << "<font color=green><i>You have been infected by the plague."

spawn()
while(src.Infection)
src << "<font color=green><i>The plague infection builds up in your veins."
src.infectionlevel += rand(1, 5)

if(src.infectionlevel >= 100)
view(6) << "<font color=green><b>The plague has claimed [src]."
usr.loc = locate(usr.SpawnPoint)
usr.dir = SOUTH
usr.infectionlevel = 0
usr.Infection = FALSE
usr.overlays -= 'InfectionOverlay.dmi'
usr.PvPFlag = FALSE

break

else if(usr.infectionlevel >= 50)
usr.overlays += 'InfectionOverlay.dmi'

sleep(rand(50, 100)) // sleep random of 5 to 10 seconds until next infection gain
else // if already infected add some infection level while walking in the infection zone
src << "<font color=green><i>The plague infection builds up in your veins."
src.infectionlevel += rand(1, 5)
In response to Darker Emerald
That seems to have done it. Thanks!
In response to Darker Emerald
No usr in proc. Ungh.
In response to Kaiochao
Yeah, my fault. Corrected it though. I keep doing it bleh.
Yeah I might have missed to change all his "usr" in his code but try to stick with src from now on Manio.