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

[LUA] getting 5 highest storage counts to broadcast

straher

???
Joined
Mar 23, 2010
Messages
255
Reaction score
3
Hi, my system counts frags as storage values and I'd like to add top 5 storage broadcast. Can anyone help me with it?

I've found those 2 pieces of code:

This one casts broadcast but it doesn't take frag amounts from storage but killers

Lua:
[local config = {
    limit = 5
}
function onThink(interval, lastExecution)
    local t, ret, tmp = {}, "Top " .. math.min(config.limit, getWorldCreatures(0)) .. " fraggers online:"
    for _, cid in ipairs(getPlayersOnline()) do
        tmp = db.getResult("SELECT COUNT(*) as count FROM killers WHERE death_id IN (SELECT kill_id FROM player_killers) AND " .. getPlayerGUID(cid) .. " IN (SELECT player_id FROM player_killers WHERE kill_id = death_id)")
        table.insert(t, {cid, tmp:getDataInt("count")})
        tmp:free()
    end
    table.sort(t, function(a,b) return a[2] > b[2] end)
    for i = 1, math.min(#t, config.limit) do
        ret = ret .. "\n" .. i .. ". " .. getPlayerName(t[i][1]) .. " - " .. t[i][2] .. " frags"
    end
    return doBroadcastMessage(ret)
end


db query:

PHP:
$i = 0; 
foreach($SQL->query('SELECT  `p`.`name` AS  `name` ,  `value` AS  `storagevalue` 
FROM  `player_storage` k
LEFT JOIN  `players` p ON  `k`.`player_id` =  `p`.`id` 
WHERE  `k`.`key` =6776
GROUP BY  `name` 
ORDER BY CAST(  `value` AS SIGNED ) DESC 
LIMIT 0 , 30;') as $player)
 
Last edited:
Well you could try this and tell me what are the errors you get
Lua:
local frag_storage = 12245  -- the frag storage id






function onThink(interval)


	local query = [[SELECT `players.name` AS `name` FROM `players` INNER JOIN `player_storage` ON `players.id` = `player_storage.player_id`
	WHERE `player_storage.key` = ]].. frag_storage ..[[
	ORDER BY `player_storage.value` DESC
	LIMIT 5;]]




	local Info = db.getResult(query)


	local players = {}
	if (Info:getID() ~= -1) then
		while true do
			table.insert(players, Info:getDataString("name"))
			if not Info:next() then
				break
			end
		end
		Info:free()
	end	
	
	local txt = "Top 5 fraggers : "
	for k, v in ipairs(players) do
		txt = txt .."".. k ..")".. v .. ((k < #players) and "\n" or "")
	end
	
	for _,cid in ipairs(getPlayersOnline()) do 
		doPlayerSendTextMessage(cid, 19,txt)
	end
	
	return true
end
 
Back
Top