Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(getAlivePlayersInTeam)
 
(27 intermediate revisions by 10 users not shown)
Line 1: Line 1:
== getAlivePlayersInTeam ==


{{Useful Function}}
<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">
-- define the command handler function
function getThePlayers(thePlayer)
local mta = createTeam("MTA",255,100,0)
for i,v in pairs(getAlivePlayersInTeam(mta)) -- get the alive players.
outputChatBox("MTA's 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 22:15, 21 May 2018