• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Little problem with a global event.

dominique120

Science & Reason
Senator
Premium User
Joined
Jun 16, 2013
Messages
3,881
Solutions
3
Reaction score
1,046
Location
Númenor
Hi again!

I have this script:

Code:
  function onThink(interval, lastExecution, thinkInterval)
    doBroadcastMessage("We encourage you to invite your friends to this server :-)")
end

And it gives me this error when executed:

Code:
[29/10/2013 18:25:41] > Broadcasted message: "We encourage you to invite your friends to this server :-)".
[29/10/2013 18:25:41] [Error - GlobalEvents::think] Couldn't execute event: reklama

What can I do to fix it?

Thanks!
 
How is it registered in globalevents.xml?

Add return true above end as tetra20 mentioned.
 
Code:
  function onThink(interval, lastExecution, thinkInterval)
    doBroadcastMessage("We encourage you to invite your friends to this server :-)")
return true
end
try this one
 
I also have this little bug with another global event:

Register:
Code:
<globalevent name="lottery" interval="36000" event="script" value="lottery.lua"/>
Script:
Code:
-- by vDk, klekSu
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2160}, -- Rewards ID
crystal_counts = 10, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "no" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
local list = {}
for i, tid in ipairs(players) do
list = 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)
local world = tonumber(getPlayerWorldId(winner))
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 ..')')
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`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
return TRUE
end
Error:
Code:
[30/10/2013 22:39:59] [Error - GlobalEvent Interface]
[30/10/2013 22:39:59] data/globalevents/scripts/lottery.lua:onThink
[30/10/2013 22:39:59] Description:
[30/10/2013 22:39:59] data/globalevents/scripts/lottery.lua:14: attempt to get length of local 'list' (a number value)
[30/10/2013 22:39:59] stack traceback:
[30/10/2013 22:39:59]    data/globalevents/scripts/lottery.lua:14: in function <data/globalevents/scripts/lottery.lua:8>
[30/10/2013 22:39:59] [Error - GlobalEvents::think] Couldn't execute event: lottery
 
Code:
-- by vDk, klekSu
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2160}, -- Rewards ID
crystal_counts = 10, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "no" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
local list = {}
for _, tid in ipairs(players) do
list = 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)
local world = tonumber(getPlayerWorldId(winner))
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 ..')')
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`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
return TRUE
end
 
@tetra20 I get this:

Code:
[31/10/2013 14:25:37] [Error - GlobalEvent Interface]
[31/10/2013 14:25:37] data/globalevents/scripts/lottery.lua:onThink
[31/10/2013 14:25:37] Description:
[31/10/2013 14:25:37] data/globalevents/scripts/lottery.lua:14: attempt to get length of local 'list' (a number value)
[31/10/2013 14:25:37] stack traceback:
[31/10/2013 14:25:37]    data/globalevents/scripts/lottery.lua:14: in function <data/globalevents/scripts/lottery.lua:8>
[31/10/2013 14:25:37] [Error - GlobalEvents::think] Couldn't execute event: lottery

But dont worry about it, I'm just going to disable it. Thanks for the help tough :)
 
Back
Top