Another question. How can I track the results of a battle with neutral monsters?
I need a script for Heroes 1 that would check whether certain monsters died or survived after a battle, and depending on the result, allow me to destroy, say, a REGION_ENTER_AND_STOP_TRIGGER, or leave it.
I'm trying to create guardians for teleporters, and given that I already have a lot of teleporters, writing a separate quest for each neutral creature would overload the game.
If it's a random battle, how do I record the results after
function guard_Tilgatal_battle_F(heroname)
local player = GetObjectOwner(heroname)
if(player == 1) then
StartCombat(heroname, nil, 3, 80, 12, 158, 5, 142, 12, nil, nil, nil);
the battle?
And if these monsters are on the map, I don't even know where to attach the script.
To the monsters themselves? It's not clear what to write.
I tried to do something with COMBAT_RESULTS_TRIGGER, but I don't understand how it works, and I don't understand at all if it can be applied to monsters, and not to heroes.
the combatCallback(heroname, result) function will receive the hero's name and the result. If result is nil, the hero lost; if it's not nil, the hero won. You can then create conditions based on this data.
Now, about the random battle. You register a trigger: Trigger(COMBAT_RESULTS_TRIGGER, "MyCombatResultsHandler")
In the MyCombatResultsHandler(combatIndex) function, after any battle, you'll receive a unique battle index – a number that characterizes that specific battle.
In it, you check if(GetSavedCombatResult(combatIndex) == COMBAT_RESULT_WIN) – this means the battle ended with someone winning.
Then, check if(GetSavedCombatArmyPlayer(combatIndex, 0) == PLAYER_NONE and GetSavedCombatArmyPlayer(combatIndex, 1) == 1). GetSavedCombatArmyPlayer(combatIndex, 1/0) is a function that returns the player number, either the loser or the winner. If the second parameter is 0, it's the loser; if you pass 1, it's the winner.
If all the above checks pass, it means your first player fought the neutrals and won.
Now, about how to check for specific killed monsters. First, you need to give them a script name in the editor; I assume you know how.
Then, there are two ways: one is complex, designed for large maps with many such monsters to check, and it will be difficult for you to understand, although it is correct from a programming and logic point of view. The other is simpler.
Let's go with the "simpler" approach, to save time. At the beginning of the map file, create n variables, one for each squad to check, for example:
ALIVE_GUARD_1 = not nil
ALIVE_GUARD_2 = not nil
...
ALIVE_GUARD_N = not nilThen, simply write a bunch of checks like this:
if(ALIVE_GUARD_N == not nil) then
if(IsObjectExists("GUARD_N") == nil) then -- If this passes, it means your guard died.
ALIVE_GUARD_N = nil -- Be sure to indicate that the condition should no longer be checked.
... -- Do your various actions here.
end
endThat's roughly the technology. I don't have ready-made scripts on this topic, so you'll have to figure it out.
To avoid getting lost in the names of the guards, you can create a convenient table instead of that list of variables,
if you know how. If not, explaining it will again take a long time, and it is described in the manual.
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!
Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.