Squirrel/Server/Functions/Server/GetPlayers
From Liberty Unleashed Wiki
(Difference between revisions)
Line 1: | Line 1: | ||
{{Squirrel/Title|GetPlayers}} | {{Squirrel/Title|GetPlayers}} | ||
− | This returns the number of players currently playing on the server. | + | This returns the number of players currently playing on the server. (This function also has an alias ''GetPlayerCount'') |
== Syntax == | == Syntax == | ||
− | <code> | + | <code>int GetPlayers()</code> |
== Arguments == | == Arguments == | ||
Line 12: | Line 12: | ||
== Example == | == Example == | ||
− | This command will return the number of players in | + | This command will return the number of players in-game when someone types /players'. |
<code lang="squirrel"> | <code lang="squirrel"> | ||
− | function onPlayerCommand( | + | function onPlayerCommand( plr, cmd, text ) |
{ | { | ||
if ( cmd == "players" ) | if ( cmd == "players" ) | ||
{ | { | ||
− | Message( "There are currently " + GetPlayers() + " players in-game.", | + | Message( "There are currently " + GetPlayers() + " players in-game.", lpr ); |
} | } | ||
+ | |||
+ | return 1; | ||
} | } | ||
</code> | </code> | ||
Line 26: | Line 28: | ||
=== Notes === | === Notes === | ||
− | The function [[Squirrel/Functions/ | + | The function [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and call [[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them can be found in corresponding pages. |
== Related Functions == | == Related Functions == | ||
− | {{Squirrel/Functions/Server}} | + | {{Squirrel/Server/Functions/Server}} |
Latest revision as of 23:16, 9 June 2011
This returns the number of players currently playing on the server. (This function also has an alias GetPlayerCount)
[edit] Syntax
int GetPlayers()
[edit] Arguments
- None
[edit] Example
This command will return the number of players in-game when someone types /players'.
function onPlayerCommand( plr, cmd, text ) { if ( cmd == "players" ) { Message( "There are currently " + GetPlayers() + " players in-game.", lpr ); } return 1; }
[edit] Notes
The function MessagePlayer and call onPlayerCommand were used in this example. More info about them can be found in corresponding pages.