Skip to content

Commit

Permalink
Fixed move hireling back to lamp on leave house talkaction (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas authored Oct 27, 2022
1 parent a37fc6f commit 482f020
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
25 changes: 19 additions & 6 deletions data/scripts/talkactions/player/leave_house.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
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

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)
playerPosition:sendMagicEffect(CONST_ME_POFF)
return false
end

Expand Down
2 changes: 0 additions & 2 deletions data/startup/others/hireling_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ function PersistHireling(hireling)
end
end



-- [[ END GLOBAL FUNCTIONS ]]

-- [[ Player extension ]]
Expand Down
2 changes: 1 addition & 1 deletion src/lua/functions/map/house_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 482f020

Please sign in to comment.