You want this:
Code: Select all
ATT_Retreat = OnCharacterDeath(
function(player, killer)
--only care when dead player is on the ATT team
if GetCharacterTeam(player) ~= ATT then return end
if GetReinforcementCount(ATT) < 50 then
--tell ATT to retreat
ClearAIGoals(ATT)
AddAIGoal(ATT, "Defend", 600, "Russian_retreat")
--stop watching this OnCharacterDeath so we don't waste game resources
ReleaseOnCharacterDeath(ATT_Retreat)
end
end
)
DEF_Retreat = OnCharacterDeath(
function(player, killer)
--only care when dead player is on the DEF team
if GetCharacterTeam(player) ~= DEF then return end
if GetReinforcementCount(ATT) < 30 then
--tell DEF to retreat
ClearAIGoals(DEF)
AddAIGoal(DEF, "Defend", 600, "German_retreat")
--stop watching this OnCharacterDeath so we don't waste game resources
ReleaseOnCharacterDeath(DEF_Retreat)
end
end
)
It may have typos, I didn't check it.
Your original problem was that your code was only running once. You have to put it in an OnCharacterDeath event callback so that every time someone dies, the code is run again.
The AI goal
Follow should give a tighter/faster retreat if
Defend isn't good enough.
You could add in a
ShowMessageText("Run for your lives!", ATT) to tell the humans that the AI are retreating. It would go after adding the new AI goal.