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

Solved Function when remove all items remove the container

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
212
Hello folks, I'm making some script, I need some function that remove the container when all items is removed from inside..
another problem ... I have some bugs if I create a item with decay time and send it to my depot, if I send the item and logout the item stop the decay...

Someone with c++ knowledge can help me with something? I want to understand what some functions do, and how use..
so much thanks
 
You can use size() to determine if a containers size is equal to zero, and if it is then use g_game.internalRemoveItem to remove it (do this in postRemoveNotification), e.g.
Code:
if (size() == 0) {
    g_game.internalRemoveItem(this);
}

There is currently no way to force item decay, see this issue: Force Item Decay
 
You can use size() inside postRemoveNotification to remove a container when it's empty, e.g
Code:
if (size() == 0) {
    g_game.internalRemoveItem(this);
}

There is currently no way to force item decay, see this issue: Force Item Decay
about the "remove container" how make it in lua? I don't know where I use it, movements? when remove all items then remove, or a globalevent to check with time if have items or not, but it can be bad to the server, the item is the reward container, that will are in the reward chest of each player...
the depot was an exemple, I'm using some stuff, the real player data is the reward chest, I'm using something made by Ranisalt ...
 
Last edited:
You can also achive the remove through onMoveItem event, e.g:

Code:
    local topParent = item:getTopParent()
    if fromPosition.x == CONTAINER_POSITION and topParent.isContainer and topParent:getId() == 1988 then
        if topParent:getSize() <= 1 then
            topParent:remove()
            fromPosition:sendMagicEffect(CONST_ME_POFF)
        end
    end
 
You can also achive the remove through onMoveItem event, e.g:

Code:
    local topParent = item:getTopParent()
    if fromPosition.x == CONTAINER_POSITION and topParent.isContainer and topParent:getId() == 1988 then
        if topParent:getSize() <= 1 then
            topParent:remove()
            fromPosition:sendMagicEffect(CONST_ME_POFF)
        end
    end
Where I can use it ? do you have a tag to me? :3
 
You can use size() to determine if a containers size is equal to zero, and if it is then use g_game.internalRemoveItem to remove it (do this in postRemoveNotification), e.g.
Code:
if (size() == 0) {
    g_game.internalRemoveItem(this);
}

There is currently no way to force item decay, see this issue: Force Item Decay
Yes, I see it, my source have it, but to work it I need make the type of the item
something like this
Code:
<attribute key="type" value="rewardcontainer" />
but with my source I can't add items inside of this bag -.-
I don't know why it .. same with
Code:
addItemEx(2160, 1, INDEX_WHEREEVER, FLAG_NOLIMIT)
the items not appear inside
this is my function to use the item attribute type "rewardcontainer"
Code:
ReturnValue RewardContainer::queryAdd(int32_t, const Thing& thing, uint32_t, uint32_t flags, Creature*) const
{
    if (!hasBitSet(FLAG_NOLIMIT, flags)) {
        return RETURNVALUE_CONTAINERNOTENOUGHROOM;
    }

    const Item* item = thing.getItem();
    if (!item) {
        return RETURNVALUE_NOTPOSSIBLE;
    }

    if (item == this) {
        return RETURNVALUE_THISISIMPOSSIBLE;
    }

    if (!item->isPickupable()) {
        return RETURNVALUE_CANNOTPICKUP;
    }

    return RETURNVALUE_NOERROR;
}
 
You can add items to reward chests, and containers through Lua but you are doing it wrong. Container.addItemEx requires Item userdata where as Container.addItem uses itemId, and count. So all you have to do is change addItemEx to addItem.
 
You can add items to reward chests, and containers through Lua but you are doing it wrong. Container.addItemEx requires Item userdata where as Container.addItem uses itemId, and count. So all you have to do is change addItemEx to addItem.
thanks, works.
 
@Ninja remember this piece that you told ?
Code:
if (size() == 0) {
g_game.internalRemoveItem(this);
}
I'm using it, but when I logout and login and try remove items the tfs get crash :/
 
@silveralol
If you're using my reward system and want to procedurally give players rewards all you have to do is this:
Code:
local reward = player:getReward(os.time(), true)
reward:addItem(itemId, count)

And a reward container will appear in the reward chest with the items you added. About the reward container disappearing when it is empty, you can't do it in Lua and I do not recommend trying to do it yourself. Right now it will disappear whenever the player logs out, if that isn't good enough for your needs you will have to study my system thoroughly to be able to change that, or start from scratch.
 
@silveralol
If you're using my reward system and want to procedurally give players rewards all you have to do is this:
Code:
local reward = player:getReward(os.time(), true)
reward:addItem(itemId, count)

And a reward container will appear in the reward chest with the items you added. About the reward container disappearing when it is empty, you can't do it in Lua and I do not recommend trying to do it yourself. Right now it will disappear whenever the player logs out, if that isn't good enough for your needs you will have to study my system thoroughly to be able to change that, or start from scratch.
i'm not using your system '-' i'm using my... my system is limited to send items just to reward chest, not in corpse :/ but I still trying improve it
 
bump!, I find the bug the crash, is about "indexing" the server lost the "indexing" of the container when call "g_game.internalRemoveItem(this);"
 
Back
Top