• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Feature Non-sellable items TFS 1.4

Fifth

Active Member
Joined
Jul 8, 2023
Messages
76
Solutions
1
Reaction score
42
little quick small edit that can be useful

C++:
bool Player::removeItemOfType(uint16_t itemId, uint32_t amount, int32_t subType, bool ignoreEquipped/* = false*/) const
{
    if (amount == 0) {
        return true;
    }

    std::vector<Item*> itemList;

    uint32_t count = 0;
    for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) {
        Item* item = inventory[i];
        if (!item) {
            continue;
        }

        if (!ignoreEquipped && item->getID() == itemId) {
            if (item->getCustomAttribute("nonsellable")) {
                continue;
            }
            uint32_t itemCount = Item::countByType(item, subType);
            if (itemCount == 0) {
                continue;
            }

            itemList.push_back(item);

            count += itemCount;
            if (count >= amount) {
                g_game.internalRemoveItems(std::move(itemList), amount, Item::items[itemId].stackable);
                return true;
            }
        } else if (Container* container = item->getContainer()) {
            for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) {
                Item* containerItem = *it;
                if (containerItem->getID() == itemId) {
                    if (containerItem->getCustomAttribute("nonsellable")) {
                        continue;
                    }
                    uint32_t itemCount = Item::countByType(containerItem, subType);
                    if (itemCount == 0) {
                        continue;
                    }

                    itemList.push_back(containerItem);

                    count += itemCount;
                    if (count >= amount) {
                        g_game.internalRemoveItems(std::move(itemList), amount, Item::items[itemId].stackable);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

std::map<uint32_t, uint32_t>& Player::getAllItemTypeCount(std::map<uint32_t, uint32_t>& countMap) const
{
    for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) {
        Item* item = inventory[i];
        if (!item) {
            continue;
        }

        if (item->getCustomAttribute("nonsellable")) {
            continue;
        }

        countMap[item->getID()] += Item::countByType(item, -1);

        if (Container* container = item->getContainer()) {
            for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) {
                if ((*it)->getCustomAttribute("nonsellable")) {
                    continue;
                }

                countMap[(*it)->getID()] += Item::countByType(*it, -1);
            }
        }
    }
    return countMap;
}

item:setCustomAttribute("nonsellable", 1) -- to set an item non-sellable
item:removeCustomAttribute("nonsellable") -- to remove non-sellable flag
 
Back
Top