Page 1 of 1

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

Posted: Sun Aug 30, 2009 6:26 pm
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
	)

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

Posted: Sun Aug 30, 2009 7:40 pm
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 :(