-- Returns the 'cid' of the highest level online player.
function getHighestLevelOnlinePlayer()
local highest = {
level = 0,
player = 0
}
for _, name in ipairs(getOnlinePlayers()) do -- Loop through all online players
local cid = getPlayerByName(name)
if isPlayer(cid) then
if getPlayerLevel(cid) > highest.level then
highest.level = getPlayerLevel(cid)
highest.player = cid
end
end
end
print("Highest level online player was: " ...
-- Returns the 'cid' of the highest level online player.
function getHighestLevelOnlinePlayer()
local highest = {
level = 0,
player = 0
}
for _, name in ipairs(getOnlinePlayers()) do -- Loop through all online players
local cid = getPlayerByName(name)
if isPlayer(cid) then
if getPlayerLevel(cid) > highest.level then
highest.level = getPlayerLevel(cid)
highest.player = cid
end
end
end
print("Highest level online player was: " .. getCreatureName(highest.player) .. " with level " .. highest.level .. ".")
return highest.player
end
thanks but how to make it with MySQL, and also Iwill add a level min, so it start loop when player level > 300
-- Returns the 'cid' of the highest level online player via query.
function getHighestLevelOnlinePlayer()
local query = db.getResult("SELECT `id` FROM `players` WHERE `online` = 1 ORDER BY `level` DESC LIMIT 1;")
local guid = query:getDataInt("id")
if guid > 0 then
return getCreatureByName(getPlayerNameByGUID(guid))
else
return 0
end
end
-- Returns the 'cid' of the highest level online player.
function getHighestLevelOnlinePlayer()
local highest = {
level = 0,
player = 0
}
if getOnlinePlayers() >= 1 then
for _, name in ipairs(getOnlinePlayers()) do -- Loop through all online players
local cid = getPlayerByName(name)
if isPlayer(cid) then
if getPlayerLevel(cid) > highest.level then
highest.level = getPlayerLevel(cid)
highest.player = cid
end
end
end
end
print("Highest level online player was: " .. getCreatureName(highest.player) .. " with level " .. highest.level .. ".")
return highest.player
end
no bro I did that but if getOnlinePlayers() >= 1 then
error: attempt to compare number with table for this line
-- Returns the 'cid' of the highest level online player.
function getHighestLevelOnlinePlayer()
local highest = {
level = 0,
player = 0
}
local online_players = getOnlinePlayers()
if online_players and #online_players > 0 then
for _, name in ipairs(online_players) do -- Loop through all online players
local cid = getPlayerByName(name)
if isPlayer(cid) and getPlayerLevel(cid) > highest.level then
highest.level = getPlayerLevel(cid)
highest.player = cid
end
end
end
print("Highest level online player was: " .. getCreatureName(highest.player) .. " with level " .. highest.level .. ".")
return highest.player
end
Why would you want to get highest online player through sql? You can already check online players, sql would only be needed if the player you are searching for is offline.