• 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 tfs 1x

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
I'm making a lottery. Do you have any idea how to make some more difficult items?
 
Solution
a quick example
Lua:
local rewards = {
-- {{item_id, amount}, {item_id, amount}}
    {{1111, 1}, {2222, 10}}, -- common
    {{1111, 1}, {2222, 10}}, -- uncommon
    {{1111, 1}, {2222, 10}}  -- rare
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local index = 1
    local rand = math.random(1000)
    if rand > 950 then
        index = 3
    elseif rand > 800 then
        index = 2
    end
    rand = math.random(#rewards[index])
    doPlayerAddItem(cid, rewards[index][rand][1], rewards[index][rand][2])
    return true
end
a quick example
Lua:
local rewards = {
-- {{item_id, amount}, {item_id, amount}}
    {{1111, 1}, {2222, 10}}, -- common
    {{1111, 1}, {2222, 10}}, -- uncommon
    {{1111, 1}, {2222, 10}}  -- rare
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local index = 1
    local rand = math.random(1000)
    if rand > 950 then
        index = 3
    elseif rand > 800 then
        index = 2
    end
    rand = math.random(#rewards[index])
    doPlayerAddItem(cid, rewards[index][rand][1], rewards[index][rand][2])
    return true
end
 
Solution
Or something more flexible:
Lua:
local rewards = {
    -- [min chance, max chance] = {item list here}
    [{1, 10}] = {
        {id = 123, count = {min = 1, max = 5}}
    },
    [{11, 100}] = {
        {id = 123, count = {min = 1, max = 5}}
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chance = math.random(100)
    local rewardList = nil
    for k, v in pairs(rewards) do
        if k[1] >= chance and k[2] <= chance then
            rewardList = v
            break
        end
    end
    if not rewardList then
        print('no reward list specified for chance rolled: '.. chance)
        return true
    end
    local reward = rewardList[math.random(#rewardList)]
    player:addItem(reward.id, math.random(reward.count.min, reward.count.max))
    return true
end
 
Code:
local config = { 
    rewards = {
	[2160] = 1 
	},
	  
} 
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(1000, #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

   
    return true
end

I'll try to adapt
 
Back
Top