GetTeamFromName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
This function finds a team object by the team's name.
This function finds a [[team]] element using the provided team name.


==Syntax==
==Syntax==
Line 7: Line 7:
team getTeamFromName ( string teamName )
team getTeamFromName ( string teamName )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||Team.getFromName||}}
===Required Arguments===
===Required Arguments===
*'''teamName:''' A string determining the name of the team you wish to find.
*'''teamName:''' A string determining the name of the team you wish to find.


===Returns===
===Returns===
Returns the team object if it was found, ''false'' otherwise.
Returns the [[team]] element if it was found, ''false'' otherwise.


==Example==
==Example==
This example joins a team named "Red", if it is found.
This example creates a team, and sets the player's team to it's partial name:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function joinRedTeam ( source )
-- Creates a red team
-- Try to find the team named 'Red'
createTeam("Red", 255, 0, 0)
local redteam = getTeamFromName ( "Red" )
 
function joinRedTeam (source)
if ( redteam ) then -- If it was found (not false)
local redteam = getTeamFromName("Red")
addPlayerToTeam ( source, redteam )
if (redteam) then -- If the team was successfully created
-- Sets the player's team by getting the partial name of the red team.
setPlayerTeam(client, readteam)
outputChatBox("You are now in the 'Red' team", source)
else
outputChatBox("Sorry, we can't set your team. An error occurred!", source)
end
end
end
end


--Add console command to join the team when 'joinTeam' is typed.
--Add console command to join the team when 'joinTeam' is typed.
addCommandHandler ( "joinTeam", joinRedTeam )
addCommandHandler("jointeam", joinRedTeam)
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 15:31, 9 May 2018

This function finds a team element using the provided team name.

Syntax

team getTeamFromName ( string teamName )

OOP Syntax Help! I don't understand this!

Method: Team.getFromName(...)


Required Arguments

  • teamName: A string determining the name of the team you wish to find.

Returns

Returns the team element if it was found, false otherwise.

Example

This example creates a team, and sets the player's team to it's partial name:

-- Creates a red team
createTeam("Red", 255, 0, 0)

function joinRedTeam (source)
	local redteam = getTeamFromName("Red")
	if (redteam) then -- If the team was successfully created
		-- Sets the player's team by getting the partial name of the red team.
		setPlayerTeam(client, readteam)
		outputChatBox("You are now in the 'Red' team", source)
	else
		outputChatBox("Sorry, we can't set your team. An error occurred!", source)
	end
end

--Add console command to join the team when 'joinTeam' is typed.
addCommandHandler("jointeam", joinRedTeam)

See Also