Hello. Could you please tell me how to wait for a playing animation to finish in a combat script?
Is it necessary to run the animation in a separate thread, or can it be run in the main thread?
The idea for the battle is that when a unit takes its turn, it applies blindness to a random stack of the player's units. The necessary checks for applicability are performed before calling this function. The problem is that the following happens: the unit moves, then the movement animation is interrupted, it starts the casting animation, and the casting animation is interrupted before it finishes, followed by the attack animation, if the unit initially planned to attack the player's stack.
Here is the code for the functions used:
function Cast(unit, target)
combatSetPause(not nil);
CastBlindForFree(unit, target);
playAnimation(target, 'hit', ONESHOT_STILL);
table.insert(blind_array, target);
combatSetPause(nil);
return not nil
end
function CastBlindForFree(caster, target)
SetUnitManaPoints(caster, 100);
local mana_before_cast = GetUnitManaPoints(caster);
repeat sleep(1) until(GetUnitManaPoints(caster) == 100);
UnitCastAimedSpell(caster, SPELL_BLIND, target);
sleep(4);
SetUnitManaPoints(caster, mana_before_cast);
repeat sleep(1) until(GetUnitManaPoints(caster) == mana_before_cast);
end
In other words, the logic works correctly, but how can I synchronize the animations so that they play sequentially, and the main game animations do not interrupt the casting animation?
Thank you very much for your time and attention to reading the question; I would be grateful for any information.