GetPlayerPing
Jump to navigation
Jump to search
This function returns the ping of a specified player. The ping is the number of milliseconds that data takes to travel from the player's client to the server or vice versa. If a player is using a VPN their ping will still be returned correctly.
Syntax
int getPlayerPing ( player thePlayer )
OOP Syntax Help! I don't understand this!
- Method: player:getPing(...)
- Variable: .ping
Required Arguments
- thePlayer: The player whose ping you want to determine.
Returns
Returns the ping as an int, or false if the player is invalid.
Example
Click to collapse [-]
ServerThis example checks every players ping every 5 seconds and if it's over 500 they get kicked.
function kickPing() -- Creates a function called kickPing for i, player in ipairs(getElementsByType("player")) do -- Loop every player if (getPlayerPing(player) >= 500) then -- If their ping is over 500 kickPlayer(player, "Ping over 500!") -- Kick them end end end setTimer(kickPing, 5000, 0) -- Every 5 seconds, the kickPing function is called.
Click to collapse [-]
ClientThis example checks the ping of every player entering the 'ping' command and warns him if it's over 100.
function checkPing() local ping = getPlayerPing(localPlayer) -- get the ping from the source element (the player who joined) if (ping > 100) then -- if it's higher than 100... outputChatBox("Your ping is pretty high! Please try to lower it if possible.") -- output a message to the player end end addCommandHandler("ping", checkPing)
See Also
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState