• 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!

isPlayerOnline(name)

Shawak

Intermediate OT User
Joined
Sep 11, 2008
Messages
1,984
Solutions
2
Reaction score
119
Location
Germany
GitHub
Shawak
This function check, if the player is online :).

Version:
TFS 0.3.5.

data/lib/functions.lua at the end, add:
Lua:
function isPlayerOnline(name)
	local result = db.getResult("SELECT `online` FROM `players` WHERE `name` = '"..name.."';")
	return result:getDataInt("online") == 1 and TRUE or FALSE
end

Example:
Lua:
function onSay(cid, words, param, channel)
	if isPlayerOnline(param) == TRUE then
		doPlayerSendTextMessage(cid, 18, ""..param.." is online.")
	else
		doPlayerSendTextMessage(cid, 18, ""..param.." is offline.")
	end
	return TRUE
end

I hope you like it :).

Regards,
Shawak
 
Simple but usefull!
Should be implemented into 0.3.5!
 
Code:
if (getPlayerByName(param) == true) then
do something
end

Why?

Cause `online` = 1 in sometimes is while player is offline. Crash etc.
 
Code:
if (getPlayerByName(param) == true) then
do something
end

Why?

Cause `online` = 1 in sometimes is while player is offline. Crash etc.

:eek:, don't know that, i change script now.

EDIT:

1. Why crashes?
 
I mean when server crash then player's `online` column is still 1, but player is offline.
 
I mean when server crash then player's `online` column is still 1, but player is offline.

Not realy, look in TFS 0.3.5 globalevents:
Lua:
function onStartup()
	db.executeQuery("UPDATE `players` SET `online` = 0 WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
	return TRUE
end
 
instead using a query you could do

players = getonlineplayers
ret = false

for _, player in ipairs(players) do
if string.lower(getcreaturename(player)) == string.lower(param?) then
ret = true
break
end
end


however nice way
 
but i'm showing you other way to do the same using less memory.
..not decided people.

@Nahruto: If you have 500+ players online, it laaaag? :)
 
Cause i not mean getPlayerByName is faster than your query, but doCombatHealth is faster than yours loop + getThingFromPos.
 
Cause i not mean getPlayerByName is faster than your query, but doCombatHealth is faster than yours loop + getThingFromPos.

I know and i mean:

for _, player in ipairs(players) do
if string.lower(getcreaturename(player)) == string.lower(param?) then
ret = true
break
end
end

I thing 1 query is faster :).

@chris77: Thanks + Nice Spammer :thumbup:.
 
Nice spammer because i beleive this was a nice script which i could use on my server for some unique things? lmao
 
Back
Top