Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Blanked the page)
Line 1: Line 1:
{{Useful Function}}
<lowercasetitle></lowercasetitle>
__NOTOC__
This function returns a table of the alive players in a team.


==Syntax==
<syntaxhighlight lang="lua">void getAlivePlayersInTeam( element theTeam )</syntaxhighlight>
===Required Arguments===
* '''theTeam''': The element of the team where you want to get the alive players from.
===Optional Arguments===
==Code==
<section name="Serverside Script" class="server" show="true">
<syntaxhighlight lang="lua">
function getAlivePlayersInTeam(theTeam)
local table = { }
local players = getPlayersInTeam(theTeam)
for i,v in pairs(players) do
if not isPedDead(v) then
    table[#table+1]=v
    end
end
return table
end
</syntaxhighlight>
</section>
==Example==
<section name="Server" class="server" show="true">
This example get's the alive players from the team "MTA".
<syntaxhighlight lang="lua">
function getAlivePlayersInTeam(theTeam)
local table = { }
local players = getPlayersInTeam(theTeam)
for i,v in pairs(players) do
if not isPedDead(v) then
    table[#table+1]=v
    end
end
return table
end
mta = createTeam("MTA",255,100,0)
-- define the command handler function
function getThePlayers(thePlayer)
for i,v in pairs(getAlivePlayersInTeam(mta)) -- get the alive players.
outputChatBox("MTA team has ".. tonumber(i) .." player's alive.",thePlayer)
  end
end
-- add the command handler
addCommandHandler("alive",getThePlayers)
</syntaxhighlight>
</section>
Author(s): Castillo, Karlis
==See Also==
{{Useful_Functions}}

Revision as of 16:21, 18 May 2011