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

Add different rewards with different amount online people

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
529
Reaction score
56
Hi im using this tfs 1.2 auto lottery script but i wonder is it possible to add different rewards if there is more online people, so like if there is
10-20 online people you get dif items
21-40 online people you get dif items
41-100 online people you get dif items
and etc


Lua:
local config = {
    interval = "4 hours",
    rewards = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function Game.broadcastMessage(message, messageType)
    if messageType == nil then
        messageType = MESSAGE_STATUS_CONSOLE_ORANGE
    end

    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(messageType, message)
    end
end
 
function onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end
 
    local c = #players
    if c <= 0 then
        return true
    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
 
    Game.broadcastMessage("Test" .. winner:getName() .. " won " .. name .. "! (Next lottery in " .. config.interval .. ")")
 
    return true
end
 
Solution
Should works...
Lua:
local config = {
    interval = "4 hours",
    rewards = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    rewards2 = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    rewards3 = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function Game.broadcastMessage(message, messageType)
    if messageType == nil then
        messageType = MESSAGE_STATUS_CONSOLE_ORANGE
    end

    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(messageType, message)
    end
end
 
function onThink(interval)
    local players = {}
    for _, player in...
Line 26 shows you how many players are online.
Lines 33 thru 36 decide what items are selected.

Combine the two together and you have the solution.
 
How can you combine them?
If you want someone to do it for you, so that you learn nothing in the process, post this over in requests.

Else, try something. If you are having trouble getting your code to work, post your non-functioning code and someone will help fix it.

Here's a starting point.
Lua:
if player_count < 10 then
    -- give them items from table_1
elseif player_count < 21 then
    -- give them items from table_2
end
Line 26 shows you how many players are online.
Lines 33 thru 36 decide what items are selected.
 
If you want someone to do it for you, so that you learn nothing in the process, post this over in requests.

Else, try something. If you are having trouble getting your code to work, post your non-functioning code and someone will help fix it.

Here's a starting point.
Lua:
if player_count < 10 then
    -- give them items from table_1
elseif player_count < 21 then
    -- give them items from table_2
end
Isnt it like monkey move to use else every time? Its not possible to achieve everything cleaner? Like in local
 
Should works...
Lua:
local config = {
    interval = "4 hours",
    rewards = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    rewards2 = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    rewards3 = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function Game.broadcastMessage(message, messageType)
    if messageType == nil then
        messageType = MESSAGE_STATUS_CONSOLE_ORANGE
    end

    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(messageType, message)
    end
end
 
function onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end
 
    local c = #players
    if c <= 0 then
        return true
    end
    
    local itemstable = nil
    if c <= 20 then
        itemstable = config.rewards
    elseif c > 20 and c <= 40 then
        itemstable = config.rewards2
    elseif c > 40 and c <= 100 then
        itemstable = config.rewards3
    end
    
    if itemstable = nil then
        return true
    end
    
    local winner  = players[math.random(#players)]
 
    local items = {}
    for itemid, count in pairs(itemstable) do
        items[#items + 1] = itemid
    end
 
    local itemid = items[math.random(1, #items)]
    local amount = itemstable[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
 
    Game.broadcastMessage("Test" .. winner:getName() .. " won " .. name .. "! (Next lottery in " .. config.interval .. ")")
 
    return true
end
 
Solution
Should works...
Lua:
local config = {
    interval = "4 hours",
    rewards = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    rewards2 = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    rewards3 = {[12757] = 1, [12779] = 10, [12778] = 10, [12780] = 5, [2160] = 20, [12764] = 1, [2678] = 50},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function Game.broadcastMessage(message, messageType)
    if messageType == nil then
        messageType = MESSAGE_STATUS_CONSOLE_ORANGE
    end

    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(messageType, message)
    end
end

function onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end

    local c = #players
    if c <= 0 then
        return true
    end
   
    local itemstable = nil
    if c <= 20 then
        itemstable = config.rewards
    elseif c > 20 and c <= 40 then
        itemstable = config.rewards2
    elseif c > 40 and c <= 100 then
        itemstable = config.rewards3
    end
   
    if itemstable = nil then
        return true
    end
   
    local winner  = players[math.random(#players)]

    local items = {}
    for itemid, count in pairs(itemstable) do
        items[#items + 1] = itemid
    end

    local itemid = items[math.random(1, #items)]
    local amount = itemstable[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

    Game.broadcastMessage("Test" .. winner:getName() .. " won " .. name .. "! (Next lottery in " .. config.interval .. ")")

    return true
end
warning then expected near = (lane 42)
 
Back
Top