• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Is there any LUA function which checks if the player is active or inactive?

okurde

New Member
Joined
Jan 28, 2009
Messages
134
Reaction score
1
Hello! If player exits on no logout tile than he is sill in game. I want to check all players - when player is active (normally playing) or inactive (exit on no logout tile). Hmm... Is there any function which can check it?

Code:
for _, pid in ipairs(getPlayersOnline()) do
   [ check if pid is active or exited ]
end

Does anyone have any idea how it can be made?
 
if Player("playerName") then print(playerName.." is online") else print(playerName.." does not exist or is offline") end
 
Hes not saying if hes online or not...Active as in has been doing something on the game recently. Not AFK.

No there is no script for that. You would have to set up a script that flags the player as "AFK" set a storage value or something....then use that storage value in the other script to see if they are active or not.
 
Code:
if player:pos5minAgo() and player:getPosition() == player:pos5minAgo() then print(player:getId().."  has not moved for 5 minutes") end

local playerPositionsHistory = {}
function Player:pos5minAgo()
local cid = self:getId()
return playerPositionsHistory[cid]
end
 
Looks to me like he wants to determine of a player is xlogged or not. After briefly skimming over the github, the best way I could find was player:getIp()
If the player is logged in and playing it will return their ip.
If the player is logged in but the client is disconnected (xlogged) it will return 0

Here is a little something you could add to your lib to make things easier:
Code:
function Player.isConnected(self)
    return self:getIp() > 0
end

Usage:
Code:
if(player:isConnected()) then
    print("Hes Connected!")
else
    print("Hes Gone :(")
end
 
Looks to me like he wants to determine of a player is xlogged or not. After briefly skimming over the github, the best way I could find was player:getIp()
If the player is logged in and playing it will return their ip.
If the player is logged in but the client is disconnected (xlogged) it will return 0

Here is a little something you could add to your lib to make things easier:
Code:
function Player.isConnected(self)
    return self:getIp() > 0
end

Usage:
Code:
if(player:isConnected()) then
    print("Hes Connected!")
else
    print("Hes Gone :(")
end

Thanks you, but ss there any working script for TFS 0.4/0.3.7?
 
As Xagul metioned, you can check by ip:

Code:
function hasConnection(cid)
    return getPlayerIp(cid) > 0 and true or false
end

for _, pid in ipairs(getPlayersOnline()) do
    if not hasConnection(pid) then
        print(getCreatureName(pid), "Not connected.")
        doRemoveCreature(pid)
    end
end
 
Not sure if it is just my version of 0.4 but if the player is xlogged, getPlayerIp still returns their last ip. hasPlayerClient does work however.
Hm no idea, he should try out and change then function if it does not work :P
 
Back
Top