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

Lua Lottery globalevent for tfs 1.2 error

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
922
Location
Chile
Hello guys, i have tfs 1.2 and i get this silly error but i cant fix it, well this is the script:

LUA:
local rewards = {
    {itemid = 28783, count = 1},
}
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players > 0 then
        while true do
            local player = players[math.random(#players)]
            if not player:hasAccess() and player:getAccountType() == ACCOUNT_TYPE_NORMAL then
                local reward = rewards[#rewards]
                local item = player:addItem(reward.itemid, math.random(reward.count))
                local itemName = item:getCount() > 1 and item:getPluralName() or item:getName()
                Game.broadcastMessage(('[LOTTERY] %s has won %d %s, next lottery in 24 hours'):format(player:getName(), item:getCount(), itemName), MESSAGE_STATUS_CONSOLE_ORANGE)
                break
            end
        end
    return true
end

and this is the error:
Code:
[Warning - Event::checkScript] Can not load script: scripts/lottery.lua
data/globalevents/scripts/lottery.lua:19: 'end' expected (to close 'function' at line 5) near <eof>

plz help :(
 
Last edited by a moderator:
LUA:
local rewards = {
    {itemid = 28783, count = 1}
}
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players > 0 then
        while true do
            local player = players[math.random(#players)]
            if not player:hasAccess() and player:getAccountType() == ACCOUNT_TYPE_NORMAL then
                local reward = rewards[#rewards]
                local item = player:addItem(reward.itemid, math.random(reward.count))
                local itemName = item:getCount() > 1 and item:getPluralName() or item:getName()
                Game.broadcastMessage(('[LOTTERY] %s has won %d %s, next lottery in 24 hours'):format(player:getName(), item:getCount(), itemName), MESSAGE_STATUS_CONSOLE_ORANGE)
                break
            end
        end
    end
    return true
end
 
LUA:
local rewards = {
    {itemid = 28783, count = 1}
}
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players > 0 then
        while true do
            local player = players[math.random(#players)]
            if not player:hasAccess() and player:getAccountType() == ACCOUNT_TYPE_NORMAL then
                local reward = rewards[#rewards]
                local item = player:addItem(reward.itemid, math.random(reward.count))
                local itemName = item:getCount() > 1 and item:getPluralName() or item:getName()
                Game.broadcastMessage(('[LOTTERY] %s has won %d %s, next lottery in 24 hours'):format(player:getName(), item:getCount(), itemName), MESSAGE_STATUS_CONSOLE_ORANGE)
                break
            end
        end
    end
    return true
end

im sorry man but i have this in console

Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/lottery.lua:onThink
data/globalevents/scripts/lottery.lua:9: attempt to call method 'hasAccess' (a nil value)
stack traceback:
        [C]: in function 'hasAccess'
        data/globalevents/scripts/lottery.lua:9: in function <data/globalevents/scripts/lottery.lua:4>
 
@Thorn change hasAccess() to getAccess()
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/lottery.lua:onThink
data/globalevents/scripts/lottery.lua:9: attempt to call method 'getAccess' (a nil value)
stack traceback:
        [C]: in function 'getAccess'
        data/globalevents/scripts/lottery.lua:9: in function <data/globalevents/scripts/lottery.lua:4>
[Error - GlobalEvents::think] Failed to execute event: lottery

:(
 
LUA:
local rewards = {
['easy'] = {items = {
        [1] = {itemid = 1111, amount = 1},
        [2] = {itemid = 1111, amount = 1}
        }},
['medium'] = {items = {
        [1] = {itemid = 1111, amount = 1},
        [2] = {itemid = 1111, amount = 1}
        }},
['hard'] = {items = {
        [1] = {itemid = 1111, amount = 1},
        [2] = {itemid = 1111, amount = 1}
        }}
}
local chance_easy = {1, 100)
local chance_medium = {101, 150}
local chance_hard = {151, 170}
function onThink(interval)
    local rand = math.random(1, 170)
        if rand >= chance_easy[1] and rand <= chance_easy[2] then
            local item_rand = math.random(1, #rewards['easy'].items)
            local ITEMID = rewards['easy'].items[item_rand].itemid
            local ITEMAMOUNT = rewards['easy'].items[item_rand].amount
        elseif rand >= chance_medium[1] and rand <= chance_medium[2] then
            local item_rand = math.random(1, #rewards['medium'].items)
            local ITEMID = rewards['medium'].items[item_rand].itemid
            local ITEMAMOUNT = rewards['medium'].items[item_rand].amount
        elseif rand >= chance_hard[1] and rand <= chance_hard[2] then
            local item_rand = math.random(1, #rewards['hard'].items)
            local ITEMID = rewards['hard'].items[item_rand].itemid
            local ITEMAMOUNT = rewards['hard'].items[item_rand].amount
        end
    
        if ITEMID and ITEMAMOUNT then
            local players_table = {}
            local players = Game.getPlayers()
            for i, v in ipairs(players) do
                local player = Player(v)
                if player then
                    if not player:getGroup():getAccess() and player:getAccountType() == ACCOUNT_TYPE_NORMAL then
                        table.insert(players_table, player)
                    end
                end
            end
            local rand_player = players_table[math.random(1, #players_table)]
            local player = Player(rand_player)
            if player then
                ITEM = player:addItem(ITEMID, ITEMAMOUNT)
                local ITEMTYPE = ItemType(ITEM)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have won the lottery! You received: "..ITEMAMOUNT.." "..ITEMTYPE:getName().."(s)!")
                Game.broadcastMessage("Player: "..getPlayerName(player).." has won the lottery and recieved: ".ITEMAMOUNT.." "..ITEMTYPE:getName().."(s)!")
            end
        end
return true
end
 
Last edited:
Back
Top