GetPlayerIdleTime

From Multi Theft Auto: Wiki
Revision as of 20:27, 3 October 2011 by Arran Fortuna (talk | contribs) (Created page with "__NOTOC__ {{Server function}} {{New feature|3.0120|1.2| '''Available only in MTA SA 1.2 and onwards''' }} This function gets the amount of time in miliseconds that a players posi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Available only in MTA SA 1.2 and onwards This function gets the amount of time in miliseconds that a players position has not changed.

Syntax

int getPlayerIdleTime ( player thePlayer )

Required Arguments

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

Returns

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

Example

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")) -- 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
        end
    end
end
setTimer(checkAFKPlayers, 30000, 0) -- Timer to execute every 30 seconds, checking for idlers

See Also