I got a problem with this script and i don't know why..
this is the problem:
Lua:
--[[
ACCOUNT_TYPE_NORMAL = 1,
ACCOUNT_TYPE_TUTOR = 2,
ACCOUNT_TYPE_SENIORTUTOR = 3,
ACCOUNT_TYPE_GAMEMASTER = 4,
ACCOUNT_TYPE_GOD = 5
]]
local config = {
interval = "1 minute",
rewards = {[2160] = 3},
-- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
website = false
}
local lotterySystem = GlobalEvent("LotterySystem")
function lotterySystem.onThink(interval)
if Game.getPlayerCount() == 0 then
return true
end
local players = {}
for _, player in ipairs(Game.getPlayers()) do
if player:getAccountType() <= 1 then
table.insert(players, player)
end
end
local winner = players[math.random(#players)]
local items = {}
for itemid, count in pairs(config.rewards) do
items[#items + 1] = itemid
end
local itemid = items[math.random(1, #items)]
local amount = config.rewards[itemid]
winner:addItem(itemid, amount)
local it = ItemType(itemid)
local name = ""
if amount == 1 then
name = it:getArticle() .. " " .. it:getName()
else
name = amount .. " " .. it:getPluralName()
end
broadcastMessage("[LOTTERY SYSTEM] " .. winner:getName() .. " won " .. name .. "! Congratulations! (Next lottery in " .. config.interval .. ")")
if config.website then
db.query("INSERT INTO `lottery` (`name`, `item`) VALUES (\"".. db.escapeString(winner:getName()) .."\", \"".. db.escapeString(it:getName()) .."\");")
end
return true
end
lotterySystem:interval(60000)
lotterySystem:register()
this is the problem:
Code:
\data\scripts\globalevents\lottery_system.lua:41: attempt to index local 'winner' (a nil value)
stack traceback:
[C]: in function '__index'
...global-main\data\scripts\globalevents\lottery_system.lua:41: in function <...global-main\data\scripts\globalevents\lottery_system.lua:19>
[2021-21-12 12:11:46.762] [error] [GlobalEvents::think] - Failed to execute event: LotterySystem