AI response to situations [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
bobfinkl
Rebel Colonel
Rebel Colonel
Posts: 593
Joined: Sun Jul 13, 2008 9:01 am
Projects :: Lots of unreleased stuff
Games I'm Playing :: Life
xbox live or psn: No gamertag set
Location: The quaint little city gametoast.

AI response to situations [Solved]

Post by bobfinkl »

Well I have a slight dilemma, my script has gone crazy. I'm trying to get my AI to gradually decrease in number and retreat dynamically as bases are captured.

Here is my script:
Hidden/Spoiler:
ATT_Retreat = OnCharacterDeath(
function(player, killer)
--only care when dead player is on the ATT team
if GetCharacterTeam(player) ~= ATT then return end

if GetCommandPostTeam("cp1") ~= DEF then
--tell ATT to retreat
ClearAIGoals(1)
SetUnitCount(1, 30)
AddAIGoal(ATT, "Defend", 800, "cp3")
AddAIGoal(ATT, "Defend", 400, "cp7")
BroadcastVoiceOver("rep_off_com_report_us_overwhelmed", ATT)
BroadcastVoiceOver("rep_off_com_report_enemy_losing", DEF)

--stop watching this OnCharacterDeath so we don't waste game resources
ReleaseOnCharacterDeath(ATT_Retreat)
end
end
)

ATT_Retreat2 = OnCharacterDeath(
function(player, killer)
--only care when dead player is on the ATT team
if GetCharacterTeam(player) ~= ATT then return end

if GetCommandPostTeam("cp3") ~= DEF then
--tell ATT to retreat
ClearAIGoals(1)
SetUnitCount(1, 10)
AddAIGoal(ATT, "Defend", 400, "cp3")
AddAIGoal(ATT, "Defend", 1000, "cp7")
BroadcastVoiceOver("cis_off_com_report_us_overwhelmed", DEF)
BroadcastVoiceOver("cis_off_com_report_enemy_losing", ATT)

--stop watching this OnCharacterDeath so we don't waste game resources
ReleaseOnCharacterDeath(ATT_Retreat2)
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 GetCommandPostTeam("cp1") ~= DEF then
--tell ATT to retreat
ClearAIGoals(1)
AddAIGoal(ATT, "Defend", 500, "cp1")
AddAIGoal(ATT, "Defend", 500, "cp5")
BroadcastVoiceOver("rep_off_com_report_us_overwhelmed", DEF)
BroadcastVoiceOver("rep_off_com_report_enemy_losing", ATT)

--stop watching this OnCharacterDeath so we don't waste game resources
ReleaseOnCharacterDeath(DEF_Retreat)
end
end
)
The game works 100% fine but the functions don't run correctly or in order only the AIGoals seem to have an impact, but unless I can decrease the unitcount it'll be impossible to win from the other side.

Thanks in advance.
Last edited by bobfinkl on Fri Aug 21, 2009 11:31 am, edited 2 times in total.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: AI response to situations

Post by [RDH]Zerted »

I'm not sure exactly how your map runs, but don't people (ATT) normally retreat when they lose a CP not when they gain one and someone dies? Overall the code seems fine. You can stick ShowMessageText("message") lines inside your OnCharacterDeath functions to see ingame when they run.

When you change AI goals, it seems a few bots sometimes don't take up the new orders until they die. You can see this effect by using the FakeConsole to clear all the AI goals. A few bots will continue to fight. A small AI goal of follow will get some of the AI to run to whatever object they are following. That may give a faster retreat.
User avatar
bobfinkl
Rebel Colonel
Rebel Colonel
Posts: 593
Joined: Sun Jul 13, 2008 9:01 am
Projects :: Lots of unreleased stuff
Games I'm Playing :: Life
xbox live or psn: No gamertag set
Location: The quaint little city gametoast.

Re: AI response to situations

Post by bobfinkl »

The AddAIGoals work just fine for some reason, and I used the voiceovers as a way of figuring out whats going on, and they just constantly go off (both CIS and REP VO's), and it's mainly the SetUnitCount's that doesn't work the.

EDIT: I solved it, I had to make sure that both command posts were on the correct team then load all I wanted to happen, now my AI actually act as if they fall back to from each layer of defence and gradually decrease in number.
Post Reply