this, I'm trying to create a check for 1 npc that will only talk to the top 3Do you mean that you want to get top 3 players with highest value in columntop_pontos
?
local lastTop3PlayersRefresh = 0
local top3PlayersCache = {}
function getTop3Players()
if lastTop3PlayersRefresh + 60 < os.time() then
top3PlayersCache = {}
lastTop3PlayersRefresh = os.time()
local resultId = db.storeQuery("SELECT id FROM players ORDER BY top_pontos DESC LIMIT 3")
if resultId ~= false then
repeat
table.insert(top3PlayersCache, result.getDataInt(resultId, "id"))
until not result.next(resultId)
result.free(resultId)
end
end
return top3PlayersCache
end
function isTop3Player(player)
local top3Players = getTop3Players()
local playerGuid = player:getGuid()
for _, guid in pairs(top3Players) do
if playerGuid == guid then
return true
end
end
return false
end
isTop3Player(player)
and it will return true
/false
.local resultId = db.storeQuery("SELECT id FROM players ORDER BY top_pontos DESC LIMIT 3")
local resultId = db.storeQuery("SELECT id FROM players WHERE top_pontos > 0 ORDER BY top_pontos DESC LIMIT 3")
local function creatureSayCallback(cid, type, msg)otservbr / TFS 1.2+ code:
I don't know how you want to block it in NPC, but you must call functionLUA:local lastTop3PlayersRefresh = 0 local top3PlayersCache = {} function getTop3Players() if lastTop3PlayersRefresh + 60 < os.time() then top3PlayersCache = {} lastTop3PlayersRefresh = os.time() local resultId = db.storeQuery("SELECT id FROM players ORDER BY top_pontos DESC LIMIT 3") if resultId ~= false then repeat table.insert(top3PlayersCache, result.getDataInt(resultId, "id")) until not result.next(resultId) result.free(resultId) end end return top3PlayersCache end function isTop3Player(player) local top3Players = getTop3Players() local playerGuid = player:getGuid() for _, guid in pairs(top3Players) do if playerGuid == guid then return true end end return false end
isTop3Player(player)
and it will returntrue
/false
.
I added cache, to do not send too many queries to database. It updates list of top 3 players every 60 seconds.
If you want to get only players with more than 0 points, replace:
with:LUA:local resultId = db.storeQuery("SELECT id FROM players ORDER BY top_pontos DESC LIMIT 3")
LUA:local resultId = db.storeQuery("SELECT id FROM players WHERE top_pontos > 0 ORDER BY top_pontos DESC LIMIT 3")