• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Function isPlayerOnline

Shinmaru

エロルアー Scripter!
Joined
Aug 20, 2007
Messages
1,988
Reaction score
88
Location
Puerto Rico
Ok I've made a function to check if a player is online, but not sure if it's correctly done.

LUA:
function isPlayerOnline(cid)
	local players = {}
	for _, pid in ipairs(getPlayersOnline()) do
		table.insert(players, pid)
	end
	local online = players[cid]
	if online then
		return true
	end
return false	
end
 
LUA:
function isPlayerOnline(cid)
	local online = false
	for _, pid in ipairs(getPlayersOnline()) do
		if cid == pid then
			online = true
		end
	end
	return online
end
 
Last edited:
LUA:
function isPlayerOnline(cid)
	for _, pid in ipairs(getPlayersOnline()) do
		if cid == pid then
			return true -- no need to iterate next ones
		end
	end
	return false
end

Should work same:
LUA:
function isPlayerOnline(cid)
        return isPlayer(cid)
end
Fixed. Didnt you wanted to use isPlayerOnline(name) ? This one is kinda useless.
 
Last edited:
Should work same:
LUA:
function isPlayerOnline(cid)
        return isPlayer(cid)
end
Fixed. Didnt you wanted to use isPlayerOnline(name) ? This one is kinda useless.
Virrages's worked fine and so will yours.
Useless!? Maybe, but I use this on looped addEvents, just in case the player logout the loop does not keep going on an infinite cycle.
 
Useless!? Maybe, but I use this on looped addEvents, just in case the player logout the loop does not keep going on an infinite cycle.

Thats why its useless since u can use just isPlayer() or isCreature(). No need to loop playersOnline to check it.
 
Back
Top