From 9b2c08e368dbdee198c006daffa3b626e7c9e43d Mon Sep 17 00:00:00 2001 From: HT Cesta <58153179+htc16@users.noreply.github.com> Date: Sat, 14 Sep 2024 09:58:28 -0300 Subject: [PATCH] @omarcopires --- data-otservbr-global/npc/gnombold.lua | 3 -- data-otservbr-global/npc/gnome_trooper.lua | 43 +++++++++++----------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/data-otservbr-global/npc/gnombold.lua b/data-otservbr-global/npc/gnombold.lua index c4d0b7b83bb..5786bd0e2d0 100644 --- a/data-otservbr-global/npc/gnombold.lua +++ b/data-otservbr-global/npc/gnombold.lua @@ -142,9 +142,6 @@ local function creatureSayCallback(npc, creature, type, message) return end - --[[///////////////////// - ////GEOMANTIC CHARGES//// - ///////////////////////]] if MsgContains(message, "charges") then if player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Spike_Middle_Charge_Daily) >= os.time() then return npcHandler:say("Sorry, you have to wait " .. string.diff(player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Spike_Middle_Charge_Daily) - os.time()) .. " before this task gets available again.", npc, creature) diff --git a/data-otservbr-global/npc/gnome_trooper.lua b/data-otservbr-global/npc/gnome_trooper.lua index 359aa90552b..bc25817247b 100644 --- a/data-otservbr-global/npc/gnome_trooper.lua +++ b/data-otservbr-global/npc/gnome_trooper.lua @@ -57,38 +57,37 @@ local response = { [3] = "A medal of honour! At last they saw my true worth!", } +local function initializeParcelDelivery(player) + local playerGuid = player:getGuid() + if not DELIVERED_PARCELS[playerGuid] then + DELIVERED_PARCELS[playerGuid] = {} + end + + return DELIVERED_PARCELS[playerGuid] +end + local function greetCallback(npc, creature) local player = Player(creature) - local playerId = player:getId() - - -- Inicializa a tabela se ela for nil - if not DELIVERED_PARCELS[player:getGuid()] then - DELIVERED_PARCELS[player:getGuid()] = {} - end + local playerGuid = player:getGuid() + local deliveredParcels = initializeParcelDelivery(player) + local parcelStatus = player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Constants.Spike_Lower_Parcel_Main) - if table.contains({ -1, 4 }, player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Spike_Lower_Parcel_Main)) then - return false - end - if table.contains(DELIVERED_PARCELS[player:getGuid()], npc:getId()) then + if table.contains({-1, 4}, parcelStatus) or table.contains(deliveredParcels, npc:getId()) then return false end npcHandler:setMessage(MESSAGE_GREET, "Do you have something to deliver?") - return true end local function creatureSayCallback(npc, creature, type, message) local player = Player(creature) - local status = player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Spike_Lower_Parcel_Main) - - -- Inicializa a tabela se ela for nil - if not DELIVERED_PARCELS[player:getGuid()] then - DELIVERED_PARCELS[player:getGuid()] = {} - end + local playerGuid = player:getGuid() + local deliveredParcels = initializeParcelDelivery(player) + local parcelStatus = player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Constants.Spike_Lower_Parcel_Main) - if MsgContains(message, "something") and not table.contains({ -1, 4 }, status) then - if table.contains(DELIVERED_PARCELS[player:getGuid()], npc:getId()) then + if MsgContains(message, "something") and not table.contains({-1, 4}, parcelStatus) then + if table.contains(deliveredParcels, npc:getId()) then return true end @@ -97,9 +96,9 @@ local function creatureSayCallback(npc, creature, type, message) return npcHandler:removeInteraction(npc, creature) end - npcHandler:say(response[player:getStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Spike_Lower_Parcel_Main)], npc, creature) - player:setStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Spike_Lower_Parcel_Main, status + 1) - table.insert(DELIVERED_PARCELS[player:getGuid()], npc:getId()) + npcHandler:say(response[parcelStatus], npc, creature) + player:setStorageValue(Storage.Quest.U10_20.SpikeTaskQuest.Constants.Spike_Lower_Parcel_Main, parcelStatus + 1) + table.insert(deliveredParcels, npc:getId()) npcHandler:removeInteraction(npc, creature) end return true