ID:141221
 
Code:Obj/Spell problem
obj
Stupefyspell
icon='Stupefy.dmi'
density=1
Bump(mob/M)
if(istype(M,/mob))
view()<<"[M] has been hit by Stupefy!"
M.Frozen=1
M.HP -= usr.Pwr
sleep(25)
M.Frozen=0
M<<"You can move again!"
DeathCheck()
del(src)
mob
verb
Stupefy()
set category = "Spells"
if(usr.wandon == 0)
usr << "You must equip your Wand to use Spells!"
return 0
if(usr.Cooldown == 1)
usr << "You must wait 5 seconds before using Stupefy again!"
return
view()<<"[usr] says: Stupefy!"
var/obj/A=new/obj/Stupefyspell
A.loc=usr.loc
walk(A,usr.dir,3)
usr.Cooldown = 1
sleep(50)
usr.Cooldown = 0
sleep(30)
del(A)


//The move() proc and vars

mob
var
Frozen = 0
Cooldown = 0

Move()
if(src.Frozen)
usr<<"You cant move!"
return
else
..()


Problem description: This is a snippet of code from my Harry Potter game, 'Original' though. I wanted to code in a Spell that stuns you, and hits you for the usr.Pwr , But the problem is that, when it hits the opponent, the stupefy icon stays untill the sleep(*) is over. Also, when you get hit, You won't be frozen for only 2.5 seconds, but until you relog again. The last problem is that the Health of the one who gets hit doesn't lower. Can anyone help me with this?

The stupefy icon stays there because you don't call for it to be deleted until the sleep ends. A lot of your problems could be fixed by using spawn() instead of sleep(). Reading up on those and understanding the differences is a very good thing.

The most likely reason that the character doesn't unfreeze appropriately is because you call for the Stupefyspell to be deleted 80 ticks after its original cast, so it ends up getting deleted before it finishes its Bump() procedure. Make Bump() call a separate proc for what should happen that won't be abruptly ended by the object being deleted.

ie.
mob/var/tmp/Frozen
mob/proc
frozen()
src.Frozen = 1
spawn(25)
src.Frozen = 0
In response to Zaole
This, and your Stupefy verb will give a runtime error if you call del(a) when a is already deleted because it bumped.

if(a) del(a)