ID:139707
 
Code:
            toxic
New()
..()
while(src)
for(var/mob/M in locate(src.x,src.y,src.z))
//make mobs lose health
var/dmg = M.MaxHealth*rand(0,0.1)
if(dmg > 0)
F_damage(M, 10, "#FF0000")
M.Health -= dmg
Update(M)
if(M.deathCheck())
view(M) << "<font color=lime>[M] has died from radioactive poisoning!"
sleep(rand(25,50))


Problem description: The toxic turf is supposed to slowly kill the player if they stay on it. The problem is that the Update proc and the F_damage proc are not working properly (damage isn't flashing above the player and healthbar doesn't go down). However, the player still eventually dies. Those two procs work fine when the player is fighting monsters.

Here is the code for the Update (note, there will be more in the Update proc as I develop the game):
proc
Update(mob/M)
M.Bars(M)

mob
var
tmp/HPB

mob/proc/Bars(mob/M)
if(!M.HPB)
M.HPB=new/obj/overtop/health
if(M.HPB)
M.overlays-=M.HPB
var/obj/overtop/health/O=new/obj/overtop/health
var/Length=20
var/Percent=round(M.Health/M.MaxHealth*Length)
O.icon_state = "[(Percent>Length)?(Length-1):Percent]"
if(Percent<=0)O.icon_state = "0"
M.HPB=O
M.overlays+=M.HPB


What could be the problem? Thanks in advance!
for(var/mob/M in locate(blahblahblah)) should just be for(var/mob/M in src).

rand(0,0.1) will ALWAYS give you 0: rand() between two numbers will only give you an integer.

I don't know why your mobs are dying considering you are never doing any damage to them.
In response to Garthor
rand(0,0.1) will actually equate to rand(0,1) -- BYOND rounds up when needed (even for numbers falling below .5 of the previous whole number).
In response to Garthor
Garthor wrote:
for(var/mob/M in locate(blahblahblah)) should just be for(var/mob/M in src).

rand(0,0.1) will ALWAYS give you 0: rand() between two numbers will only give you an integer.

I don't know why your mobs are dying considering you are never doing any damage to them.

Thanks for explaining rand() to me. I fixed it.

Unfortunately, mobs are still dying and damage is not showing.

Edit: Okay, so I tried putting the damage code from the turf into a separate proc and called it from the turf. Works now.
In response to Nadrew
Actually, I just tested it, and it's weird: rand(0,0.1) actually seems to be 0 90% of the time, and 1 10% of the time.

So I guess the initial error was that no damage was taken most of the time, until eventually the player was just instantly killed.