ID:1239898
 
(See the best response by Kozuma3.)
Code:
obj
Amaterasu1
icon = 'Amaterasu.dmi'
density = 1
pixel_x = -4
pixel_y = -4
Bump(A)
if(ismob(A))
var/mob/M = A
var/damage = src.Ninjutsu
if(damage >= 1)
var/mob/O = src.Fowner
M.health -= damage
view(M)<< "<b><font size=1 face=verdana color=red>[M] was hit by [O]'s Amaterasu for [damage] damage!!"
M.overlays+=/obj/AmaterasuBurn/
M.inamat = 1
src.loc=locate(101,101,1)
End
if(M.inamat==0)
M.overlays-=/obj/AmaterasuBurn/
M.inamat = 0
del(src)
return
else
M.health-=M.maxHP/6
M<<"Amateratsu burns your body."

if(M.health>=0)
sleep(60)
goto End

if(M.health<=0)
M.health=0
M.Death(O)
M.overlays-=/obj/AmaterasuBurn/
M.inamat = 0
M.inamat2 = 0
del(src)
return

M.Death(O)




if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)


Problem description:
I've been trying to attach a poison like effect with the projectile. Never got the loop to work. I have no idea where to go from here.
Best response
I myself would make the poison effect its own proc :P
mob/proc/Poison(time,damage)
spawn() while(time)
sleep(10)//1 second
time-=10
src.Health -= damage
So like I'll insert it as M.Poison(something)?
Yes.

M.Poison(60,4)
//6 seconds.
//4 damage per second.
Okei thank you! And that was a really quick reply! xD
Also, you could probably use that procedure for alot more than just poison :P
Ah~ like what? :o Just curious.
Renaming the procedure to Effect, it could be used for Poison, Burn, and other types of harmful effects.
Ah! I see, useful indeed ^^
If ever though, how can I stop it. Like with antidote or extinguish.
In response to Mitz001
You would need a check for that.

Example:
if(!is_poisoned && !is_burned) return 0

// Or a format you may be familiar with (though not as robust):
...
if( (is_poisoned == 0) && (is_burned == 0))
return 0
...continue on...


The ! checks for the values 0, "" and null, which are the false Boolean values in BYOND; true being anything else.


Edit: Another safety check you want to do is that, before starting the loop, check if the person is already poisoned at the beginning. Otherwise that person will get killed a lot faster due to the more damage from the proc being called & running more than once

Ex:
mob/proc/Poisoned()

if(is_poisoned || is_burned) return 0
/*

Stop the procedure if the person is already poisoned/burned.


By the way, that is how you check for true Boolean values:
if(x) == if( x != false ) == if( x == true)

For checking the false values (0, null, ""):
if(!x) == if( x == false ) == if( x!=false)

if() evaluates to see if the statement is true. ! is essentially an inverse of false <--> true

*/


while/for ... // Start constant damaging

if(!is_poisoned && !is_burned) return 0
// Stop the procedure if the person is no longer poisoned nor burned

... do poison stuff ...
To sum it up, setting a mob's stop_effect to true will stop the effect proc on the next recursion.
mob/var/stop_effect=0
mob/var/is_effected=0

mob/proc/Effect(time,damage)
if(is_effected)return
src.is_effected=1
while(time)
sleep(5)
if(stop_effect)break
time-=5
src.health-=damage
src.is_effected=0
src.stop_effect=0
In response to Kozuma3
Going off of the current solutions, it would be best to offer a "delay" argument to sleep by instead of 5 or 10.
In response to Kaiochao
Kaiochao wrote:
Going off of the current solutions, it would be best to offer a "delay" argument to sleep by instead of 5 or 10.

Maybe. Mine was more-so for example.