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

C++ Container - onMove function

Roddet

Staff member
Global Moderator
Joined
May 1, 2013
Messages
945
Solutions
103
Reaction score
763
Location
Mex
Basically im trying to create a parameter (onThrow) where i could be able to check if an item is being moving to a container that stands on the floor or viceversa.

This in order to block some items to not being able to throw to the floor or containers on the floor.

C++:
    CreatureEventList throwEvents = player->getCreatureEvents(CREATURE_EVENT_THROW);
    for(CreatureEventList::iterator it = throwEvents.begin(); it != throwEvents.end(); ++it)
    {
        Item* toContainer = toCylinder->getItem();
        Item* fromContainer = fromCylinder->getItem();

        Item* fromGround = fromCylinder->getTile()->getTopDownItem();
        Item* toGround = toCylinder->getTile()->getTopDownItem();

        if(!(*it)->executeThrow(player, item, count, fromPos, toPos, (fromContainer ? fromContainer : 0), (toContainer ? toContainer : 0), fromGround, toGround, fromStackpos) && !deny)
            deny = true;
    }

With those lines i've added, it works as expected, expecified items cannot be thrown to containers that are on the floor but, there is a problem, when im standing on top of a backpack/container which is on the floor and i try to move an item which is inside of my backpack the code "thinks" that im trying to move the item to the backpack/container that im standing on and then it gets blocked.

Also tried with ground instead of getTopDownItem but didn't work properly either.
Anyone could explain me how to get only the container on the floor?


TFS 0.3.7
 
Last edited:
Solution
Im not sure if I understood this at all but you can check if the player is the actual parent of the item so you will know if the player is holding or not the item
Im not sure if I understood this at all but you can check if the player is the actual parent of the item so you will know if the player is holding or not the item
 
Solution
as always there is no tfs version provided, is this a tradition now? But looking at what you try to implement which is already implemented in tfs 1.3, you are using some old pre 1.x tfs?
 
was it really there or you are trying to fool me now? Anyway good luck (to author) with getting help for this ancient distro.
It was there already.

Im not sure if I understood this at all but you can check if the player is the actual parent of the item so you will know if the player is holding or not the item

EDIT: It worked using getItemParent, thanks.
 
Last edited:
can you post the full working code pls? : p

Firstly, fromGround & toGround are irrelevant at this points.

Just use fromContainer & toContainer using getItemParent like this:
getItemParent(toContainer.uid).itemid

Once you throw an item to a container you will get 2 results:
If you get 1 means the container is hold by yourself
If you get 0 means the container is not hold by a player

If you get 0 means a container on the floor or even the depot, so you must create an exception like this:

C++:
local items = {depot = {2589,2590,2591,2592,2594}}
if toContainer.uid > 0 then
      if not(isInArray(items.depot, toContainer.itemid)) and getItemParent(toContainer.uid).itemid == 0 then
           return false
      end
end

This part wont let you throw items to a container which stands on the floor.
There are more checks to-do like slots, containers with proctected items and such but now you got the idea how to...

thank you man <3

EDIT: Actually, you will need fromGround & toGround aswell. I just realized getItemParent returns the real itemid if you throw an item to a container which is inside another container. Only with onGround will returns 0 or 1 since it will check always the main container unlike getItemParent
 
Last edited:
Back
Top