• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

TFS 1.3 Lottery System

dredwan

New Member
Joined
Feb 9, 2013
Messages
19
Reaction score
1
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
 

lopez65

Member
Joined
May 10, 2012
Messages
286
Solutions
1
Reaction score
14
Location
Barcelona
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
 

abdala ragab

Banned User
Joined
Aug 18, 2018
Messages
306
Solutions
10
Reaction score
272
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"/>
 
Top