GetPlayerTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(Undo revision 56820 by Ahmedsayed Hamada (talk))
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Server client function}}
__NOTOC__
__NOTOC__
This function is used to get the current [[team]] a [[player]] is on.
This function gets the current [[team]] a [[player]] is on.


==Syntax==
==Syntax==
Line 6: Line 7:
team getPlayerTeam ( player thePlayer )
team getPlayerTeam ( player thePlayer )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[player]]:getTeam|team|setPlayerTeam}}
===Required Arguments===
===Required Arguments===
*'''thePlayer''': The [[player]] whose team you want to find out.
*'''thePlayer''': The [[player]] whose team you want to find out.
===Returns===
Returns a ''team'' element representing the team the player is on, ''false'' if the player is not part of a team.


==Example==
==Example==
<section name="Server" class="server" show="true">
This example finds the team a player is on, and then changes its name.
This example finds the team a player is on, and then changes its name.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "teamName", "teamName" )
function teamName ( source, key, newTeamName )
function teamName ( source, key, newTeamName )
  team = getPlayerTeam ( source ) -- get the player's team
    local playerTeam = getPlayerTeam ( source )         -- get the player's team
  if ( team ) then -- if he's on a team
    if ( playerTeam ) then                               -- if he's on a team
    teamName = getTeamName ( team ) -- get the teams current name
        local oldTeamName = getTeamName ( playerTeam )   -- get the team's current name
    setTeamName ( team, newTeamName ) -- change its name
        setTeamName ( playerTeam, newTeamName )         -- change its name
    outputChatBox ( "Changed "..getClientName ( source ).."'s team name from "..teamName.." to "..newTeamName )
        outputChatBox ( "Changed " .. getPlayerName ( source ).."'s team name from " .. oldTeamName .. " to " .. newTeamName )
  else
    else
    outputChatBox ( getClientName ( source ).." isn't on a team" )
        outputChatBox ( getPlayerName ( source ) .. " isn't on a team" )
  end
    end
end
end
addCommandHandler ( "teamname", teamName )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Latest revision as of 23:58, 23 July 2018

This function gets the current team a player is on.

Syntax

team getPlayerTeam ( player thePlayer )

OOP Syntax Help! I don't understand this!

Method: player:getTeam(...)
Variable: .team
Counterpart: setPlayerTeam


Required Arguments

  • thePlayer: The player whose team you want to find out.

Returns

Returns a team element representing the team the player is on, false if the player is not part of a team.

Example

Click to collapse [-]
Server

This example finds the team a player is on, and then changes its name.

function teamName ( source, key, newTeamName )
    local playerTeam = getPlayerTeam ( source )          -- get the player's team
    if ( playerTeam ) then                               -- if he's on a team
        local oldTeamName = getTeamName ( playerTeam )   -- get the team's current name
        setTeamName ( playerTeam, newTeamName )          -- change its name
        outputChatBox ( "Changed " .. getPlayerName ( source ).."'s team name from " .. oldTeamName .. " to " .. newTeamName )
    else
        outputChatBox ( getPlayerName ( source ) .. " isn't on a team" )
    end
end
addCommandHandler ( "teamname", teamName )

See Also