• 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 Anyone know how to put this script to only 30 top level online win the prize?

anotapreta

New Member
Joined
Mar 12, 2010
Messages
104
Reaction score
0
Anyone know how to put this script to only 30 top level online win the prize?
Anyone know how to put this script to only 30 top level online win the prize?
Anyone know how to put this script to only 30 top level online win the prize?


Lua:
local config = {
lottery_hour = "16 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2534, 2363, 5785, 2363, 8900, 2520, 2519, 2195, 10523, 10523, 7892, 2114, 10515, 2466, 2491, 2173, 5957, 5957, 5957, 5957, 5957, 5957, 9003, 6527, 5952, 8303, 5952, 5952, 2160}, -- Rewards ID
crystal_counts = 10, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
local list = {}
for i, tid in ipairs(players) do
list[i] = tid 
end

local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(random_item)
local world = tonumber(getPlayerWorldId(winner))
local level = tonumber(getPlayerLevel(winner))


if #list >= 0 then
if level >= 30 then
if(random_item == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
else

doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
doPlayerAddItem(winner, random_item, 1)
end

if(config.website == "yes") then
db.executeQuery("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
end
end
return TRUE
end

Anyone know how to put this script to only 30 top level online win the prize?
Anyone know how to put this script to only 30 top level online win the prize?
Anyone know how to put this script to only 30 top level online win the prize?
 
Last edited:
Lua:
function onThink(cid, interval, lastExecution)
local config = {
hours = 16,
items = {{2534,1}, {2363,1}, {5785,1}, {2363,1}, {8900,1}, {2520,1}, {2519,1}, {2195,1}, {10523,1}, {10523,1}, {7892,1}, {2114,1}, {10515,1}, {2466,1}, {2491,1}, {2173,1}, {5957,1}, {5957,1}, {5957,1}, {5957,1}, {5957,1}, {5957,1}, {9003,1}, {6527,1}, {5952,1}, {8303,1}, {5952,1}, {5952,1}, {2160,10}},
website = true -- Do you have `lottery` table in your database?
}
local on,list= getPlayersOnline(),{}
if #on > 0 then
local max_players = #on >= 30 and 30 or #on
local query = db.getResult("SELECT `name`, `level` FROM `players` WHERE `online` > 0 AND `id` > 6 AND `group_id` < 2 ORDER BY `level` DESC, `name` ASC;")
if (query:getID() ~= -1) then k = 1 while true do
table.insert(list, getPlayerByNameWildcard(query:getDataString("name"))) 
k = k + 1
if not(query:next()) or k > max_players then break end end query:free() end
local p,r = list[math.random(#list)],config.items[math.random(#config.items)]
doPlayerAddItem(p, r[1], r[2] or 1)
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(p) .. ", Reward: "..r[2].." "..getItemNameById(r[1]).."! Congratulations! (Next Lottery in "..config.hours..")")
if(config.website == true) then
local world = tonumber(getPlayerWorldId(p))
db.executeQuery("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(p) .."', '".. getItemNameById(r[1]) .."', '".. world .."');")
end  
end    
return true
end
 
Last edited:
Back
Top