player.GetAll

From GMod Wiki

Revision as of 14:41, 12 October 2011 by Donkie (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax player.GetAll( )
Where is this used?
Description:
Returns a table of all the connected players as Player objects.
Returns: Table :Player
Part of Library: Player
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Player.GetAll]Player.GetAll [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionThis example grabs all the player objects, and prints out each name.
Used onNewerShared.png
Code
 
for k, v in pairs(player.GetAll()) do
   Msg( v:Nick() .. "\n")
end
 
OutputN/A


DescriptionSends every player flying into the air
Used onNewerServer.png
Code
 
local Players = player.GetAll()
for i = 1, table.Count(Players) do
    local ply = Players[i]
    ply:SetVelocity(Vector(0,0,50) * 50)
end
 
OutputN/A


DescriptionPrints a message into every players talk area
Used onNewerServer.png
Code
 
local message = {
"You are playing on "..GetConVarString("hostname")..".",
"Having Fun?",
}
 
local allplayers = player.GetAll( )
local r = math.random(1,table.Count(message))
 
for k,v in pairs ( allplayers ) do
     v:PrintMessage( HUD_PRINTTALK, message[ r ] );
end
 
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox