- Joined
- Jan 15, 2014
- Messages
- 1,318
- Solutions
- 35
- Reaction score
- 435
Hello OtLand Community,
I'm trying to get this lottery system to work on TFS 1.0 and i've gotten stuck at one point. I think the problem is that it can't find the online players, but maybe you guys know better.
Here is the Code:
I'm trying to get this lottery system to work on TFS 1.0 and i've gotten stuck at one point. I think the problem is that it can't find the online players, but maybe you guys know better.
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/lottery.lua:onThink
data/globalevents/scripts/lottery.lua:25: attempt to concatenate a boolean value
stack traceback:
[C]: in function '__concat'
data/globalevents/scripts/lottery.lua:25: in function <data/globalevents
/scripts/lottery.lua:7>
Here is the Code:
Code:
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2195, 2472, 2514, 2157, 8902}, -- Rewards ID
crystal_counts = 10, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval)
if(getWorldCreatures(0) == 0)then
return true
end
local players = getOnlinePlayers()
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)]
if(random_item == 2157) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
broadcastMessage("[LOTTERY SYSTEM] Winner: " .. getPlayerName(winner) .. ", Reward: " .. config.crystal_counts .. " " .. getItemName(random_item) .. "s! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
else
broadcastMessage("[LOTTERY SYSTEM] Winner: " .. getPlayerName(winner) .. ", Reward: " .. getItemName(random_item) .. "! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
doPlayerAddItem(winner, random_item, 1)
end
if(config.website == "yes") then
db.query("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getPlayerName(winner) .."', '".. getItemName(random_item) .."');")
end
return true
end