• 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+ Container:addItem[Ex] - Does not add items recursively

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,249
Solutions
71
Reaction score
621
Location
Hell
I am trying to send a reward to the depot of winner but for some reason Container:addItem[Ex] function does not work as expected.
This happens even tho there's an empty backpack in the first slot of depot.

How can I make it add the item into any INNER container (if there is any)?

I have tried both addItem and addItemEx. Didn't make a difference in my case.
Lua:
local depot = creature:getDepotChest(1)
if(depot) then

    for i = 1, table.maxn(tempBoss.rewards), 1 do
        print(tostring(depot:getEmptySlots(true))) -- shows 20 (which is true)
        depot:addItem(tempBoss.rewards[i][1], tempBoss.rewards[i][2])
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have received new reward items.")
    end
    creature:setStorageValue(tempBoss.storage, 1)

end
 
I am trying to send a reward to the depot of winner but for some reason Container:addItem[Ex] function does not work as expected.
This happens even tho there's an empty backpack in the first slot of depot.

How can I make it add the item into any INNER container (if there is any)?

I have tried both addItem and addItemEx. Didn't make a difference in my case.
Lua:
local depot = creature:getDepotChest(1)
if(depot) then

    for i = 1, table.maxn(tempBoss.rewards), 1 do
        print(tostring(depot:getEmptySlots(true))) -- shows 20 (which is true)
        depot:addItem(tempBoss.rewards[i][1], tempBoss.rewards[i][2])
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have received new reward items.")
    end
    creature:setStorageValue(tempBoss.storage, 1)

end
You want it to find any container that is inside the depot chest and if it has empty slots to add it in there? Why not just add it directly inside the depot chest.
 
You want it to find any container that is inside the depot chest and if it has empty slots to add it in there? Why not just add it directly inside the depot chest.

@Apollos
I tried doing that but it sort of "squizzes" that in the depot chest, even if its full. here's a preview of what I mean (where the hell do other items go when it forces those hats in the chest?):


giphy.gif
 
I tried doing that but it sort of "squizzes" that in the depot chest, even if its full. here's a preview of what I mean (where the hell do other items go when it forces those hats in the chest?):


giphy.gif
Yeah it is pretty ghetto but it's a good safety measure.

I'm curious tho, do you have an inbox with multiple pages in your server version? If so that could work better since there's no slot limit.

If not I can try to help make the recursive depot add item but it still will have its limits, if there are no containers with extra slots then it won't add the item to the depot unless we do a fail safe and revert back to this method of INDEX_WHEREVER and squeeze it in like you explained.

Or if there is one slot available but it's inside a container, that's inside a container, that's inside a container, that's inside the depot. This would just create a lot of looping and it's probably not wise to do so.
 
Yeah it is pretty ghetto but it's a good safety measure.

I'm curious tho, do you have an inbox with multiple pages in your server version? If so that could work better since there's no slot limit.

If not I can try to help make the recursive depot add item but it will still will have limits, if there are no containers with extra slots then it won't add the item to the depot unless we do a fail safe and revert back to this method of INDEX_WHEREVER and squeeze it in like you explained.

No, I haven't enabled pagination. It's just that one depot chest with 30 slots.

Edit: Do you have any other Ideas? The reason Im doing this is because I wanted to replicate the reward chest system but in a simpler way. Maybe it would be possible to save the rewards in a database table and then fetch them when player uses a chest with actionid. What are your thoughts on that?
 
container:addItem does add item only to the container you specified, it wont add recursively and find any other backpacks in that backpack, if its full backpack and one slot is backpack its also item, so it wont check it. You have to write your own lua function for that, that will check all slots and if any is container and then check the container and back etc.
 
No, I haven't enabled pagination. It's just that one depot chest with 30 slots.

Edit: Do you have any other Ideas? The reason Im doing this is because I wanted to replicate the reward chest system but in a simpler way. Maybe it would be possible to save the rewards in a database table and then fetch them when player uses a chest with actionid. What are your thoughts on that?
At least in my server I added the reward chest inside my locker (along with depot and inbox) and set it to have multiple pages like the inbox does. That way you don't have issues with it squeezing. If you like this option I can make a pdf of my commit but I'm not entirely sure it'll work with your server version.

35930

Otherwise it might be best to just add them all into one container(the reward bag for instance) and then add that into the depot chest with INDEX_WHEREVER and FLAG_NOLIMIT so it'll squeeze in, but it won't take up much room at all and will only push the other items 1 slot over.
 
At least in my server I added the reward chest inside my locker (along with depot and inbox) and set it to have multiple pages like the inbox does. That way you don't have issues with it squeezing. If you like this option I can make a pdf of my commit but I'm not entirely sure it'll work with your server version.

View attachment 35930

Otherwise it might be best to just add them all into one container(the reward bag for instance) and then add that into the depot chest with INDEX_WHEREVER and FLAG_NOLIMIT so it'll squeeze in, but it won't take up much room at all and will only push the other items 1 slot over.

I am using TFS 1.3 - 10.98 and I would like to have reward chest implemented xD

btw I am using OTClient and whenever I click on reward bag (under EQ ) it freezes for a second and then nothing happens. Is this an OTC issue?
 
I am using TFS 1.3 - 10.98 and I would like to have reward chest implemented xD

btw I am using OTClient and whenever I click on reward bag (under EQ ) it freezes for a second and then nothing happens. Is this an OTC issue?
Here's the commit, let me know if you like it and it works out well enough. If so I'll probably release it on resources.
Reward Chest System

NOTES:
  • Run the query I added in schema inside your database to add the player_rewarditems table.
  • In object builder and item editor you need to add flag pickupable to the reward bag (id 21518)
  • Ignore the jalapeno pepper part lol
 
Last edited:
Here's the commit, let me know if you like it and it works out well enough. If so I'll probably release it on resources.
Reward Chest System

NOTES:
  • Run the query I added in schema inside your database to add the player_rewarditems table.
  • In object builder and item editor you need to add flag pickupable to the reward bag (id 21518)
  • Ignore the jalapeno pepper part lol

Who is the author of this code?
 
Back
Top