Brave but dumb, the AI are. [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.

Brave but dumb, the AI are. [Solved]

Post by bobfinkl »

So I've been messing around with AI properties for a while trying to get them to do things that real soldiers would do, and I thought they would run away if enough of their comrades died right? So I went ahead and made a script to give them to "defend" an object outside the maps boundary, and whaddaya know they didn't run.

Here is my script:

Code: Select all

    ATT_ReinforcementCount = GetReinforcementCount(ATT)
    if ATT_ReinforcementCount < 50 then
        AddAIGoal(ATT, "Defend", 600, "Russian_retreat")
    end

    DEF_ReinforcementCount = GetReinforcementCount(DEF)
    if DEF_ReinforcementCount < 30 then
        AddAIGoal(DEF, "Defend", 200, "German_retreat")
    end
Nothing in the error log is there that wasn't there before, the "German_retreat" and "Russian_retreat" are objects on the map (a yavin object I placed underground and set to be on the side that would retreat to them) that I named that.

Thanks in advance.
Null_1138
Jedi
Jedi
Posts: 1192
Joined: Thu Oct 16, 2008 4:05 pm

Re: Brave but dumb, the AI are.

Post by Null_1138 »

Very ingenious, but I don't know why it wouldn't work. Would your answer lie in the Kashyyyk campaign script? Or was that retreat fudged?
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Brave but dumb, the AI are.

Post by AQT »

Most likely fudged; they all were killed and then respawned behind the fort.
MercuryNoodles
Jedi
Jedi
Posts: 1003
Joined: Sun Mar 12, 2006 7:16 pm
Projects :: Space - Boarding Action
xbox live or psn: No gamertag set

Re: Brave but dumb, the AI are.

Post by MercuryNoodles »

This is just a suggestion, since I don't really do scripting, but maybe you should clear or delete the other AI goals for the team in question, so that the defend goal for the retreat carries all of the weight. As far as I can tell, so long as a goal has any weight, the AI will be assigned to that goal.

It also might be worth it to try changing the CP strategic values via the script as well. The docs don't seem to state specifically, but it appears these values determine what priorites are given to attacking and defending the individual CPs.
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: Brave but dumb, the AI are.

Post by bobfinkl »

AQT wrote:Most likely fudged; they all were killed and then respawned behind the fort.
Actually it wasn't, the AI were given an objective to "Defend" the refinery objects and I'm trying to get the AI to do the same to objects outside the boundary.

MercuryNoodles I doubt the 2nd thing you suggested would work, but perhaps clearing the AI goals would give me a tip as to what the problem is.
YaNkFaN
Field Commander
Field Commander
Posts: 943
Joined: Sat Dec 13, 2008 8:17 am

Re: Brave but dumb, the AI are.

Post by YaNkFaN »

do the objects have health or are they just props i'm not sure AI defend just props (maybe they're smarter than you think) because if you were told to defend something that couldn't be destroyed or captured would you do it...

I'm trying to say that the only things in BF2 that have an AI defend goal attached to them is destructable things or flags (in ctf and 1flag) maybe possibly giving those objects (german retreat and russian retreat health's (probably a huge one like 1000000) the AI may be more responsive
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: Brave but dumb, the AI are.

Post by bobfinkl »

That is probably true, but I've found the main source of the problem. I'm 80% sure that the problem is that you can't constantly get the reinforcement count of a team, and I have no way that I can think of that would trigger it to go off when it reaches the number of reinforcements.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Brave but dumb, the AI are.

Post by Frisbeetarian »

Use OnCharacterDeath and check the reinforcements inside it.
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: Brave but dumb, the AI are.

Post by bobfinkl »

Sorry for my lack of knowledge I haven't scripted in a long time so I'm a bit rusty. Could you write out the code for me?
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Brave but dumb, the AI are.

Post by Fiodis »

I'm only a newbie at this myself, but something along the lines of:

Code: Select all

OnCharacterDeath(
function (player, killer)
GetReinforcementCount (team)
end
)
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: Brave but dumb, the AI are.

Post by bobfinkl »

Still doesn't work, again nothing in the error log that wasn't there before.

Here is my code:
Hidden/Spoiler:
OnCharacterDeath(
function (player, killer)
ATT_ReinforcementCount = GetReinforcementCount(ATT)
end
)

if ATT_ReinforcementCount < 50 then
ClearAIGoals(ATT)
--AddAIGoal(ATT, "Defend", 600, "Russian_retreat")
end

OnCharacterDeath(
function (player, killer)
DEF_ReinforcementCount = GetReinforcementCount(DEF)
end
)

if DEF_ReinforcementCount < 30 then
ClearAIGoals(DEF)
--AddAIGoal(DEF, "Defend", 200, "German_retreat")
end
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: Brave but dumb, the AI are.

Post by [RDH]Zerted »

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.
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: Brave but dumb, the AI are.

Post by bobfinkl »

Thanks Zerted that worked, oh and just for anyone else who wants to get their AI to retreat you must have a invisible CP for the AI to retreat to.
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Re: Brave but dumb, the AI are.

Post by jangoisbaddest »

[RDH]Zerted wrote:The AI goal Follow should give a tighter/faster retreat if Defend isn't good enough.
Woah! Sorry to derail, but I was wondering about this kind of thing. How does this work? Do you specify, say, a path or planning arc for the AI to follow? What is the difference between this and "patrol"?
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Brave but dumb, the AI are.

Post by Frisbeetarian »

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: Brave but dumb, the AI are.

Post by [RDH]Zerted »

bobfinkl wrote:...you must have a invisible CP for the AI to retreat to.
You shouldn't have to use a CP. Check that ScriptAIGoals.txt doc. It says you can use any game object pointer (gameObjectPtr) or any integer character index (integerChrIdx) for Defend. The pointers are the game objects and the index is the number you get as the character value for all those character event callbacks, such as OnCharacterSpawn.
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: Brave but dumb, the AI are.

Post by bobfinkl »

Odd, because once I switched it to a cp it worked and before it refused to. I'll try some other objects and see if they work.
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: Brave but dumb, the AI are.

Post by [RDH]Zerted »

Well if you're not over the CP limit, theres no problem in using another CP.
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: Brave but dumb, the AI are.

Post by bobfinkl »

Then I guess this is solved then, admins go ahead and lock this.
Post Reply