GetTeamColor: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(OOP syntax added)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Server client function}}
__NOTOC__
__NOTOC__
This function is for retrieving the color of a team.
This function retrieves the color of a team.


==Syntax==
==Syntax==
Line 6: Line 7:
int, int, int getTeamColor ( team theTeam )
int, int, int getTeamColor ( team theTeam )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[team]]:getColor||}}
===Required Arguments===
===Required Arguments===
*'''theTeam:''' The team you want to get the color of.
*'''theTeam:''' The team you want to get the color of.


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


==Example==
==Example==
This example outputs the player's team name and colors if he is on a team.
<section name="Serverside example" class="server" show="true">
This example defines a console command that outputs the player's team name and colors if he is on a team.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function teamInfo ( source )
function teamInfo ( source )
  local r, g, b = 255, 255, 255
    local r, g, b
  local team = getPlayerTeam( source )
    local playerTeam = getPlayerTeam( source )
    
    
  -- Make a string to print out the player's team information
    -- Make a string to print out the player's team information
  local string = getClientName ( source ) .. " spawned"
    local text = getPlayerName ( source )


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


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


Line 41: Line 45:
addCommandHandler ( "teamInfo", teamInfo )
addCommandHandler ( "teamInfo", teamInfo )
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 06:51, 12 July 2014

This function retrieves the color of a team.

Syntax

int, int, int getTeamColor ( team theTeam )

OOP Syntax Help! I don't understand this!

Method: team:getColor(...)


Required Arguments

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

Returns

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

Example

Click to collapse [-]
Serverside example

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

function teamInfo ( source )
    local r, g, b
    local playerTeam = getPlayerTeam( source )
  
    -- Make a string to print out the player's team information
    local text = getPlayerName ( source )

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

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

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

See Also