<?xml version="1.0" encoding="UTF-8"?>
<mod name="Lottery System" version="1.2" author="vDk" contact="[email protected]" enabled="yes">
<config name="lottery_config"><![CDATA[
config =
{
lottery_hour = "3 Hours", -- Time to next lottery (This is only only for broadcast message. Real time you set in "interval" after config section)
rewards_id = {2494, 2472, 2514, 2160, "points"}, -- Rewards ID
crystal_counts = 10, -- used only if on rewards_id you have crystal coins (ID: 2160).
points = 15, -- ile punktów
website = "no" -- Do you have `lottery` table in your database?
}
]]></config>
<globalevent name="lottery" interval="10800" event="script"><![CDATA[
domodlib('lottery_config')
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)
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 ..')')
elseif(random_item == "points") then
db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + '.. config.points..' WHERE `name` = '.. getAccountByName(winner) ..';")
doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: Premium Points! 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`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."');")
end
return TRUE
end
]]></globalevent>
</mod>