From 7fbf8b8c94924d68eac6f73d0f06c011b4e4a0de Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 26 Oct 2022 10:43:16 -0300 Subject: [PATCH 1/3] Fix leave house remove hireling --- data/scripts/talkactions/player/leave_house.lua | 13 +++++++++++++ data/startup/others/hireling_lib.lua | 2 -- src/lua/functions/map/house_functions.cpp | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/data/scripts/talkactions/player/leave_house.lua b/data/scripts/talkactions/player/leave_house.lua index 0855ed21b3e..05f520f14ff 100644 --- a/data/scripts/talkactions/player/leave_house.lua +++ b/data/scripts/talkactions/player/leave_house.lua @@ -16,6 +16,19 @@ function leaveHouse.onSay(player, words, param) return false end + local tiles = house:getTiles() + if tiles then + for i, tile in pairs(tiles) do + if tile then + local position = Position(tile:getPosition()) + local hireling = getHirelingByPosition(position) + if (hireling) then + hireling:returnToLamp(player:getGuid()) + end + end + end + end + house:setOwnerGuid(0) player:sendTextMessage(MESSAGE_LOOK, "You have successfully left your house.") position:sendMagicEffect(CONST_ME_POFF) diff --git a/data/startup/others/hireling_lib.lua b/data/startup/others/hireling_lib.lua index 6523563637a..5f073d6135d 100644 --- a/data/startup/others/hireling_lib.lua +++ b/data/startup/others/hireling_lib.lua @@ -488,8 +488,6 @@ function PersistHireling(hireling) end end - - -- [[ END GLOBAL FUNCTIONS ]] -- [[ Player extension ]] diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 57b6db50452..d92af9369db 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -259,7 +259,7 @@ int HouseFunctions::luaHouseGetTiles(lua_State* L) { } const auto& tiles = house->getTiles(); - lua_createtable(L, tiles.size(), 0); + lua_newtable(L); int index = 0; for (Tile* tile : tiles) { From e8bcc8b35ea4afea393a463228d4759ff3650124 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 26 Oct 2022 10:44:11 -0300 Subject: [PATCH 2/3] Remove not needed --- data/scripts/talkactions/player/leave_house.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/scripts/talkactions/player/leave_house.lua b/data/scripts/talkactions/player/leave_house.lua index 05f520f14ff..31748032ddf 100644 --- a/data/scripts/talkactions/player/leave_house.lua +++ b/data/scripts/talkactions/player/leave_house.lua @@ -22,7 +22,7 @@ function leaveHouse.onSay(player, words, param) if tile then local position = Position(tile:getPosition()) local hireling = getHirelingByPosition(position) - if (hireling) then + if hireling then hireling:returnToLamp(player:getGuid()) end end From fd207a5f86517d6c8f0d5233e95163eb7facd2d8 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 26 Oct 2022 10:50:17 -0300 Subject: [PATCH 3/3] Fix shadowing variables --- data/scripts/talkactions/player/leave_house.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/data/scripts/talkactions/player/leave_house.lua b/data/scripts/talkactions/player/leave_house.lua index 31748032ddf..46d539345a6 100644 --- a/data/scripts/talkactions/player/leave_house.lua +++ b/data/scripts/talkactions/player/leave_house.lua @@ -1,18 +1,18 @@ local leaveHouse = TalkAction("!leavehouse") function leaveHouse.onSay(player, words, param) - local position = player:getPosition() - local tile = Tile(position) - local house = tile and tile:getHouse() + local playerPosition = player:getPosition() + local playerTile = Tile(playerPosition) + local house = playerTile and playerTile:getHouse() if not house then player:sendCancelMessage("You are not inside a house.") - position:sendMagicEffect(CONST_ME_POFF) + playerPosition:sendMagicEffect(CONST_ME_POFF) return false end if house:getOwnerGuid() ~= player:getGuid() then player:sendCancelMessage("You are not the owner of this house.") - position:sendMagicEffect(CONST_ME_POFF) + playerPosition:sendMagicEffect(CONST_ME_POFF) return false end @@ -31,7 +31,7 @@ function leaveHouse.onSay(player, words, param) house:setOwnerGuid(0) player:sendTextMessage(MESSAGE_LOOK, "You have successfully left your house.") - position:sendMagicEffect(CONST_ME_POFF) + playerPosition:sendMagicEffect(CONST_ME_POFF) return false end