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

Lua TFS 1.3 Suprise bag

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys,

I found a few scripts that are close to what I need, but they are not for my TFS. Well the script I need is a suprese bag, when the player open the bag it will give the player a item with a certain % for example:

bag tier 1 (ID XXXX):
10% chance of player getting 1 fire sword
40% chance of player getting 10 health potions and 10 mana potions
50% chance of player getting 15 ham

bag tier 2 (IDYYYY):
10% chance of player getting 1 magic long sword
30% chance of player getting 10 great health potions and 10 great mana potions
60% chance of player getting 15 dragon ham

If anyone could help me, I would be glad, thanks.
 
Lua:
local config = {
    [9108] = {
        maxRewards = 2;
        rewards = {
            {item = {{"fire sword", 1}}, chance = 10};
            {item = {{"health potion", 10}, {"mana potion", 10}}, chance = 40};
            {item = {{"ham", 15}}, chance = 50};
        }
    };
    [6570] = {
        maxRewards = 1;
        rewards = {
            {item = {{"magic longsword", 1}}, chance = 10};
            {item = {{"great health potion", 10}, {"great mana potion", 10}}, chance = 30};
            {item = {{"dragon ham", 15}}, chance = 60};
        }
    }
}

local surpriseBag = Action()
function surpriseBag.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local rewards = {}
    local chance = math.random(1, 100)
    for k, v in pairs(config) do
        if item:getId() == k then
            for i = 1, #v.rewards do
                if chance <= v.rewards[i].chance then
                    for j = 1, #v.rewards[i].item do
                        local itemType, subType = ItemType(v.rewards[i].item[j][1]), v.rewards[i].item[j][2]
                        if itemType then
                            rewards[#rewards + 1] = subType.." "..itemType:getName()
                            player:addItem(itemType:getId(), subType)
                        end
                    end
                end
                if #rewards >= v.maxRewards then
                    break
                end
            end
            break
        end
    end
    -- remove item
    item:remove(1)

    if #rewards == 0 then
        return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You didnt receive any reward.")
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have received "..table.concat(rewards, ", "):gsub("(.*),", "%1 and")..".")
    player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    return true
end

for k, _ in pairs(config) do
    surpriseBag:id(k)
end
surpriseBag:register()
 
Last edited:
Lua:
local config = {
    [9108] = {
        maxRewards = 2;
        rewards = {
            {item = {{"fire sword", 1}}, chance = 10};
            {item = {{"health potion", 10}, {"mana potion", 10}}, chance = 40};
            {item = {{"ham", 15}}, chance = 50};
        }
    };
    [6570] = {
        maxRewards = 1;
        rewards = {
            {item = {{"magic longsword", 1}}, chance = 10};
            {item = {{"great health potion", 10}, {"great mana potion", 10}}, chance = 30};
            {item = {{"dragon ham", 15}}, chance = 60};
        }
    }
}

local surpriseBag = Action()
function surpriseBag.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local rewards = {}
    local chance = math.random(1, 100)
    for k, v in pairs(config) do
        if item:getId() == k then
            for i = 1, #v.rewards do
                if chance <= v.rewards[i].chance then
                    for j = 1, #v.rewards[i].item do
                        local itemType, subType = ItemType(v.rewards[i].item[j][1]), v.rewards[i].item[j][2]
                        print(itemType:getName())
                        if itemType then
                            rewards[#rewards + 1] = subType.." "..itemType:getName()
                            player:addItem(itemType:getId(), subType)
                        end
                    end
                end
                if #rewards >= v.maxRewards then
                    break
                end
            end
            break
        end
    end
    -- remove item
    item:remove(1)

    if #rewards == 0 then
        return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You didnt receive any reward.")
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have received "..table.concat(rewards, ", "):gsub("(.*),", "%1 and")..".")
    player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    return false
end

for k, _ in pairs(config) do
    surpriseBag:id(k)
end
surpriseBag:register()
Nice, but how do I put for the player to always receive something?
 
Back
Top