Fifth
Active Member
- Joined
- Jul 8, 2023
- Messages
- 76
- Solutions
- 1
- Reaction score
- 42
little quick small edit that can be useful
item:setCustomAttribute("nonsellable", 1) -- to set an item non-sellable
item:removeCustomAttribute("nonsellable") -- to remove non-sellable flag
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