-- Globalevent script, run it etc every 1 or 5 min.
function onThink(interval)
-- timestamp = timestamp on when player was last active.
local timestampStorage = 31515
--...
-- 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
function onSay(cid, words, param)
local player = Player(cid) -- The player that triggered this script
local players = Game.getPlayers() -- All online players
local playerCount = Game.getPlayerCount() -- Count of all players
local activeplayers = 0; -- Active players
local consideredafk = (8 * 60) -- You are considered afk/inactive after 8 minutes.
local msg = "" -- Build up the response text
-- timestamp = timestamp on when player was last active.
local timestampStorage = 31515
-- Loop through all online players
for k, tmpPlayer in ipairs(players) do
-- Fetch the storage value they have saved timestamp in
local playerTimestamp = tmpPlayer.getStorageValue(timestampStorage)
-- If timestamp on the player is not older than configured afk timer
if playerTimestamp > os.time() - consideredafk then
-- Sum the active player
activeplayers = activeplayers + 1
-- Append his name to the response text
msg = msg .. tmpPlayer:getName() .. ", "
end
end
-- Prepend how many players are active before listing the names
msg = "Active players: " .. activeplayers .. ". Names: " .. msg
-- Send the response text
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
return false
end