Telling AI to Follow a Player

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
Fierfek
High General
High General
Posts: 805
Joined: Wed Jul 01, 2009 4:38 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Somewhere in the Galaxy (Most Likely Scrapping Tinnies)

Telling AI to Follow a Player

Post by Fierfek »

How do I tell AI to follow a player?
I looked in the scripting doc, and searched. I still can't figure it out.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Telling AI to Follow a Player

Post by Maveritchell »

User avatar
Fierfek
High General
High General
Posts: 805
Joined: Wed Jul 01, 2009 4:38 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Somewhere in the Galaxy (Most Likely Scrapping Tinnies)

Re: Telling AI to Follow a Player

Post by Fierfek »

So I add this to the lua?
Hidden/Spoiler:
AddAIGoal(REP, "Follow", 2, player)
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Telling AI to Follow a Player

Post by Maveritchell »

No. "Player" means nothing. You have to retrieve the gameobjectPtr of the unit you want to be followed (I don't recall what grouping of functions you do to get this, look at the scripting doc). It may be easier to use the "defend" AI goal since that can use a character index (which is simpler to retrieve, I think, but you'll also need to look at the scripting doc).
User avatar
Fierfek
High General
High General
Posts: 805
Joined: Wed Jul 01, 2009 4:38 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Somewhere in the Galaxy (Most Likely Scrapping Tinnies)

Re: Telling AI to Follow a Player

Post by Fierfek »

Maveritchell wrote:No. "Player" means nothing. You have to retrieve the gameobjectPtr of the unit you want to be followed (I don't recall what grouping of functions you do to get this, look at the scripting doc). It may be easier to use the "defend" AI goal since that can use a character index (which is simpler to retrieve, I think, but you'll also need to look at the scripting doc).
What's a character index?
mswf
Master Bounty Hunter
Master Bounty Hunter
Posts: 1674
Joined: Tue Mar 31, 2009 3:40 pm
Location: Twello, The Netherlands
Contact:

Re: Telling AI to Follow a Player

Post by mswf »

My only suggestion would be to try to find that out by reading all the docs you're being directed to.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Telling AI to Follow a Player

Post by Frisbeetarian »

The character index of the player (it only makes sense that this is only true in single player) is 0.

Code: Select all

        local agroGeonosianIndex = GetTeamMember(BOSS, 0)       
        local agroGeonosianUnit = GetCharacterUnit( agroGeonosianIndex )
        SetAIDamageThreshold( agroGeonosianUnit, 0.6 )  --keep the AI's from killing the agro_geonosian
        AddAIGoal(BODYGUARDS, "Follow", 300, agroGeonosianIndex)    
This is the only place in the mission scripts where the AI goal "Follow" is used. It looks like it's using the integerChrIdx instead of a gameObjectPtr. Why don't you try it and see what happens.
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: Telling AI to Follow a Player

Post by [RDH]Zerted »

All characters in the game have an ID. It is sometimes referred to as a 'character index'. The AI follow goal works fine with integerChrIdx. integerChrIdx is just saying that a character index is an integer.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Telling AI to Follow a Player

Post by Frisbeetarian »

I understand what the variables mean and why they are called that, I was just referring directly to the ScriptAIGoals.txt. This document goes on to say that only an object's pointer can be used ("gamObjectPtr") for the "Follow" command and I was giving reason to disbelieve the accuracy of this. I know that you have previously stated that you thought the character index could be used despite the document, and I just gave evidence from the scripts to support that.

The document says that the character index for the player (it must only be in single player) is 0.
User avatar
Fierfek
High General
High General
Posts: 805
Joined: Wed Jul 01, 2009 4:38 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Somewhere in the Galaxy (Most Likely Scrapping Tinnies)

Re: Telling AI to Follow a Player

Post by Fierfek »

Okay, I took a look at the mustafar script.
It has a local team for Gizor Delzo with only him on it, then another local team with his followers.
So, I made my republic team have only 1 unit on it (the player), then made a local team with all the others commandos.
Then, I added this script in my scriptpostload section:

