local config = {
lottery_hour = "30 Minutes", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
rewards_id = {2145}, -- Rewards ID
crystal_counts = 3, -- Used only if on rewards_id is crystal coin (ID: 2160).
website = "no" -- Only if you have php scripts and table `lottery` in your database!
}
function onThink(interval, lastExecution)
local list = {}
for i, tid in ipairs(getPlayersOnline()) do
list[i] = tid
end

local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]

if(random_item == 2145) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage("[LOTTERY SYSTEM] Ganhador: " .. getCreatureName(winner) .. ", Prêmio: " .. config.crystal_counts .. " " .. getItemNameById(random_item) .. "s! Parabéns! (Proxima Loteria em " .. config.lottery_hour .. ")")
else
doBroadcastMessage("[LOTTERY SYSTEM] Ganhador: " .. getCreatureName(winner) .. ", Prêmio: " .. getItemNameById(random_item) .. "! Parabéns! (Proxima Loteria em " .. config.lottery_hour .. ")")
doPlayerAddItem(winner, random_item, 1)
end

if(config.website == "yes") then
db.query("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
end
return true
end