SetPlayerTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 34: Line 34:
addCommandHandler ( "takeawaymyteam", unassignTeam )
addCommandHandler ( "takeawaymyteam", unassignTeam )
</syntaxhighlight>
</syntaxhighlight>
==Issues==
{{Issues|
{{Issue|6861|Teams members aren't sent to clients if set in onResourceStart}}
}}


==See Also==
==See Also==
{{Team_functions}}
{{Team_functions}}

Revision as of 21:34, 10 October 2012

This function adds a player to an existing team. The player will automatically be removed from his current team if he's on one.

Syntax

bool setPlayerTeam ( player thePlayer, team theTeam )

Required Arguments

  • thePlayer: The player you wish to add to a team.
  • theTeam: The team you want to add the player to, or nil if you wish to unassign a player from his team.

Returns

Returns true if the player was successfully added to the specified team or removed from his previous one, false otherwise.

Example

This example adds a command to create a new team for a player, then add him to it. It also adds a command to remove him from his team.

function assignNewTeam ( source, commandName, teamName )
  local theTeam = createTeam ( teamName )  -- create a new team with the specified name
  if theTeam then                          -- if it was successfully created
    setPlayerTeam ( source, theTeam )    -- add the player to the new team
  end
end
addCommandHandler ( "gimmeateam", assignNewTeam )

function unassignTeam ( source, commandName )
  local theTeam = getPlayerTeam ( source )  -- Check if the player is on a team
  if theTeam then                          -- this player is on a team, so we can remove them from it
    setPlayerTeam ( source, nil )    -- remove the player from the current team
  end
end
addCommandHandler ( "takeawaymyteam", unassignTeam )

Issues

Issue ID Description
#6861 Teams members aren't sent to clients if set in onResourceStart

See Also