Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(22 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Useful Function}}
== Pending functions ==
<lowercasetitle></lowercasetitle>
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.
__NOTOC__
This function returns a table of the alive players in a team.


==Syntax==
* https://forum.mtasa.com/topic/122958-getworldfrommapposition/ - calculating the world position on a map image
<syntaxhighlight lang="lua">void getAlivePlayersInTeam( element theTeam )</syntaxhighlight>
* https://forum.mtasa.com/topic/122823-help-getscreenfromworldposition/ - more powerful screen coordinate function with border support


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

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)