• 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.0] Lottery System

imkingran

Learning everyday.
Premium User
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.

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
 
Try this one:
Code:
local config = {
  interval = "3 hours",
  rewards = {[2195] = 1, [2472] = 1, [2514] = 1, [2157] = 1, [8902] = 1},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
  website = true
}


function onThink(interval)
  if Game.getPlayerCount() == 0 then
    return true
  end

  local players = Game.getPlayers()
  local winner  = players[math.random(1, #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
 
do you have the sql tables to showme how add these to mysql? have you linked the lottery players.id with the id of player tables? Can you post the sql changes too?
 
So i am using this lottery system, but i dont believe it works with TFS 1.2 i am trying to make it so GM's and God's cannot get lottery rewards

data/globalevents/scripts/lottery.lua
Code:
--[[
    ACCOUNT_TYPE_NORMAL = 1,
    ACCOUNT_TYPE_TUTOR = 2,
    ACCOUNT_TYPE_SENIORTUTOR = 3,
    ACCOUNT_TYPE_GAMEMASTER = 4,
    ACCOUNT_TYPE_GOD = 5

]]

local config = {
    interval = "1 hour",
    rewards = {[2160] = 5},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function onThink(interval)
    if Game.getPlayerCount() == 0 then
        return true
    end

    local players = {}

    for _, player in ipairs(Game.getPlayers()) do
        if player:getAccountType() <= 2 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

data/xml/groups.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>
 
Back
Top