ID:175717
 
Well I basically want to delay attacking. So rather than the player clicking on attack like mad and it attacking like mad it will only attack maybe once per second.
This is the code I've got for attacking so far.
Attack(mob/M in oview(1))
if (usr.Bug2 == FALSE)
if (usr.Hunger > 0)
var/chance = rand(1,M.Speed)
if (chance < usr.Speed)
var/damage = rand(usr.Strength-3,usr.Strength+3) - M.Defence
if (damage <= 0)
damage = 0
s_damage(M, damage, colour = "#FF0000")
usr << "You attack [M]!"
M.Hp -= damage
if (usr.Exp >= usr.ExpNeeded-1)
usr.Level_Up()
M.Death()
else usr << "You missed."
else usr << "Your to hungry to fight."
else usr << "You're forbidden to do this."
It is pretty sloppy :D.
Add a timer variable to the mob... such as var/canattack = 1 Then:
if(canattack == 1)
Attack Code
canattack = 0
sleep(20) // Wait 2 secs
canattack = 1


Also, all those if's such as if (usr.Hunger > 0) why not:
if(usr.Hunger <= 0)
usr << "Too hungry!"
return
Continue with code...

-Nova