GetPlayerIdleTime: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(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...")
 
(Remove obsolete Requirements section)
 
(8 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server function}}
{{New feature|3.0120|1.2|
This function gets the amount of time in milliseconds that a players position has not changed.
'''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==
==Syntax==
Line 10: Line 7:
int getPlayerIdleTime ( player thePlayer )
int getPlayerIdleTime ( player thePlayer )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[player]]:getIdleTime|idleTime|}}
===Required Arguments===
===Required Arguments===
*'''thePlayer''': The [[player]] you wish to get the idle time of.
*'''thePlayer''': The [[player]] you wish to get the idle time of.


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


==Example==
==Example==
Line 21: Line 18:
This example will kick a player if they don't move for 5 minutes and the resource has access to "function.kickPlayer"
This example will kick a player if they don't move for 5 minutes and the resource has access to "function.kickPlayer"
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function checkAFKPlayers()
setTimer(
    for index, thePlayer in ipairs(getElementsByType("player")) -- Loop all online players
    function()
        if (getPlayerIdleTime(thePlayer) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes)
        for _, player in ipairs(getElementsByType("player"))do -- Loop thru every player
            kickPlayer(thePlayer, "Idle for 5 minutes") -- Kick the idle player
            if (getPlayerIdleTime(player) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes)
                kickPlayer(player, "Idle for 5 minutes") -- Kick the idling player
            end
         end
         end
     end
     end,
end
30000, 0) -- Timer to execute every 30 seconds, checking for idlers
setTimer(checkAFKPlayers, 30000, 0) -- Timer to execute every 30 seconds, checking for idlers
 
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions|server}}

Latest revision as of 15:33, 7 November 2024

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

Syntax

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

Returns the amount of time in milliseconds 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"

setTimer(
    function()
        for _, player in ipairs(getElementsByType("player"))do -- Loop thru every player
            if (getPlayerIdleTime(player) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes)
                kickPlayer(player, "Idle for 5 minutes") -- Kick the idling player
            end
        end
    end,
30000, 0) -- Timer to execute every 30 seconds, checking for idlers

See Also