From Multi Theft Auto: Wiki
Jump to: navigation, search

This function gets the amount of time in milliseconds that a players position has not changed.


int getPlayerIdleTime ( player thePlayer )

OOP Syntax Help! I don't understand this!

Method: player:getIdleTime(...)
Variable: .idleTime

Required Arguments

  • thePlayer: The player you wish to get the idle time of.


Returns the amount of time in milliseconds that a player has been idle, false otherwise.


Click to collapse [-]
Serverside example

This example will kick a player if they don't move for 5 minutes and the resource has access to "function.kickPlayer"

function checkAFKPlayers()
    for index, thePlayer in ipairs(getElementsByType("player"))do -- Loop all online players
        if (getPlayerIdleTime(thePlayer) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes)
            kickPlayer(thePlayer, "Idle for 5 minutes") -- Kick the idle player
setTimer(checkAFKPlayers, 30000, 0) -- Timer to execute every 30 seconds, checking for idlers


Minimum supported server 1.1.1-9.03316
Minimum supported client n/a
Note: Using this function requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.1.1-9.03316" />

See Also