Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(26 intermediate revisions by 10 users not shown)
Line 1: Line 1:
== getAlivePlayersInTeam ==
== Pending functions ==
Here are some functions that were developed as part of the MTA forums scripting section but have not yet been added to the list. Those could be useful to advanced resource crafters.


{{Useful Function}}
* https://forum.mtasa.com/topic/122958-getworldfrommapposition/ - calculating the world position on a map image
<lowercasetitle/>
* https://forum.mtasa.com/topic/122823-help-getscreenfromworldposition/ - more powerful screen coordinate function with border support
__NOTOC__
This function returns a table of the alive players in a team.


==Syntax==
--[[User:Quiret|Quiret]] ([[User talk:Quiret|talk]]) 18:58, 17 March 2020 (UTC)
<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
 
-- 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 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}}

Latest revision as of 18:59, 17 March 2020

Pending functions

Here are some functions that were developed as part of the MTA forums scripting section but have not yet been added to the list. Those could be useful to advanced resource crafters.

--Quiret (talk) 18:58, 17 March 2020 (UTC)