Page 1 of 1
Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 2:59 pm
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.
Re: Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 3:02 pm
by Maveritchell
Re: Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 3:05 pm
by Fierfek
So I add this to the lua?
Re: Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 3:11 pm
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).
Re: Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 3:15 pm
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?
Re: Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 3:18 pm
by mswf
My only suggestion would be to try to find that out by reading all the docs you're being directed to.
Re: Telling AI to Follow a Player
Posted: Tue Aug 25, 2009 4:01 pm
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.
Re: Telling AI to Follow a Player
Posted: Wed Aug 26, 2009 12:33 am
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.
Re: Telling AI to Follow a Player
Posted: Wed Aug 26, 2009 2:59 am
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.
Re: Telling AI to Follow a Player
Posted: Wed Aug 26, 2009 10:32 am
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.
Re: Telling AI to Follow a Player
Posted: Wed Aug 26, 2009 10:37 am
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.
Re: Telling AI to Follow a Player
Posted: Wed Aug 26, 2009 10:57 am
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?
Re: Telling AI to Follow a Player
Posted: Wed Aug 26, 2009 3:02 pm
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)
Re: Telling AI to Follow a Player
Posted: Thu Aug 27, 2009 7:01 pm
by Fierfek
Thanks, that worked.
Re: Telling AI to Follow a Player
Posted: Sun Oct 11, 2009 10:04 pm
by boyohboyohboy
I'm new to the scripting system, so which LUA do put the AI Goal in?
Re: Telling AI to Follow a Player
Posted: Mon Oct 12, 2009 12:21 am
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)