From 6392cb2468b241288684d3bb094e3989ecac3090 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 00:08:31 -0300 Subject: [PATCH 1/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 35 ++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index a927715cd93..790c41b68cf 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -402,7 +402,7 @@ function parseBuyStoreOffer(playerId, msg) -- All guarding conditions under which the offer should not be processed must be included here if - (table.contains(GameStore.OfferTypes, offer.type) == false) -- we've got an invalid offer type + (not table.contains(GameStore.OfferTypes, offer.type)) -- we've got an invalid offer type or not player or (player:getVocation():getId() == 0) and (not GameStore.haveOfferRook(id)) -- we don't have such offer or not offer @@ -620,7 +620,7 @@ end function Player.canBuyOffer(self, offer) local playerId = self:getId() local disabled, disabledReason = 0, "" - if offer.disabled == true or not offer.type then + if offer.disabled or not offer.type then disabled = 1 end @@ -693,7 +693,7 @@ function Player.canBuyOffer(self, offer) end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_MOUNT then local hasMount = self:hasMount(offer.id) - if hasMount == true then + if hasMount then disabled = 1 disabledReason = "You already have this mount." end @@ -1183,7 +1183,7 @@ function sendStoreBalanceUpdating(playerId, updating) msg:addByte(0x00) msg:sendToPlayer(player) - if updating == true then + if updating then sendUpdatedStoreBalances(playerId) end end @@ -1346,7 +1346,7 @@ end GameStore.retrieveHistoryTotalPages = function(accountId) local resultId = db.storeQuery("SELECT count(id) as total FROM store_history WHERE account_id = " .. accountId) - if resultId == false then + if not resultId then return 0 end @@ -1602,7 +1602,7 @@ function GameStore.processStackablePurchase(player, offerId, offerCount, offerNa local countToAdd = math.min(remainingCount, stackSize) local inboxItem = inbox:addItem(offerId, countToAdd) if inboxItem then - if movable ~= true then + if not movable then inboxItem:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end else @@ -1631,21 +1631,32 @@ function GameStore.processHouseRelatedPurchase(player, offer) local inbox = player:getStoreInbox() if inbox then for _, itemId in ipairs(itemIds) do - for i = 1, offer.count do + if isCaskItem(itemId) then local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1) if decoKit then decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a <" .. ItemType(itemId):getName() .. ">.") decoKit:setCustomAttribute("unWrapId", itemId) - if isCaskItem(itemId) then - decoKit:setAttribute(ITEM_ATTRIBUTE_DATE, offer.count) - end + decoKit:setAttribute(ITEM_ATTRIBUTE_DATE, offer.count) - if offer.movable ~= true then + if not offer.movable then decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end end + player:sendUpdateContainer(inbox) + else + for i = 1, offer.count do + local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1) + if decoKit then + decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a <" .. ItemType(itemId):getName() .. ">.") + decoKit:setCustomAttribute("unWrapId", itemId) + + if not offer.movable then + decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) + end + end + player:sendUpdateContainer(inbox) + end end - player:sendUpdateContainer(inbox) end end end From 7c416cf65565ddcac5151ab0517c51e8538ca7ab Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 19:24:57 -0300 Subject: [PATCH 2/9] Update data/modules/scripts/gamestore/init.lua Co-authored-by: Elson Costa --- data/modules/scripts/gamestore/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 790c41b68cf..30fef94c1d9 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -402,7 +402,7 @@ function parseBuyStoreOffer(playerId, msg) -- All guarding conditions under which the offer should not be processed must be included here if - (not table.contains(GameStore.OfferTypes, offer.type)) -- we've got an invalid offer type + not table.contains(GameStore.OfferTypes, offer.type) -- we've got an invalid offer type or not player or (player:getVocation():getId() == 0) and (not GameStore.haveOfferRook(id)) -- we don't have such offer or not offer From 892282fd8c5b201b61e3d70e8025cd40729af989 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 19:46:26 -0300 Subject: [PATCH 3/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 64 +++++++++++++------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 30fef94c1d9..70666ff545e 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -692,8 +692,7 @@ function Player.canBuyOffer(self, offer) disabledReason = "The offer is fake." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_MOUNT then - local hasMount = self:hasMount(offer.id) - if hasMount then + if self:hasMount(offer.id) then disabled = 1 disabledReason = "You already have this mount." end @@ -723,12 +722,11 @@ function Player.canBuyOffer(self, offer) disabledReason = "You already have 3 slots released." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then - local remainingBoost = self:getExpBoostStamina() if self:getStorageValue(GameStore.Storages.expBoostCount) == 6 then disabled = 1 disabledReason = "You can't buy XP Boost for today." end - if remainingBoost > 0 then + if self:getExpBoostStamina() > 0 then disabled = 1 disabledReason = "You already have an active XP boost." end @@ -786,9 +784,9 @@ function Player.canReceiveStoreItems(self, offerId, offerCount) local inboxItems = inbox:getItems(true) local slotsOccupied = #inboxItems local maxCapacity = inbox:getMaxCapacity() - local slotsAvailable = maxCapacity - slotsOccupied if slotsOccupied + slotsNeeded > maxCapacity then + local slotsAvailable = maxCapacity - slotsOccupied return false, string.format("Not enough free slots in your store inbox. You need %d more slot(s). Currently occupied: %d/%d", slotsNeeded - slotsAvailable, slotsOccupied, maxCapacity) end @@ -1104,14 +1102,16 @@ function sendStoreTransactionHistory(playerId, page, entriesPerPage) if not player then return false end - local oldProtocol = player:getClient().version < 1200 - local totalEntries = GameStore.retrieveHistoryTotalPages(player:getAccountId()) - local totalPages = math.ceil(totalEntries / entriesPerPage) + local entries = GameStore.retrieveHistoryEntries(player:getAccountId(), page, entriesPerPage) -- this makes everything easy! if #entries == 0 then return addPlayerEvent(sendStoreError, 250, playerId, GameStore.StoreErrors.STORE_ERROR_HISTORY, "You don't have any entries yet.") end + local oldProtocol = player:getClient().version < 1200 + local totalEntries = GameStore.retrieveHistoryTotalPages(player:getAccountId()) + local totalPages = math.ceil(totalEntries / entriesPerPage) + local msg = NetworkMessage() msg:addByte(GameStore.SendingPackets.S_OpenTransactionHistory) msg:addU32(totalPages > 0 and page - 1 or 0x0) -- current page @@ -1165,10 +1165,8 @@ function sendStoreError(playerId, errorType, message) local msg = NetworkMessage() msg:addByte(GameStore.SendingPackets.S_StoreError) - msg:addByte(errorType) msg:addString(message, "sendStoreError - message") - msg:sendToPlayer(player) end @@ -1194,7 +1192,6 @@ function sendUpdatedStoreBalances(playerId) return false end - local oldProtocol = player:getClient().version < 1200 local msg = NetworkMessage() msg:addByte(GameStore.SendingPackets.S_CoinBalanceUpdating) msg:addByte(0x01) @@ -1205,6 +1202,8 @@ function sendUpdatedStoreBalances(playerId) -- Send total of coins (transferable and normal coin) msg:addU32(player:getTibiaCoins()) msg:addU32(player:getTransferableCoins()) -- How many are Transferable + + local oldProtocol = player:getClient().version < 1200 if not oldProtocol then -- How many are reserved for a Character Auction -- We currently do not have this system implemented, so we will send 0 @@ -1360,7 +1359,7 @@ GameStore.retrieveHistoryEntries = function(accountId, currentPage, entriesPerPa local offset = currentPage > 1 and entriesPerPage * (currentPage - 1) or 0 local resultId = db.storeQuery("SELECT * FROM `store_history` WHERE `account_id` = " .. accountId .. " ORDER BY `time` DESC LIMIT " .. offset .. ", " .. entriesPerPage .. ";") - if resultId ~= false then + if resultId then repeat local entry = { mode = Result.getNumber(resultId, "mode"), @@ -1700,8 +1699,6 @@ function GameStore.processMountPurchase(player, offerId) end function GameStore.processNameChangePurchase(player, offer, productType, newName) - local playerId = player:getId() - if productType == GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE then local tile = Tile(player:getPosition()) if tile then @@ -1731,11 +1728,11 @@ function GameStore.processNameChangePurchase(player, offer, productType, newName else message = "Your character has been renamed successfully." end - addPlayerEvent(sendStorePurchaseSuccessful, 500, playerId, message) + addPlayerEvent(sendStorePurchaseSuccessful, 500, player:getId(), message) player:changeName(newName) else - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) + return addPlayerEvent(sendRequestPurchaseData, 250, player:getId(), offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) end end @@ -1791,9 +1788,6 @@ function GameStore.processTempleTeleportPurchase(player) end function GameStore.processHirelingPurchase(player, offer, productType, hirelingName, chosenSex) - local playerId = player:getId() - local offerId = offer.id - if player:getClient().version < 1200 then return error({ code = 1, message = "You cannot buy hirelings on client 10, please relog on client 12 and try again." }) end @@ -1815,7 +1809,7 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN player:makeCoinTransaction(offer, hirelingName) local message = "You have successfully bought " .. hirelingName - return addPlayerEvent(sendStorePurchaseSuccessful, 650, playerId, message) + return addPlayerEvent(sendStorePurchaseSuccessful, 650, player:getId(), message) -- If not, we ask him to do! else if player:getHirelingsCount() >= 10 then @@ -1823,14 +1817,11 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN end -- TODO: Use the correct dialog (byte 0xDB) on client 1205+ -- for compatibility, request name using the change name dialog - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offerId, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_HIRELING) + return addPlayerEvent(sendRequestPurchaseData, 250, player:getId(), offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_HIRELING) end end function GameStore.processHirelingChangeNamePurchase(player, offer, productType, newHirelingName) - local playerId = player:getId() - local offerId = offer.id - if player:getClient().version < 1200 then return error({ code = 1, @@ -1849,17 +1840,15 @@ function GameStore.processHirelingChangeNamePurchase(player, offer, productType, end) local message = "Close the store window to select which hireling should be renamed to " .. newHirelingName + local playerId = player:getId() addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) - addPlayerEvent(HandleHirelingNameChange, 550, playerId, offer, newHirelingName) else - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offerId, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) + return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) end end function GameStore.processHirelingChangeSexPurchase(player, offer) - local playerId = player:getId() - if player:getClient().version < 1200 then return error({ code = 1, @@ -1868,8 +1857,8 @@ function GameStore.processHirelingChangeSexPurchase(player, offer) end local message = "Close the store window to select which hireling should have the sex changed." + local playerId = player:getId() addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) - addPlayerEvent(HandleHirelingSexChange, 550, playerId, offer) end @@ -2169,11 +2158,16 @@ end -- Hireling Helpers function HandleHirelingNameChange(playerId, offer, newHirelingName) local player = Player(playerId) + if not player then + return + end local cb = function(playerId, data, hireling) - local offer = data.offer - local newHirelingName = data.newHirelingName local player = Player(playerId) + if not player then + return + end + if not hireling then return player:showInfoModal("Error", "Your must select a hireling.") end @@ -2183,6 +2177,7 @@ function HandleHirelingNameChange(playerId, offer, newHirelingName) end local oldName = hireling.name + local newHirelingName = data.newHirelingName hireling.name = newHirelingName if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then @@ -2202,9 +2197,16 @@ end function HandleHirelingSexChange(playerId, offer) local player = Player(playerId) + if not player then + return + end local cb = function(playerId, data, hireling) local player = Player(playerId) + if not player then + return + end + if not hireling then return player:showInfoModal("Error", "Your must select a hireling.") end From 96174b1547107f2136e9caa508cd83c8b43b7388 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 29 Mar 2024 22:47:01 +0000 Subject: [PATCH 4/9] Lua code format - (Stylua) --- data/modules/scripts/gamestore/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 70666ff545e..078ba4a15ae 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -2167,7 +2167,7 @@ function HandleHirelingNameChange(playerId, offer, newHirelingName) if not player then return end - + if not hireling then return player:showInfoModal("Error", "Your must select a hireling.") end @@ -2206,7 +2206,7 @@ function HandleHirelingSexChange(playerId, offer) if not player then return end - + if not hireling then return player:showInfoModal("Error", "Your must select a hireling.") end From f98651071d6ba37def2913ba5f51044b2f4cb6d0 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 20:09:41 -0300 Subject: [PATCH 5/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 82 +++++++++++++------------ 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 078ba4a15ae..ba92e5f95be 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -1821,6 +1821,48 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN end end +-- Hireling Helpers +local function HandleHirelingNameChange(playerId, offer, newHirelingName) + local player = Player(playerId) + if not player then + return + end + + local functionCallback = function(playerId, data, hireling) + local player = Player(playerId) + if not player then + return + end + + local offer = data.offer + local newHirelingName = data.newHirelingName + + if not hireling then + return player:showInfoModal("Error", "Your must select a hireling.") + end + + if hireling.active > 0 then + return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") + end + + local oldName = hireling.name + hireling.name = newHirelingName + + if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then + return player:showInfoModal("Error", "Transaction error") + end + + local lamp = player:findHirelingLamp(hireling:getId()) + if lamp then + lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".") + end + logger.debug("{} has been renamed to {}", oldName, newHirelingName) + sendUpdatedStoreBalances(playerId) + end + + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", functionCallback, { offer = offer, newHirelingName = newHirelingName }) +end + function GameStore.processHirelingChangeNamePurchase(player, offer, productType, newHirelingName) if player:getClient().version < 1200 then return error({ @@ -2155,46 +2197,6 @@ function Player:openStore(serviceName) --exporting the method so other scripts c end end --- Hireling Helpers -function HandleHirelingNameChange(playerId, offer, newHirelingName) - local player = Player(playerId) - if not player then - return - end - - local cb = function(playerId, data, hireling) - local player = Player(playerId) - if not player then - return - end - - if not hireling then - return player:showInfoModal("Error", "Your must select a hireling.") - end - - if hireling.active > 0 then - return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") - end - - local oldName = hireling.name - local newHirelingName = data.newHirelingName - hireling.name = newHirelingName - - if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then - return player:showInfoModal("Error", "Transaction error") - end - - local lamp = player:findHirelingLamp(hireling:getId()) - if lamp then - lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".") - end - logger.debug("{} has been renamed to {}", oldName, newHirelingName) - sendUpdatedStoreBalances(playerId) - end - - player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer, newHirelingName = newHirelingName }) -end - function HandleHirelingSexChange(playerId, offer) local player = Player(playerId) if not player then From 2eaf63e98e0cb347f09ecdc597840c7efa21d79b Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 20:11:22 -0300 Subject: [PATCH 6/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 90 ++++++++++++------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index ba92e5f95be..91a64d65868 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -1890,6 +1890,51 @@ function GameStore.processHirelingChangeNamePurchase(player, offer, productType, end end +local function HandleHirelingSexChange(playerId, offer) + local player = Player(playerId) + if not player then + return + end + + local cb = function(playerId, data, hireling) + local player = Player(playerId) + if not player then + return + end + + if not hireling then + return player:showInfoModal("Error", "Your must select a hireling.") + end + + if hireling.active > 0 then + return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") + end + + if not player:makeCoinTransaction(data.offer, hireling:getName()) then + return player:showInfoModal("Error", "Transaction error") + end + + local changeTo, sexString, lookType + if hireling.sex == HIRELING_SEX.FEMALE then + changeTo = HIRELING_SEX.MALE + sexString = "male" + lookType = HIRELING_OUTFIT_DEFAULT.male + else + changeTo = HIRELING_SEX.FEMALE + sexString = "female" + lookType = HIRELING_OUTFIT_DEFAULT.female + end + + hireling.sex = changeTo + hireling.looktype = lookType + + logger.debug("{} sex was changed to {}", hireling:getName(), sexString) + sendUpdatedStoreBalances(playerId) + end + + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer }) +end + function GameStore.processHirelingChangeSexPurchase(player, offer) if player:getClient().version < 1200 then return error({ @@ -2196,48 +2241,3 @@ function Player:openStore(serviceName) --exporting the method so other scripts c addPlayerEvent(sendShowStoreOffers, 50, playerId, category) end end - -function HandleHirelingSexChange(playerId, offer) - local player = Player(playerId) - if not player then - return - end - - local cb = function(playerId, data, hireling) - local player = Player(playerId) - if not player then - return - end - - if not hireling then - return player:showInfoModal("Error", "Your must select a hireling.") - end - - if hireling.active > 0 then - return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") - end - - if not player:makeCoinTransaction(data.offer, hireling:getName()) then - return player:showInfoModal("Error", "Transaction error") - end - - local changeTo, sexString, lookType - if hireling.sex == HIRELING_SEX.FEMALE then - changeTo = HIRELING_SEX.MALE - sexString = "male" - lookType = HIRELING_OUTFIT_DEFAULT.male - else - changeTo = HIRELING_SEX.FEMALE - sexString = "female" - lookType = HIRELING_OUTFIT_DEFAULT.female - end - - hireling.sex = changeTo - hireling.looktype = lookType - - logger.debug("{} sex was changed to {}", hireling:getName(), sexString) - sendUpdatedStoreBalances(playerId) - end - - player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer }) -end From ef4be4abf97bcc317e256d6b5ba0d771079676ff Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 20:16:13 -0300 Subject: [PATCH 7/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 91a64d65868..257b002d16e 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -1828,9 +1828,9 @@ local function HandleHirelingNameChange(playerId, offer, newHirelingName) return end - local functionCallback = function(playerId, data, hireling) - local player = Player(playerId) - if not player then + local functionCallback = function(playerIdInFunction, data, hireling) + local playerInFunction = Player(playerIdInFunction) + if not playerInFunction then return end @@ -1838,26 +1838,26 @@ local function HandleHirelingNameChange(playerId, offer, newHirelingName) local newHirelingName = data.newHirelingName if not hireling then - return player:showInfoModal("Error", "Your must select a hireling.") + return playerInFunction:showInfoModal("Error", "Your must select a hireling.") end if hireling.active > 0 then - return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") + return playerInFunction:showInfoModal("Error", "Your hireling must be inside his/her lamp.") end local oldName = hireling.name hireling.name = newHirelingName - if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then - return player:showInfoModal("Error", "Transaction error") + if not playerInFunction:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then + return playerInFunction:showInfoModal("Error", "Transaction error") end - local lamp = player:findHirelingLamp(hireling:getId()) + local lamp = playerInFunction:findHirelingLamp(hireling:getId()) if lamp then lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".") end logger.debug("{} has been renamed to {}", oldName, newHirelingName) - sendUpdatedStoreBalances(playerId) + sendUpdatedStoreBalances(playerIdInFunction) end player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", functionCallback, { offer = offer, newHirelingName = newHirelingName }) @@ -1896,22 +1896,22 @@ local function HandleHirelingSexChange(playerId, offer) return end - local cb = function(playerId, data, hireling) - local player = Player(playerId) - if not player then + local functionCallback = function(playerIdInFunction, data, hireling) + local playerInFunction = Player(playerIdInFunction) + if not playerInFunction then return end if not hireling then - return player:showInfoModal("Error", "Your must select a hireling.") + return playerInFunction:showInfoModal("Error", "Your must select a hireling.") end if hireling.active > 0 then - return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") + return playerInFunction:showInfoModal("Error", "Your hireling must be inside his/her lamp.") end - if not player:makeCoinTransaction(data.offer, hireling:getName()) then - return player:showInfoModal("Error", "Transaction error") + if not playerInFunction:makeCoinTransaction(data.offer, hireling:getName()) then + return playerInFunction:showInfoModal("Error", "Transaction error") end local changeTo, sexString, lookType @@ -1929,10 +1929,10 @@ local function HandleHirelingSexChange(playerId, offer) hireling.looktype = lookType logger.debug("{} sex was changed to {}", hireling:getName(), sexString) - sendUpdatedStoreBalances(playerId) + sendUpdatedStoreBalances(playerIdInFunction) end - player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer }) + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", functionCallback, { offer = offer }) end function GameStore.processHirelingChangeSexPurchase(player, offer) From 7717b892b14ea163180d44fdbce6aa5ec59aa2f5 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 20:18:05 -0300 Subject: [PATCH 8/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 257b002d16e..d8076aee09d 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -1834,9 +1834,6 @@ local function HandleHirelingNameChange(playerId, offer, newHirelingName) return end - local offer = data.offer - local newHirelingName = data.newHirelingName - if not hireling then return playerInFunction:showInfoModal("Error", "Your must select a hireling.") end @@ -1846,9 +1843,9 @@ local function HandleHirelingNameChange(playerId, offer, newHirelingName) end local oldName = hireling.name - hireling.name = newHirelingName + hireling.name = data.newHirelingName - if not playerInFunction:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then + if not playerInFunction:makeCoinTransaction(data.offer, oldName .. " to " .. hireling.name) then return playerInFunction:showInfoModal("Error", "Transaction error") end @@ -1856,7 +1853,7 @@ local function HandleHirelingNameChange(playerId, offer, newHirelingName) if lamp then lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".") end - logger.debug("{} has been renamed to {}", oldName, newHirelingName) + logger.debug("{} has been renamed to {}", oldName, hireling.name) sendUpdatedStoreBalances(playerIdInFunction) end From ed3ef5f767603797bdfeabb8d71848c3ca8ea628 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Mar 2024 20:25:21 -0300 Subject: [PATCH 9/9] Update init.lua --- data/modules/scripts/gamestore/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index d8076aee09d..6146f562307 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -1883,7 +1883,7 @@ function GameStore.processHirelingChangeNamePurchase(player, offer, productType, addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) addPlayerEvent(HandleHirelingNameChange, 550, playerId, offer, newHirelingName) else - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) + return addPlayerEvent(sendRequestPurchaseData, 250, player:getId(), offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) end end