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

RevScripts [TFS 1.4.1] Random Item Bag Script

DrRed24

Active Member
Joined
May 18, 2022
Messages
27
Reaction score
30
Hello! I would like to ask for this request! [Using TFS 1.4.1 10.98 version latest files]
Using the Gooey Mass as an example (or i guess this code can have the adjustments.?)
Lua:
local config = {
    {chanceFrom = 0, chanceTo = 38}, -- nothing
    {chanceFrom = 39, chanceTo = 2132, itemId = 2152, count = 2}, -- platinum coin
    {chanceFrom = 2133, chanceTo = 4187, itemId = 15487, count = 10}, -- larvae
    {chanceFrom = 4188, chanceTo = 6040, itemId = 2144, count = 2}, -- black pearl
    {chanceFrom = 6041, chanceTo = 7951, itemId = 7591, count = 2}, -- great health potion
    {chanceFrom = 7952, chanceTo = 9843, itemId = 7590, count = 2}, -- great mana potion
    {chanceFrom = 9844, chanceTo = 9941, itemId = 9971}, -- gold ingot
    {chanceFrom = 9942, chanceTo = 9987, itemId = 15546}, -- four-leaf clover
    {chanceFrom = 9988, chanceTo = 10000, itemId = 15492} -- hive scythe
}

local gooeyMass = Action()

function gooeyMass.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chance = math.random(0, 10000)
    for i = 1, #config do
        local randomItem = config[i]
        if chance >= randomItem.chanceFrom and chance <= randomItem.chanceTo then
            if randomItem.itemId then
                local gift = randomItem.itemId
                local count = randomItem.count or 1
                if type(count) == "table" then
                    count = math.random(count[1], count[2])
                end
                player:addItem(gift, count)
            end

            item:getPosition():sendMagicEffect(CONST_ME_HITBYPOISON)
            item:remove(1)
            return true
        end
    end
    return false
end

gooeyMass:id(15572)
gooeyMass:register()
Let's say i want a 3 different bags that gives random items to a player and for stackable items the "count" can be random too, let's say a player receive gold coins between 1 to 100 gold coins (can be any other stackable item, just the gold coins as refference).

Bag 1 gives random items (no need for a key)
Bag 2 and Bag 3 needs an special key to open (player have to use the key on the box to open it.)

Thank in advance!
 
Back
Top