Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leave house remove hireling #556

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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