Hello. Please tell me: how do I wait for the end of a playing animation 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 of the battle is that when a unit takes its turn, it applies blindness to a random stack of the player. 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 the attack animation finishes, 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);
endIn other words, the logic works correctly, but how do 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 will be grateful for any information.
while combatReadyPerson() == nil do sleep(1) end