-- by vDk
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
rewards_id = {5887, 5875, 6097, 6098, 6489, 7887, 2170, 10220, 7889, 8855, 2426, 2381, 7436, 2435, 7419, 3976, 5091, 2580, 5710, 5942, 7430, 7415, 2423, 7379, 2393, 8910, 8922, 8900, 2475, 2470, 2648, 2464, 2481, 2457, 7886, 2201, 2460, 2478, 2467, 2649, 2171, 2476, 2463, 2647, 2195, 2520, 2488, 2160}, -- Rewards ID
crystal_counts = 1, -- Used only if on rewards_id is crystal coin (ID: 2160).
website = "yes" -- Only if you have php scripts and table `lottery` in your database!
}
function onThink(interval, lastExecution)
if getWorldCreatures(0) > 0 then
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 == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. config.crystal_counts .. " " .. getItemNameById(random_item) .. "s! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
else
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. getItemNameById(random_item) .. "! 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`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
end
return true
end
return true
end