CreateTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Example highlighting fix, minor fixes)
Line 4: Line 4:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
team createTeam ( string teamName, [int colorR = 255, int colorG = 255, int colorB = 255 ] )
team createTeam ( string teamName, [int colorR = 255, int colorG = 255, int colorB = 255] )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''teamName:''' A string representing the teams name.
*'''teamName:''' A string representing the teams name.
*'''colorR:''' An integer representing the Red color value.
*'''colorR:''' An integer representing the red color value.
*'''colorG:''' An integer representing the Green color value.
*'''colorG:''' An integer representing the green color value.
*'''colorB:''' An integer representing the Blue color value.
*'''colorB:''' An integer representing the blue color value.


===Returns===
===Returns===
Returns a team element if it was successfully created, 'false' otherwise.
Returns a team element if it was successfully created, ''false'' if invalid arguments are passed or a team with that name already exists.


==Example==
==Example==
'''Example 1:''' This example creates a new team for a player, then adds him to it.
'''Example 1:''' This example creates a new team for a player, then adds him to it.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function gimmeATeam ( source, key, teamName )
function gimmeATeam ( source, commandName, teamName )
   team = createTeam ( teamName ) -- create a new team with the specified name
   local newTeam = createTeam ( teamName ) -- create a new team with the specified name
   if ( team ) then -- if it was successfully created
   if newTeam then -- if it was successfully created
     addPlayerToTeam ( source, team ) -- add the player to the new team
     addPlayerToTeam ( source, newTeam ) -- add the player to the new team
   end
   end
end
end
Line 28: Line 28:
</syntaxhighlight>
</syntaxhighlight>


'''Example 2:''' This example creates two teams, one for grove and one for ballas, when the resource is started.
'''Example 2:''' This example creates two teams, one for grove and one for ballas, when the resource this script is in is started.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function createTeamsOnStart ( resource )
function createTeamsOnStart ()
teamGrove = createTeam ( "grove", 0,255,0 )
teamGrove = createTeam ( "grove", 0, 255, 0 )
teamBallas = createTeam ( "ballas", 200, 0, 100 )
teamBallas = createTeam ( "ballas", 200, 0, 100 )
end
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  )
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) --we attach the function to this resource's root element
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 13:52, 16 July 2007

This function is for creating a new team, which can be used to group players.

Syntax

team createTeam ( string teamName, [int colorR = 255, int colorG = 255, int colorB = 255] )

Required Arguments

  • teamName: A string representing the teams name.
  • colorR: An integer representing the red color value.
  • colorG: An integer representing the green color value.
  • colorB: An integer representing the blue color value.

Returns

Returns a team element if it was successfully created, false if invalid arguments are passed or a team with that name already exists.

Example

Example 1: This example creates a new team for a player, then adds him to it.

function gimmeATeam ( source, commandName, teamName )
  local newTeam = createTeam ( teamName ) -- create a new team with the specified name
  if newTeam then -- if it was successfully created
    addPlayerToTeam ( source, newTeam ) -- add the player to the new team
  end
end
addCommandHandler ( "giveteam", gimmeATeam )

Example 2: This example creates two teams, one for grove and one for ballas, when the resource this script is in is started.

function createTeamsOnStart ()
	teamGrove = createTeam ( "grove", 0, 255, 0 )
	teamBallas = createTeam ( "ballas", 200, 0, 100 )
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) --we attach the function to this resource's root element

See Also