• 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+ playeradditem, removal of auto stacking

emil92b

Intermediate OT User
Joined
Aug 21, 2013
Messages
335
Solutions
13
Reaction score
135
Location
Sweden
im trying to change how items gets added to the player, i dont want the item to stack with the other item of the same id

so far i tracked it down to this, how can i change it?

C++:
ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t index,
                                  uint32_t flags, bool test, uint32_t& remainderCount)
{
    if (toCylinder == nullptr || item == nullptr) {
        return RETURNVALUE_NOTPOSSIBLE;
    }

    Cylinder* destCylinder = toCylinder;
    Item* toItem = nullptr;
    toCylinder = toCylinder->queryDestination(index, *item, &toItem, flags);

    //check if we can add this item
    ReturnValue ret = toCylinder->queryAdd(index, *item, item->getItemCount(), flags);
    if (ret != RETURNVALUE_NOERROR) {
        return ret;
    }

    /*
    Check if we can move add the whole amount, we do this by checking against the original cylinder,
    since the queryDestination can return a cylinder that might only hold a part of the full amount.
    */
    uint32_t maxQueryCount = 0;
    ret = destCylinder->queryMaxCount(INDEX_WHEREEVER, *item, item->getItemCount(), maxQueryCount, flags);

    if (ret != RETURNVALUE_NOERROR) {
        return ret;
    }

    if (test) {
        return RETURNVALUE_NOERROR;
    }

    if (item->isStackable() && item->equals(toItem)) {
        uint32_t m = std::min<uint32_t>(item->getItemCount(), maxQueryCount);
        uint32_t n = std::min<uint32_t>(100 - toItem->getItemCount(), m);

        toCylinder->updateThing(toItem, toItem->getID(), toItem->getItemCount() + n);

        int32_t count = m - n;
        if (count > 0) {
            if (item->getItemCount() != count) {
                Item* remainderItem = item->clone();
                remainderItem->setItemCount(count);
                if (internalAddItem(destCylinder, remainderItem, INDEX_WHEREEVER, flags, false) != RETURNVALUE_NOERROR) {
                    ReleaseItem(remainderItem);
                    remainderCount = count;
                }
            } else {
                toCylinder->addThing(index, item);

                int32_t itemIndex = toCylinder->getThingIndex(item);
                if (itemIndex != -1) {
                    toCylinder->postAddNotification(item, nullptr, itemIndex);
                }
            }
        } else {
            //fully merged with toItem, item will be destroyed
            item->onRemoved();
            ReleaseItem(item);

            int32_t itemIndex = toCylinder->getThingIndex(toItem);
            if (itemIndex != -1) {
                toCylinder->postAddNotification(toItem, nullptr, itemIndex);
            }
        }
    } else {
        toCylinder->addThing(index, item);

        int32_t itemIndex = toCylinder->getThingIndex(item);
        if (itemIndex != -1) {
            toCylinder->postAddNotification(item, nullptr, itemIndex);
        }
    }

    return RETURNVALUE_NOERROR;
}
 
Not this one, in your container.cpp find this one
C++:
    bool autoStack = !hasBitSet(FLAG_IGNOREAUTOSTACK, flags);
        if (autoStack && item->isStackable() && item->getParent() != this) {
        //try find a suitable item to stack with
        uint32_t n = 0;
        for (Item* listItem : itemlist) {
             if (listItem != item && listItem->equals(item) && listItem->getItemCount() < 100) {
                *destItem = listItem;
                index = n;
                return this;
            }
            ++n;
        }
    }
    return this;
}
and change it to this then recompile
C++:
    /* bool autoStack = !hasBitSet(FLAG_IGNOREAUTOSTACK, flags);
        if (autoStack && item->isStackable() && item->getParent() != this) {
        //try find a suitable item to stack with
        uint32_t n = 0;
        for (Item* listItem : itemlist) {
             if (listItem != item && listItem->equals(item) && listItem->getItemCount() < 100) {
                *destItem = listItem;
                index = n;
                return this;
            }
            ++n;
        }
    } */
    return this;
}
 
Not this one, in your container.cpp find this one
C++:
    bool autoStack = !hasBitSet(FLAG_IGNOREAUTOSTACK, flags);
        if (autoStack && item->isStackable() && item->getParent() != this) {
        //try find a suitable item to stack with
        uint32_t n = 0;
        for (Item* listItem : itemlist) {
             if (listItem != item && listItem->equals(item) && listItem->getItemCount() < 100) {
                *destItem = listItem;
                index = n;
                return this;
            }
            ++n;
        }
    }
    return this;
}
and change it to this then recompile
C++:
    /* bool autoStack = !hasBitSet(FLAG_IGNOREAUTOSTACK, flags);
        if (autoStack && item->isStackable() && item->getParent() != this) {
        //try find a suitable item to stack with
        uint32_t n = 0;
        for (Item* listItem : itemlist) {
             if (listItem != item && listItem->equals(item) && listItem->getItemCount() < 100) {
                *destItem = listItem;
                index = n;
                return this;
            }
            ++n;
        }
    } */
    return this;
}
that seems to be for player stacking items by himself, what im looking for is how items are given to the player trough npcs and other stuff that uses that additem function
 
if items are meant to be used once or to be different from normal items like example. tibia uses one potion but with 2 different functions.
I did this by adding an special action id to every item that was added to the player, this way its not going to stack neither tradeable at market.
 
if items are meant to be used once or to be different from normal items like example. tibia uses one potion but with 2 different functions.
I did this by adding an special action id to every item that was added to the player, this way its not going to stack neither tradeable at market.
i want every "stackable" item not to stack with previous item in backpack or item slot if conjured by you/given to you by npcs etc regardless if they are used once or not :p
 

Similar threads

Back
Top