From aa779bbdd985e192fe7a210bef64397f04597918 Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Thu, 23 Jan 2020 21:02:43 +0200 Subject: [PATCH] fix houses to be buyable by website only and rent would be taken from player balance --- data/talkactions/scripts/buyhouse.lua | 34 +------------------------- data/talkactions/scripts/znoteshop.lua | 12 +++++---- src/house.cpp | 9 +++---- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/data/talkactions/scripts/buyhouse.lua b/data/talkactions/scripts/buyhouse.lua index 5e3020b..9896bbf 100644 --- a/data/talkactions/scripts/buyhouse.lua +++ b/data/talkactions/scripts/buyhouse.lua @@ -1,36 +1,4 @@ function onSay(player, words, param) - if player:getPremiumDays() <= 0 then - player:sendCancelMessage("You need a premium account.") - return false - end - - local position = player:getPosition() - position:getNextPosition(player:getDirection()) - - local tile = Tile(position) - local house = tile and tile:getHouse() - if house == nil then - player:sendCancelMessage("You have to be looking at the door of the house you would like to buy.") - return false - end - - if house:getOwnerGuid() > 0 then - player:sendCancelMessage("This house already has an owner.") - return false - end - - if player:getHouse() then - player:sendCancelMessage("You are already the owner of a house.") - return false - end - - local price = house:getRent() * 5 - if not player:removeMoney(price) then - player:sendCancelMessage("You do not have enough money.") - return false - end - - house:setOwnerGuid(player:getGuid()) - player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.") + player:sendTextMessage(MESSAGE_INFO_DESCR, "Buying a house is available only through auction which is available at website: https://sabrehaven.com/house.php") return false end diff --git a/data/talkactions/scripts/znoteshop.lua b/data/talkactions/scripts/znoteshop.lua index 9fbcfe0..788ef6a 100644 --- a/data/talkactions/scripts/znoteshop.lua +++ b/data/talkactions/scripts/znoteshop.lua @@ -85,17 +85,19 @@ function onSay(player, words, param) end -- ORDER TYPE 7 (Direct house purchase) - if orderType == 7 then + if q_type == 7 then served = true - local house = House(orderItemId) + local house = House(q_itemid) -- Logged in player is not neccesarily the player that bough the house. So we need to load player from db. - local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1") + print(q_count) + local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..q_count.." LIMIT 1") + if buyerQuery ~= false then local buyerName = result.getDataString(buyerQuery, "name") result.free(buyerQuery) if house then - db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";") - house:setOwnerGuid(orderCount) + db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + house:setOwnerGuid(q_count) player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.") print("Process complete. [".. buyerName .."] has recieved house: ["..house:getName().."]") end diff --git a/src/house.cpp b/src/house.cpp index 29f375c..0864b09 100644 --- a/src/house.cpp +++ b/src/house.cpp @@ -109,11 +109,6 @@ void House::updateDoorDescription() const ss << "It belongs to house '" << houseName << "'. " << ownerName << " owns this house."; } else { ss << "It belongs to house '" << houseName << "'. Nobody owns this house."; - - const int32_t housePrice = getRent(); - if (housePrice != -1) { - ss << " It costs " << housePrice * 5 << " gold coins."; - } } for (const auto& it : doorSet) { @@ -667,7 +662,9 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const continue; } - if (g_game.removeMoney(player.getDepotLocker(house->getTownId(), true), house->getRent(), FLAG_NOLIMIT)) { + if (player.getBankBalance() >= rent) { + player.setBankBalance(player.getBankBalance() - rent); + time_t paidUntil = currentTime; switch (rentPeriod) { case RENTPERIOD_DAILY: