-- Globalevent script, run it etc every 1 or 5 min.
function onThink(interval)
-- timestamp = timestamp on when player was last active.
local timestampStorage = 31515
-- pos storages = which position the player was in last time he was active.
local posXstorage = 31516
local posYstorage = 31517
local posZstorage = 31518
local players = Game.getPlayers() -- All online players
-- Loop through all online players
for k, tmpPlayer in ipairs(players) do
-- Get player current position
local playerPosition = tmpPlayer:getPosition()
-- Check if current position == old position
if playerPosition.x == tmpPlayer.getStorageValue(posXstorage) and playerPosition.y = tmpPlayer.getStorageValue(posYstorage) and playerPosition.z = tmpPlayer.getStorageValue(posZstorage) then
-- Same position, considered afk. Do nothing.
else
-- User is active, save timestamp and new position
-- Set timestamp
tmpPlayer.setStorageValue(timestampStorage, os.time())
-- Set new positions
tmpPlayer.setStorageValue(posXstorage, playerPosition.x)
tmpPlayer.setStorageValue(posYstorage, playerPosition.y)
tmpPlayer.setStorageValue(posZstorage, playerPosition.z)
end
end
return true
end