Code: Select all

    local agroGeonosianIndex = GetTeamMember(REP, 0)       
    local agroGeonosianUnit = GetCharacterUnit( agroGeonosianIndex )
    SetAIDamageThreshold( agroGeonosianUnit, 0.6 )  --keep the AI's from killing the agro_geonosian
    AddAIGoal(4, "Follow", 300, agroGeonosianIndex)   
I changed the team names - but I don't know how to change the agroGeonosian thingy.
I tried ingame - this script doesn't work as it is.
mswf
Master Bounty Hunter
Master Bounty Hunter
Posts: 1674
Joined: Tue Mar 31, 2009 3:40 pm
Location: Twello, The Netherlands
Contact:

Re: Telling AI to Follow a Player

Post by mswf »

You can't simply copy over parts of scripts from a different campaign. I mean, take a look at it:
It still references to an Agressive Geonosian unit, not to a Republic Commando. It also makes that unit unkillable by the AI. Take a more serious look at what references to what and be sure to carefully change those codes.
User avatar
Fierfek
High General
High General
Posts: 805
Joined: Wed Jul 01, 2009 4:38 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Somewhere in the Galaxy (Most Likely Scrapping Tinnies)

Re: Telling AI to Follow a Player

Post by Fierfek »

Okay, I have a script here:

Code: Select all

AddAIGoal( team, "Follow", weight, gameObjectPtr );
AddAIGoal( team, "Follow", weight, integerChrIdx );
I'm hearing all about 'gameObjectPtr' and 'integerChrIdx'.
I know what they stand for, but I have absolutely no idea as to how to reference them to my character.
The rep team is only allowed 1 unit (AI can't spawn on it) - the player can choose from 6 different units.
Then there is a local team (team 4), which I want to follow the player around.
So far, I have this script then:

Code: Select all

AddAIGoal( 4, "Follow", 500, gameObjectPtr );
AddAIGoal( 4, "Follow", 500, integerChrIdx );
What do I need to change game object pointer and integer character index to to make it 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: Telling AI to Follow a Player

Post by [RDH]Zerted »

Frisbeetarian wrote:I understand what the variables mean and why...
I was supplementing your post, not replying to it and was trying to confirm the disbelief. v1.3 uses the Follow goal to get the AI to follow selected people around.

gameObjectPtr is any ingame object. Such as "cp1", "health_droid3", or "team_flag".
integerChrIdx is any character id. In singleplayer, the human player's id is 0. In multiplayer, all the character related event callbacks given you the id of the player that triggered them. As example, this code will make the bots on team 1 follow the first human which spawn. In the code, character is an integerChrIdx:

Code: Select all

local firstSpawn = OnCharacterSpawn(function(character)
    --check to see if the player is human
    if IsCharacterHuman(character) then
        --make the bots on team 1 follow the spawned player
        AddAIGoal(1,'Follow', 50, character)

        --stop this event callback from being called a second time
        ReleaseCharacterSpawn(firstSpawn)
    end
end)
User avatar
Fierfek
High General
High General
Posts: 805
Joined: Wed Jul 01, 2009 4:38 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Somewhere in the Galaxy (Most Likely Scrapping Tinnies)

Re: Telling AI to Follow a Player

Post by Fierfek »

Thanks, that worked.
User avatar
boyohboyohboy
Recruit Womprat Killer
Posts: 12
Joined: Sat Oct 10, 2009 8:54 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: up :)

Re: Telling AI to Follow a Player

Post by boyohboyohboy »

I'm new to the scripting system, so which LUA do put the AI Goal in?
mswf
Master Bounty Hunter
Master Bounty Hunter
Posts: 1674
Joined: Tue Mar 31, 2009 3:40 pm
Location: Twello, The Netherlands
Contact:

Re: Telling AI to Follow a Player

Post by mswf »

In the .lua of your gamemode (be it conquest, cptf or a hunt mode) Usually, it's somewhere near the top. In the future, I'd suggest you'd look at the date of the last post, there is a "no bump after 30 days" rule on this forum. (the date stamp is in the top right corner of the last post)
Post Reply