• 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++ TFS 1.2 Someone can help me to modific this code?

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
How can I modify this code to work this way.
if the item that will be added to the player has property (isStackable()) it will not autostack if the item is added to any container of the player, or arrow slot or in both hands, but if the item is added and there is no empyt slot in the player's container, when the item falls to the ground it autostacks if it has another item like it.
basically I would like the item to only stack on another item if it falls to the ground when added to the player.

can anybody help me? Thank you very much in advance

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;
}
 
How can I modify this code to work this way.
if the item that will be added to the player has property (isStackable()) it will not autostack if the item is added to any container of the player, or arrow slot or in both hands, but if the item is added and there is no empyt slot in the player's container, when the item falls to the ground it autostacks if it has another item like it.
basically I would like the item to only stack on another item if it falls to the ground when added to the player.

can anybody help me? Thank you very much in advance

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;
}
I don't get it 100% but eh, give it a try..
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;
    }

    // Check if the item is being added to a container, the arrow slot, or both hands
    bool skipStacking = (flags & FLAG_IGNORE_CONTAINER) || (flags & FLAG_IGNORE_ARROW) || (flags & FLAG_IGNORE_BOTH_HANDS);

    // If the item is not being added to a container, the arrow slot, or both hands
    if (!skipStacking) {
        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,
 
Last edited:
not work ;/ tfs not have that flags
C++:
 bool skipStacking = (flags & FLAG_IGNORE_CONTAINER) || (flags & FLAG_IGNORE_ARROW) || (flags & FLAG_IGNORE_BOTH_HANDS);
 

Similar threads

Back
Top