GetTeamColor: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 14: Line 14:


==Example==
==Example==
This example outputs the name of a players team when they spawn, in that team's color.
This example outputs the player's team name and colors if he is on a team.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerSpawn", root, "onPlayerSpawn" )
function teamInfo ( source )
function onPlayerSpawn ( spawnpoint, team )
   local r, g, b = 255, 255, 255
   r, g, b = 255, 255, 255
   local team = getPlayerTeam( source )
   string = getClientName ( source ) .. " spawned"
 
   if ( team ) then
  -- Make a string to print out the player's team information
     teamName = getTeamName ( team )
  local string = getClientName ( source ) .. " spawned"
     string = string.." as a "..teamName
 
   if ( team ) then -- If the player is on a team (team is not false)
     -- Add the team name to the string
     string = string.." as ".. getTeamName ( team )
   
    -- Get the red, green, and blue values of the team's color
     r, g, b = getTeamColor ( team )
     r, g, b = getTeamColor ( team )
   
    -- Convert the colors to strings and add them to the string
    string = string .. " with team colors: " .. tostring(r) .. ", " .. tostring(g) .. ", " .. tostring(b)
   end
   end
   outputChatBox ( string, r, g, b )
 
  -- Print the string with the player's team information
   outputChatBox ( string )
end
end
-- Add console command to print out your team information
addCommandHandler ( "teamInfo", teamInfo )
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 03:40, 2 August 2007

This function is for retrieving the color of a team.

Syntax

int, int, int getTeamColor ( team theTeam )

Required Arguments

  • theTeam: The team you want to get the color of.

Returns

Returns 3 integers representing the red, green, and blue color values of the team if valid, otherwise 'false'.

Example

This example outputs the player's team name and colors if he is on a team.

function teamInfo ( source )
  local r, g, b = 255, 255, 255
  local team = getPlayerTeam( source )
  
  -- Make a string to print out the player's team information
  local string = getClientName ( source ) .. " spawned"

  if ( team ) then -- If the player is on a team (team is not false)
    -- Add the team name to the string
    string = string.." as ".. getTeamName ( team )
    
    -- Get the red, green, and blue values of the team's color
    r, g, b = getTeamColor ( team )
    
    -- Convert the colors to strings and add them to the string
    string = string .. " with team colors: " .. tostring(r) .. ", " .. tostring(g) .. ", " .. tostring(b)
  end

  -- Print the string with the player's team information
  outputChatBox ( string )
end

-- Add console command to print out your team information
addCommandHandler ( "teamInfo", teamInfo )

See Also