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

TFS 1.X+ Add rings from quest rewards to bag instead of ring slot

Dawg

Member
Joined
Mar 23, 2014
Messages
180
Reaction score
22
I'm trying to figure out how to make it so that when a player receives a ring from a reward chest, the ring goes straight to the backpack even if the player's ring slot is open. With TFS 1.2, if the player has no ring on, and then they open a quest chest that gives a ring, the ring goes straight to the player's ring slot and starts the expire timer.

Obviously this is not ideal, and besides, in RL this does not happen. See here:
A guy has no ring on and he does the banshee quest. When he opens the top right chest and gets the stealth ring, it goes to his bag, not his ring slot.

I also try some other distros, like nostalrius, and it also has the same problem. The game tries to dress the ring in your ring slot.

I see that the quest system adds the item with playerAddItemEx, and i see in the source code (luascript.cpp) that playerAddItemEx goes through all slots, but I don't understand how to exclude rings from this.

I searched and i have not seen anyone else reporting this issue, not sure if it's easy to fix and I'm just missing it or if the solution is already out there somwhere, or if I need to be using another function. thanks in advance!
 
I see, thank you. I also see that getEmptySlots has a recursive feature if you use

Lua:
if backpack:getEmptySlots(true) > 0 then
    --has room
end

~~~EDIT~~~~~~
Here is my current code:

Lua:
local added = false
local useBackpack = itemtype and itemtype:getTransformEquipId() > 0
if useBackpack then
    print("an expiring item")
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
    if backpack then
        print("player has a backpack")
        -- Check recursively if the backpack is full
        if backpack:getEmptySlots(true) > 0 then
            print(backpack:getEmptySlots(true))
            print("recursive found an empty slot, add the item to it")
            -- Add to the backpack or ground if it contains additional backpacks
            if backpack:addItemEx(reward:clone(), true, CONST_SLOT_BACKPACK, FLAG_RECURSIVE) == RETURNVALUE_NOERROR then
                print("added to the backpack, first empty slot")
                added = true
            end
        else
            print("recursive did not find any empty slots")
        end
    end

    -- If player doesn't have a backpack or the item couldn't be added to the backpack, add to the ground
    if not added then
        player:addItemEx(reward:clone(), true, CONST_SLOT_BACKPACK)
        print("player doesn't have a backpack or backpack is full, added to the ground")
    end
else
    print("not an expiring item, can go wherever or on the ground")
    player:addItemEx(reward:clone(), true)
end
This works if:
1) player has no backpack. ring goes to the ground
2) player has a backpack with free slots. ring goes into the backpack
3) player has backpack, but its full: ring goes to the ground
4) player has a backpack, but its full, but theres a 2nd backpack inside with space: ring goes to the inner backpack
5) backpack #2 is also full, ring goes to the ground

The code does not work, however, if a 3rd backpack is introduced. If there is a 3rd backpack, the ring gets jammed inside backpack #2 as the 21st item instead of going to the empty 3rd backpack:
Screenshot 2023-12-19 at 11.56.17 AM.png
This is the print:

Code:
an expiring item
player has a backpack
20
recursive found an empty slot, add the item to it
added to the backpack, first empty slot

SO the getEmptySlots recursion is working. However, for some reason addItemEx is only going down to the 2nd backpack level?
 
Last edited:
Back
Top