• 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!

TFS 1.3 Lottery System

dredwan

New Member
Joined
Feb 9, 2013
Messages
20
Reaction score
2
I got a problem with this script and i don't know why..

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
 
Lua:
local lottery = GlobalEvent("lottery")

local config = {
    interval = "1 minute",
    rewards = {[3043] = 5, [22118] = 2, [10218] = 1}, -- Rewards aleatorio, separados por coma, 2160 es crystal coin = cuantos, 2152, platinium coins, cuantos, 24774 son tibia coins, cuantos etc
    website = false
}

function lottery.onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end

    local c = #players
    if c <= 0 then
        return true
    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 .. ")")

    return true
end

lottery:interval(60000) --- aqui son 1 minut, hay que modificarlo si se quiere augmentar o disminuir
lottery:register()

credits to: Alex
 
Lua:
local config = {
    interval = "1 hours",
    rewards = {[6527] = 75, [6527] = 100, [2160] = 100},
    -- [itemid] = count; [6527] = 50 - it gives 50 crystal coins
    website = false
}
 
function onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end
 
    local c = #players
    if c <= 0 then
        return true
    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 .. ")")
 
    return true
end
its work every hour
and in globalevent.xml put\/
Code:
        <globalevent name="Lottery" interval="3600000" script="lottery.lua"/>
 
Back
Top