From fe4dfdcf4e1d4889f19668dec4159545bb8d0704 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Tue, 16 Aug 2022 11:49:02 -0500 Subject: [PATCH] Check if player is actually in house before forcing out --- scripts/server/house.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/server/house.js b/scripts/server/house.js index 1952a285..7f9be89a 100644 --- a/scripts/server/house.js +++ b/scripts/server/house.js @@ -692,8 +692,13 @@ function deleteHouseCommand(command, params, client) { * @return {bool} Whether or not the house was successfully deleted * */ -function deleteHouse(houseId, whoDeleted = 0) { - let tempHouseData = getServerData().houses[houseId]; +function deleteHouse(houseIndex, whoDeleted = 0) { + if (!getHouseData(houseIndex)) { + messagePlayerError(client, getLocaleString(client, "InvalidHouse")); + return false; + } + + let tempHouseData = getServerData().houses[houseIndex]; let dbConnection = connectToDatabase(); let dbQuery = null; @@ -706,15 +711,15 @@ function deleteHouse(houseId, whoDeleted = 0) { disconnectFromDatabase(dbConnection); } - deleteHouseEntrancePickup(houseId); - deleteHouseExitPickup(houseId); + deleteHouseEntrancePickup(houseIndex); + deleteHouseExitPickup(houseIndex); - deleteHouseEntranceBlip(houseId); - deleteHouseExitBlip(houseId); + deleteHouseEntranceBlip(houseIndex); + deleteHouseExitBlip(houseIndex); - removePlayersFromHouse(houseId); + removePlayersFromHouse(houseIndex); - getServerData().houses.splice(houseId, 1); + getServerData().houses.splice(houseIndex, 1); } // =========================================================================== @@ -739,11 +744,13 @@ function removePlayerFromHouse(client) { * @return {Boolean} Whether or not the players were forced to exit * */ -function removePlayersFromHouse(houseId) { +function removePlayersFromHouse(houseIndex) { getClients().forEach(function (client) { - if (doesHouseHaveInterior(houseId)) { - if (getPlayerHouse(client) == houseId) { - exitHouse(client); + if (doesHouseHaveInterior(houseIndex)) { + if (getPlayerHouse(client) == houseIndex) { + if (getPlayerInterior(client) == getHouseData(houseIndex).exitInterior && getPlayerDimension(client) == getHouseData(houseIndex).exitDimension) { + exitHouse(client); + } } } });