Getting Spawned Units to Follow the Spawner [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
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Getting Spawned Units to Follow the Spawner [Solved]

Post by Sky_216 »

**This is being used for DS as a replacement for the overpowered mobile command post. archer01 made most of the code.**

The idea is it spawns a squad of security droids that follow the spawner (tactical droid, can be human or ai) around. They spawn fine, they work fine...except I can't get them to follow the tactical droid around (just sit still so clearly the code is messed up somewhere). Anyone with experience in this sort of thing able to help?

Code:
Hidden/Spoiler:
[code]OnCharacterDispenseControllableTeam(
function(character,controlled)
if GetEntityClass(controlled) == GetEntityClassPtr(TroopSpawnerWeapon) then
local SupportTeam = 3 --Team the new spawned character is in (change this)
local teamSize = GetTeamSize(SupportTeam)
for i = 0, teamSize-1 do
local characterIndex = GetTeamMember(SupportTeam, i)
local charUnit = GetCharacterUnit(characterIndex)
local leaderIndex = GetEntityPtr(character)
if not charUnit then
local destination = GetEntityMatrix(GetCharacterUnit(character))
SpawnCharacter(characterIndex,destination)
ClearAIGoals(3)
AddAIGoal(3, "Follow", 100, leaderIndex)
end
end
end
end,
CIS --User team (change this)
)[/code][/size]
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: Getting spawned units to follow the Spawner

Post by [RDH]Zerted »

Put the AI goal's target on the character's unit and move the ClearAIGoal and AddAIGoal lines above the loop. One adds AI goals for each team, not for each team member.
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Getting spawned units to follow the Spawner

Post by Sky_216 »

Thanks Zerted, worked perfectly :)
Post Reply