GetAllPlayers: Difference between revisions

From Onset Developer Wiki
(Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|GetAllPlayers()}} {{FuncParameters}} {{FuncNoParam}} {{FuncReturnValue|__EDIT_ME__}} == Example...")
 
No edit summary
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Get all players on the server. Useful for loops.}}


{{FuncSyntax|GetAllPlayers()}}
{{FuncSyntax|GetAllPlayers()}}
Line 8: Line 8:
{{FuncNoParam}}
{{FuncNoParam}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns a table of all players.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
function cmd_healall(player)
if (PlayerData[player].admin < 4) then
return AddPlayerChat(player, "Insufficient permission")
end
 
for _, v in pairs(GetAllPlayers()) do
SetPlayerHealth(v, 100.0)
end
 
AddPlayerChatAll("Admin "..GetPlayerName(player).." has healed all players!")
end
AddCommand("healall", cmd_healall)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
__EDIT_ME__

Revision as of 09:50, 8 October 2019

GetAllPlayers

Type: Function
Context: Server
Introduced: v1.0

Description

Get all players on the server. Useful for loops.

Syntax

GetAllPlayers()

Parameters

  • This function has no parameters.

Return Value

  • Returns a table of all players.

Example

function cmd_healall(player)
	if (PlayerData[player].admin < 4) then
		return AddPlayerChat(player, "Insufficient permission")
	end

	for _, v in pairs(GetAllPlayers()) do
		SetPlayerHealth(v, 100.0)
	end

	AddPlayerChatAll("Admin "..GetPlayerName(player).." has healed all players!")
end
AddCommand("healall", cmd_healall)

See also

__EDIT_ME__