getPlayerPing | Multi Theft Auto: Wiki Skip to content

getPlayerPing

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


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.

OOP Syntax Help! I don't understand this!

  • Method:player:getPing(...)
  • Variable: .ping

Syntax

int getPlayerPing ( player thePlayer )
Required Arguments
  • thePlayer: The player whose ping you want to determine.

Returns

  • int: value

Returns the ping as an int , or false if the player is invalid.

Code Examples

shared

This 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.

See Also