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

Lottery System (TFS 1.0)

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,051
Solutions
2
Reaction score
260
Location
United States
If someone could help me i need it so it does not give reward to group id 2-3 (GM, God)

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


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
 
Code:
local config = {
  interval = "1 hour",
  rewards = {[2160] = 3},
  -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
  website = false
}


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

  local players = Game.getPlayers()
  local people_ = {}
   for i = 1,#players do
     if getPlayerGroupId(players[i]) < 2 then
       table.insert(people_, players[i])
     end
   end
  local winner  = people_[math.random(1, #people_)]

  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
it might not work because i used 0.4 function, this Part
Code:
 if getPlayerGroupId(players[i]) < 2 then
 
Try:
Code:
local config = {
  interval = "1 hour",
  rewards = {[2160] = 3},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
  website = false
}


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

  local players = Game.getPlayers()
  local winner  = players[math.random(1, #players)]

   if players:getGroup():getAccess() then
        return true
   end

  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
 
Last edited:
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] = 3},
    -- [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
 
Try:
Code:
local config = {
  interval = "1 hour",
  rewards = {[2160] = 3},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
  website = false
}


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

  if player:getGroup():getAccess() 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
Is it me or your signature looks like hentai *-* , i cant think of anything else, it looks dirty or it is my mind :D also player isn't defined there xD
 
: x

rtkthYG.png
 

Similar threads

Back
Top