Changing a player to a different team (human AND ai)

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
Tourny
Command Sergeant Major
Command Sergeant Major
Posts: 289
Joined: Sat Sep 27, 2008 5:58 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: Crifton
Contact:

Changing a player to a different team (human AND ai)

Post by Tourny »

I don't know how to do it, but:

I want to get a CIS to kill a rep, then when the rep dies I have a function that detects that the rep was killed by the cis. Then it switches the rep to team 3. But I'm not sure if it will STAY team 3 the way I have it set up. I need it to spawn at a particular command post and be on team 3.

Code:

Code: Select all

OnCharacterDeath(
	function(player, killer)
		if GetCharacterTeam(killer) == "DEF" then
			SetProperty(GetCharacterUnit(player), Team, 3)
		end
	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: Changing a player to a different team (human AND ai)

Post by [RDH]Zerted »

Nope, the unit is destroyed a few seconds after the character dies. When a player spawns, it has a new unit. You need to change the team of the newly spawned unit. That means using OnCharacterSpawn. In order to track which players' units need to be moved to team 3, store them in a table:
Hidden/Spoiler:
[code]--table holding the characters whose units are to be moved
toTeamThree = {}

OnCharacterDeathTeam(function(player,killer)
--ignore when there is no killer, like when one falls off a building or drowns
if killer == nil then return end

if GetCharacterTeam(killer) == DEF then
--store the dead player's id in a table
table.insert(toTeamThree, player)
end
end, DEF)

OnCharacterSpawn(function(player)
--search through the table to see if the newly spawned character needs to have his unit put on team 3
for i=1,table.getn(toTeamThree) do

if toTeamThree == player then
--found this player, so move his unit to team 3
local unit = GetCharacterUnit(player)
SetProperty(unit, "PerceivedTeam", 3)
SetProperty(unit, "Team", 3)

--remove this player from the table, as we already moved his unit
table.remove(toTeamThree, i)
return
end
end
end)
[/code]
If you want the unit at a certain CP, then you have to force spawn it or teleport it there.

12/12/2010 Edit: Fixed typo in the if statement (was supposed to be then not do) and two other typos :(
Post Reply