From 308cbe1048c009baed6f889f4d4a5192db1dbdc0 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 16 Sep 2023 21:31:30 -0300 Subject: [PATCH 1/3] fix: container:addLoot warnings --- data-canary/scripts/actions/other/cask_kegs.lua | 2 +- data-canary/scripts/actions/other/potions.lua | 2 +- .../monster/demons/true_frost_flower_asura.lua | 2 +- .../scripts/actions/other/cask_kegs.lua | 2 +- data-otservbr-global/scripts/actions/other/potions.lua | 2 +- .../quests/forgotten_knowledge/dragon_egg.lua | 10 ++++++++-- data/items/items.xml | 8 ++++---- data/libs/functions/container.lua | 2 +- data/libs/functions/game.lua | 8 +++++++- src/lua/functions/items/container_functions.cpp | 4 ++++ 10 files changed, 29 insertions(+), 13 deletions(-) diff --git a/data-canary/scripts/actions/other/cask_kegs.lua b/data-canary/scripts/actions/other/cask_kegs.lua index 2c1a7499e99..f437840e3fa 100644 --- a/data-canary/scripts/actions/other/cask_kegs.lua +++ b/data-canary/scripts/actions/other/cask_kegs.lua @@ -35,7 +35,7 @@ local targetIdList = { local flasks = Action() function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not target or not player:getTile():getHouse() then + if not target or not target:getItem() then return false end diff --git a/data-canary/scripts/actions/other/potions.lua b/data-canary/scripts/actions/other/potions.lua index 485cdf34dbb..619356f44c0 100644 --- a/data-canary/scripts/actions/other/potions.lua +++ b/data-canary/scripts/actions/other/potions.lua @@ -159,7 +159,7 @@ local setting = { local potions = Action() function potions.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if type(target) == "userdata" and not target:isPlayer() then + if not target or type(target) == "userdata" and not target:isPlayer() then return false end diff --git a/data-otservbr-global/monster/demons/true_frost_flower_asura.lua b/data-otservbr-global/monster/demons/true_frost_flower_asura.lua index 6aff33bd5d2..7a5a6998cf1 100644 --- a/data-otservbr-global/monster/demons/true_frost_flower_asura.lua +++ b/data-otservbr-global/monster/demons/true_frost_flower_asura.lua @@ -29,7 +29,7 @@ monster.Bestiary = { monster.health = 4000 monster.maxHealth = 4000 monster.race = "blood" -monster.corpse = 28668 +monster.corpse = 28667 monster.speed = 150 monster.manaCost = 0 diff --git a/data-otservbr-global/scripts/actions/other/cask_kegs.lua b/data-otservbr-global/scripts/actions/other/cask_kegs.lua index 872d30d613c..9b95335d5d1 100644 --- a/data-otservbr-global/scripts/actions/other/cask_kegs.lua +++ b/data-otservbr-global/scripts/actions/other/cask_kegs.lua @@ -35,7 +35,7 @@ local targetIdList = { local flasks = Action() function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not target then + if not target or not target:getItem() then return false end diff --git a/data-otservbr-global/scripts/actions/other/potions.lua b/data-otservbr-global/scripts/actions/other/potions.lua index cfa76f441a4..b25cd6cb37e 100644 --- a/data-otservbr-global/scripts/actions/other/potions.lua +++ b/data-otservbr-global/scripts/actions/other/potions.lua @@ -222,7 +222,7 @@ local potions = { local flaskPotion = Action() function flaskPotion.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if type(target) == "userdata" and not target:isPlayer() then + if not target or type(target) == "userdata" and not target:isPlayer() then return false end diff --git a/data-otservbr-global/scripts/creaturescripts/quests/forgotten_knowledge/dragon_egg.lua b/data-otservbr-global/scripts/creaturescripts/quests/forgotten_knowledge/dragon_egg.lua index 0554ec201e4..ccc452c87ae 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/forgotten_knowledge/dragon_egg.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/forgotten_knowledge/dragon_egg.lua @@ -22,7 +22,13 @@ local function revertHorror() end local function changeHorror() - local melting = Tile(Position(32267, 31071, 14)):getTopCreature() + local meltingTile = Tile(Position(32267, 31071, 14)) + if not meltingTile then + logger.error("Tile not exist on position '{}'", Position(32267, 31071, 14):toString()) + return + end + + local meltingCreature = meltingTile:getTopCreature() local pos = 0 local specs, spec = Game.getSpectators(Position(32269, 31091, 14), false, false, 12, 12, 12, 12) for i = 1, #specs do @@ -30,7 +36,7 @@ local function changeHorror() if spec:isMonster() and spec:getName():lower() == "solid frozen horror" then pos = spec:getPosition() spec:teleportTo(Position(32267, 31071, 14)) - melting:teleportTo(pos) + meltingCreature:teleportTo(pos) end end addEvent(revertHorror, 20 * 1000) diff --git a/data/items/items.xml b/data/items/items.xml index 0c072fe2f1b..b568ab1fed4 100644 --- a/data/items/items.xml +++ b/data/items/items.xml @@ -48715,13 +48715,13 @@ - + - + @@ -48736,13 +48736,13 @@ - + - + diff --git a/data/libs/functions/container.lua b/data/libs/functions/container.lua index 5f554ce0514..b92d64b018a 100644 --- a/data/libs/functions/container.lua +++ b/data/libs/functions/container.lua @@ -32,7 +32,7 @@ function Container:addLoot(loot) tmpItem:setText(item.text) end else - Spdlog.warn(("Container:addLoot: failed to add item: %s"):format(ItemType(itemId):getName())) + logger.warn("Container:addLoot: failed to add item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId()) end ::continue:: diff --git a/data/libs/functions/game.lua b/data/libs/functions/game.lua index cb77c296067..4823dd7166c 100644 --- a/data/libs/functions/game.lua +++ b/data/libs/functions/game.lua @@ -131,5 +131,11 @@ function Game.getStorageValue(key) end function Game.setStorageValue(key, value) - globalStorageTable[key] = value + local addedValue = globalStorageTable[key] + if addedValue == nil then + logger.error("[Game.setStorageValue] Key is nil") + return + end + + addedValue = value end diff --git a/src/lua/functions/items/container_functions.cpp b/src/lua/functions/items/container_functions.cpp index 9bdc958b353..efd01eae743 100644 --- a/src/lua/functions/items/container_functions.cpp +++ b/src/lua/functions/items/container_functions.cpp @@ -117,6 +117,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { Container* container = getUserdata(L, 1); if (!container) { lua_pushnil(L); + reportErrorFunc("Container is nullptr"); return 1; } @@ -127,6 +128,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { itemId = Item::items.getItemIdByName(getString(L, 2)); if (itemId == 0) { lua_pushnil(L); + reportErrorFunc("Item id is wrong"); return 1; } } @@ -140,6 +142,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { Item* item = Item::CreateItem(itemId, count); if (!item) { lua_pushnil(L); + reportErrorFunc("Item is nullptr"); return 1; } @@ -151,6 +154,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { pushUserdata(L, item); setItemMetatable(L, -1, item); } else { + reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret))); delete item; lua_pushnil(L); } From adf9506c04287722b1d09004fb6b9f12c414120d Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 16 Sep 2023 21:35:57 -0300 Subject: [PATCH 2/3] fix --- data/libs/functions/game.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/libs/functions/game.lua b/data/libs/functions/game.lua index 4823dd7166c..3ea70a43608 100644 --- a/data/libs/functions/game.lua +++ b/data/libs/functions/game.lua @@ -137,5 +137,5 @@ function Game.setStorageValue(key, value) return end - addedValue = value + globalStorageTable[key] = value end From c431bf116eb04d89f36fb5478dac88c7ab986c8a Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Mon, 18 Sep 2023 14:35:39 -0300 Subject: [PATCH 3/3] fix: flag no limit for loots and fix setStorageValue --- data/libs/functions/container.lua | 2 +- data/libs/functions/game.lua | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/data/libs/functions/container.lua b/data/libs/functions/container.lua index b92d64b018a..6ec5897c577 100644 --- a/data/libs/functions/container.lua +++ b/data/libs/functions/container.lua @@ -8,7 +8,7 @@ end function Container:addLoot(loot) for itemId, item in pairs(loot) do logger.debug("[Container:addLoot] - Adding loot item id: {} to container id: {}", itemId, self:getId()) - local tmpItem = self:addItem(itemId, item.count) + local tmpItem = self:addItem(itemId, item.count, INDEX_WHEREEVER, FLAG_NOLIMIT) if tmpItem then if tmpItem:isContainer() and item.childLoot then if not tmpItem:addLoot(item.childLoot) then diff --git a/data/libs/functions/game.lua b/data/libs/functions/game.lua index 3ea70a43608..f9242c32d88 100644 --- a/data/libs/functions/game.lua +++ b/data/libs/functions/game.lua @@ -131,8 +131,7 @@ function Game.getStorageValue(key) end function Game.setStorageValue(key, value) - local addedValue = globalStorageTable[key] - if addedValue == nil then + if key == nil then logger.error("[Game.setStorageValue] Key is nil") return end