Skip to content

Current questions and answers regarding the map editor.

User Avatar
#3917
Auto-translated
Markel the Imperor
Is there a direct way to find out the hero's losses in battle?
We set up a trigger:
COMBAT_RESULTS_TRIGGER
In it, we check which hero participated in the battle using
GetSavedCombatArmyHero
We get the units themselves using the functions
GetSavedCombatArmyCreaturesCount
GetSavedCombatArmyCreatureInfo
If the data is not needed immediately, you can save it in an array

Here is an example of the code (losses are recorded in the 'died' variable):
COMBAT_WINNER = 1;
COMBAT_LOSER = 0;
Trigger(COMBAT_RESULTS_TRIGGER, 'CombatResult');

function CombatResult(id)

-- we analyze only for the main hero
if(GetSavedCombatArmyHero(id, COMBAT_WINNER) ~= player_hero) then return end

local n_stacks, creature, count, died;

-- analysis of the losing side
n_stacks = GetSavedCombatArmyCreaturesCount(id, COMBAT_LOSER);
for i = 0,(n_stacks-1) do
creature, count, died = GetSavedCombatArmyCreatureInfo(id, COMBAT_LOSER, i);
-- here you can analyze or save the data somewhere
-- creature - creature ID, count - their number at the beginning of the battle, died - how many died
end;

-- analysis of the winning side
n_stacks = GetSavedCombatArmyCreaturesCount(id, COMBAT_WINNER);
for i = 0,(n_stacks-1) do
creature, count, died = GetSavedCombatArmyCreatureInfo(id, COMBAT_WINNER, i);
end;

end