otservbr / TFS 1.2+ code:
Lua:
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
I don't know how you want to block it in NPC, but you must call function
isTop3Player(player)
and it will return
true
/
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:
Lua:
local resultId = db.storeQuery("SELECT id FROM players ORDER BY top_pontos DESC LIMIT 3")
with:
Lua:
local resultId = db.storeQuery("SELECT id FROM players WHERE top_pontos > 0 ORDER BY top_pontos DESC LIMIT 3")