ID:1974993
 
I'm trying to change a mobs icon states, I have an idle,attack,defend,walk,run icon state. Now my problem is not with walk/run these are called with my movement procs. The problem is with attack/defense/idle/beinghit. I want when a unit attacks to go idle. My solution was to create a timer and check it with a proc, when timer==0 means attack animation is complete and I set icon-state to idle. Is there a better solution??

Also my animations last nearly 1.5 seconds, so if a unit A attacks unit B and unit C attacks unit A at the same time how is this going to be resolved??

Should I just apply damages to both B and A or is it better to wait until attack animation is complete to apply damages and if animation interrupted by another attack no damage is applied??

By the way the fight involves like 600 mobs so most details will not be noticeable.
/mob/var/attacked = null
/mob/verb
Attack()
//this line of code will go into your attack command.
if(attacked)//if the mob attack itll wait until sleep time is complete.
return//return's all futhur action.

flick("animation",src)//changes your icon state to the animation and then back to idle.
src.attacked = 1// sets your attack to 1 so the next attack will be delayed until set back to null

//the rest of the code goes bellow.

sleep(10)//wait's the amount of seconds.

src.attacked = null//sets attack back to null so you can attack again.

your solution , apply damage after and put a cool down between every attack.
Thanks for the help but in my code attack is actually a proc performed by npc's so if I use sleep() code execution halts and waits for that one attack to finish before going to the next attack while I'm trying to achieve parallel attacks. So do I solve that by using spawn() instead of sleep() or is there any problem (asking that cause I've never used spawn before)??
my code is like

proc/MainLoop()
for(var/mob/Soldier/s in world)
s.Cooldown-=1
if(s.Cooldown==0)s.Attack(another mob)
You can use a counter. When you attack, change your icon state, and increment the counter. Then spawn(duration of state) and decrement the counter. Then check if the counter is equal to zero, and if it is, reset the icon state.
In response to Victorqr
Victorqr wrote:
Thanks for the help but in my code attack is actually a proc performed by npc's so if I use sleep() code execution halts and waits for that one attack to finish before going to the next attack while I'm trying to achieve parallel attacks. So do I solve that by using spawn() instead of sleep() or is there any problem (asking that cause I've never used spawn before)??
> my code is like
>
> proc/MainLoop()
> for(var/mob/Soldier/s in world)
> s.Cooldown-=1
> if(s.Cooldown==0)s.Attack(another mob)
>
>
>

spawn() works too.