Resource:Battlefield/getSquad: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Undo revision 31069 by Jaysds (talk))
 
(5 intermediate revisions by 3 users not shown)
Line 20: Line 20:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
nameTable = { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel" }
nameTable = { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel" }
shortnTable = { "a", "b", "c", "d", "e", "f", "g", "h" }
function getSquad ( name, team )
function getSquad ( name, team )
local squads = getElementsByType ( "squad" )
local squads = getElementsByType ( "squad" )
Line 27: Line 26:
if team == sTeam then
if team == sTeam then
for j,l in ipairs ( nameTable ) do
for j,l in ipairs ( nameTable ) do
if name == l then
shortn = string.lower ( string.sub ( l, 1, 1 ) )
if name == l or name == shortn then
return v
return v
else
else
for u,p in ipairs ( shortnTable ) do
return false
if name == p then
return v
else
return false
end
end
end
end
end

Latest revision as of 15:32, 22 May 2012

Purpose

This command retrieves a squad element when given the name or shortname of a squad and the team.

Syntax

squad getSquad ( [string squadName, string squadShortn], team squadTeam )

Required Arguments

  • squadTeam: The team element the squad will be attached to.

Optional Arguments

  • squadName: The name of the squad.
  • squadShortn: The shortname of the squad.

Returns

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

Function Source

nameTable = { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel" }
function getSquad ( name, team )
	local squads = getElementsByType ( "squad" )
	for k,v in ipairs ( squads ) do
		local sTeam = getElementData ( v, "team" )
		if team == sTeam then
			for j,l in ipairs ( nameTable ) do
				shortn = string.lower ( string.sub ( l, 1, 1 ) )
				if name == l or name == shortn then
					return v
				else
					return false
				end
			end
		else
			return false
		end
	end
end


Return to Battlefield Resource