Skip to content

Commit

Permalink
fix: fix load unique items from map (#2881)
Browse files Browse the repository at this point in the history
This fix the load of unique items.
Enable purchasing backpacks when the player doesn't have a main backpack
  • Loading branch information
carlospess0a authored Sep 9, 2024
1 parent dec6ad0 commit b330a33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions data-otservbr-global/startup/others/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function loadLuaMapAction(tablename)
if not value.itemId == false and tile:getItemCountById(value.itemId) == 0 then
logger.error("[loadLuaMapAction] - Wrong item id {} found", value.itemId)
logger.warn("Action id: {}, position {}", index, tile:getPosition():toString())
break
goto continue
end

if value.itemId ~= false and tile:getItemCountById(value.itemId) > 0 then
Expand All @@ -49,6 +49,7 @@ function loadLuaMapAction(tablename)
tile:getGround():setAttribute(ITEM_ATTRIBUTE_ACTIONID, index)
end
end
::continue::
end
end
end
Expand All @@ -64,19 +65,21 @@ function loadLuaMapUnique(tablename)
if not value.itemId == false and tile:getItemCountById(value.itemId) == 0 then
logger.error("[loadLuaMapUnique] - Wrong item id {} found", value.itemId)
logger.warn("Unique id: {}, position {}", index, tile:getPosition():toString())
break
goto continue
end
if tile:getItemCountById(value.itemId) < 1 or value.itemId == false then
logger.warn("[loadLuaMapUnique] - Wrong item id {} found", value.itemId)
logger.warn("Unique id: {}, position {}, item id: wrong", index, tile:getPosition():toString())
break
goto continue
end
item = tile:getItemById(value.itemId)
-- If he found the item, add the unique id
if item then
item:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, index)
end
end

::continue::
end
end

Expand All @@ -91,7 +94,7 @@ function loadLuaMapSign(tablename)
if tile:getItemCountById(value.itemId) == 0 then
logger.error("[loadLuaMapSign] - Wrong item id {} found", value.itemId)
logger.warn("Sign id: {}, position {}, item id: wrong", index, tile:getPosition():toString())
break
goto continue
end
if tile:getItemCountById(value.itemId) == 1 then
item = tile:getItemById(value.itemId)
Expand All @@ -101,6 +104,7 @@ function loadLuaMapSign(tablename)
item:setAttribute(ITEM_ATTRIBUTE_TEXT, value.text)
end
end
::continue::
end
end

Expand Down Expand Up @@ -137,17 +141,18 @@ function loadLuaMapBookDocument(tablename)
totals[2] = totals[2] + 1
else
logger.warn("[loadLuaMapBookDocument] - Item not found! Index: {}, itemId: {}", index, value.itemId)
break
goto continue
end
else
logger.warn("[loadLuaMapBookDocument] - Container not found! Index: {}, containerId: {}", index, value.containerId)
break
goto continue
end
else
logger.warn("[loadLuaMapBookDocument] - Tile not found! Index: {}, position: x: {} y: {} z: {}", index, value.position.x, value.position.y, value.position.z)
break
goto continue
end
end
::continue::
end
if totals[1] == totals[2] then
logger.debug("Loaded {} books and documents in the map", totals[2])
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ void Npc::onPlayerBuyItem(std::shared_ptr<Player> player, uint16_t itemId, uint8
return;
}

// Check if the player not have empty slots
if (!ignore && player->getFreeBackpackSlots() == 0) {
// Check if the player not have empty slots or the item is not a container
if (!ignore && (player->getFreeBackpackSlots() == 0 && (player->getInventoryItem(CONST_SLOT_BACKPACK) || (!Item::items[itemId].isContainer() || !(Item::items[itemId].slotPosition & SLOTP_BACKPACK))))) {
player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
return;
}
Expand Down

0 comments on commit b330a33

Please sign in to comment.