From 37a358d57994425fda902fca082724761ac7daea Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Tue, 31 Dec 2024 15:19:26 -0300 Subject: [PATCH] fix: imbuement shrine and time guardian script errors (#2877) --- .../actions/objects/imbuement_shrine.lua | 2 +- .../actions/object/imbuement_shrine.lua | 2 +- .../scripts/lib/register_actions.lua | 2 +- .../cults_of_tibia/actions_analyser.lua | 2 +- .../cults_of_tibia/actions_counter_agent.lua | 2 +- .../cults_of_tibia/actions_magnifier.lua | 2 +- .../actions_gnomish_pesticide.lua | 2 +- .../actions_using_crystals.lua | 2 +- .../magma_bubble_fight.lua | 2 +- .../roshamuul_quest/actions_mixture.lua | 2 +- .../quests/roshamuul_quest/actions_mortar.lua | 2 +- .../quests/roshamuul_quest/actions_trough.lua | 2 +- .../quests/spike_tasks/actions_fertilizer.lua | 2 +- .../quests/spike_tasks/actions_lode_stone.lua | 2 +- .../spike_tasks/actions_spirit_shovel.lua | 2 +- .../spike_tasks/actions_tuning_fork.lua | 2 +- .../scripts/spells/monster/time_guardiann.lua | 99 +++++++++++++------ .../actions/items/bed_modification_kits.lua | 6 +- .../items/exercise_training_weapons.lua | 2 +- 19 files changed, 93 insertions(+), 46 deletions(-) diff --git a/data-canary/scripts/actions/objects/imbuement_shrine.lua b/data-canary/scripts/actions/objects/imbuement_shrine.lua index 493e00e056c..aea7c1edf47 100644 --- a/data-canary/scripts/actions/objects/imbuement_shrine.lua +++ b/data-canary/scripts/actions/objects/imbuement_shrine.lua @@ -5,7 +5,7 @@ function imbuement.onUse(player, item, fromPosition, target, toPosition, isHotke return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You did not collect enough knowledge from the ancient Shapers. Visit the Shaper temple in Montag for help.") end - if not target or not (target:isItem()) then + if not target or type(target) ~= "userdata" or not target:isItem() then return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use the shrine on an valid item.") end diff --git a/data-otservbr-global/scripts/actions/object/imbuement_shrine.lua b/data-otservbr-global/scripts/actions/object/imbuement_shrine.lua index f5d878df284..5cec0f7506d 100644 --- a/data-otservbr-global/scripts/actions/object/imbuement_shrine.lua +++ b/data-otservbr-global/scripts/actions/object/imbuement_shrine.lua @@ -5,7 +5,7 @@ function imbuement.onUse(player, item, fromPosition, target, toPosition, isHotke return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You did not collect enough knowledge from the ancient Shapers. Visit the Shaper temple in Thais for help.") end - if not target or not (target:isItem()) then + if type(target) ~= "userdata" or not target:isItem() then return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use the shrine on an valid item.") end diff --git a/data-otservbr-global/scripts/lib/register_actions.lua b/data-otservbr-global/scripts/lib/register_actions.lua index d89772f7ce9..48ef4c38993 100644 --- a/data-otservbr-global/scripts/lib/register_actions.lua +++ b/data-otservbr-global/scripts/lib/register_actions.lua @@ -242,7 +242,7 @@ local function addFerumbrasAscendantReward(player, target, toPosition) end function onDestroyItem(player, item, fromPosition, target, toPosition, isHotkey) - if not target or target == nil or type(target) ~= "userdata" or not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/cults_of_tibia/actions_analyser.lua b/data-otservbr-global/scripts/quests/cults_of_tibia/actions_analyser.lua index ce01d36c244..d50d13b6cbd 100644 --- a/data-otservbr-global/scripts/quests/cults_of_tibia/actions_analyser.lua +++ b/data-otservbr-global/scripts/quests/cults_of_tibia/actions_analyser.lua @@ -6,7 +6,7 @@ function cultsOfTibiaAnalyser.onUse(player, item, fromPosition, target, toPositi return true end - if not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/cults_of_tibia/actions_counter_agent.lua b/data-otservbr-global/scripts/quests/cults_of_tibia/actions_counter_agent.lua index 24b414399ee..b083bd45a4c 100644 --- a/data-otservbr-global/scripts/quests/cults_of_tibia/actions_counter_agent.lua +++ b/data-otservbr-global/scripts/quests/cults_of_tibia/actions_counter_agent.lua @@ -19,7 +19,7 @@ function cultsOfTibiaCounter.onUse(player, item, fromPosition, target, toPositio return true end - if not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/cults_of_tibia/actions_magnifier.lua b/data-otservbr-global/scripts/quests/cults_of_tibia/actions_magnifier.lua index e50f94226b0..929ebf362f1 100644 --- a/data-otservbr-global/scripts/quests/cults_of_tibia/actions_magnifier.lua +++ b/data-otservbr-global/scripts/quests/cults_of_tibia/actions_magnifier.lua @@ -7,7 +7,7 @@ function cultsOfTibiaMagnifier.onUse(player, item, fromPosition, target, toPosit return true end - if not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/dangerous_depth/actions_gnomish_pesticide.lua b/data-otservbr-global/scripts/quests/dangerous_depth/actions_gnomish_pesticide.lua index 55aae368926..9d5b9da150d 100644 --- a/data-otservbr-global/scripts/quests/dangerous_depth/actions_gnomish_pesticide.lua +++ b/data-otservbr-global/scripts/quests/dangerous_depth/actions_gnomish_pesticide.lua @@ -5,7 +5,7 @@ function dangerousDepthPesticide.onUse(player, item, fromPosition, target, toPos return true end - if not (target or target:isItem()) then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/dangerous_depth/actions_using_crystals.lua b/data-otservbr-global/scripts/quests/dangerous_depth/actions_using_crystals.lua index 6f134dab02d..948106be648 100644 --- a/data-otservbr-global/scripts/quests/dangerous_depth/actions_using_crystals.lua +++ b/data-otservbr-global/scripts/quests/dangerous_depth/actions_using_crystals.lua @@ -405,7 +405,7 @@ function dangerousDepthCrystals.onUse(player, item, fromPosition, target, toPosi return true end - if not target or not target.isItem or not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/primal_ordeal_quest/magma_bubble_fight.lua b/data-otservbr-global/scripts/quests/primal_ordeal_quest/magma_bubble_fight.lua index 36de1fb1497..35b9728bd69 100644 --- a/data-otservbr-global/scripts/quests/primal_ordeal_quest/magma_bubble_fight.lua +++ b/data-otservbr-global/scripts/quests/primal_ordeal_quest/magma_bubble_fight.lua @@ -208,7 +208,7 @@ function chargedFlameAction.onUse(player, item, fromPosition, target, toPosition if not player then return false end - if not target or not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end if target:getId() ~= config.cooledCrystalId then diff --git a/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mixture.lua b/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mixture.lua index cb2e30d97c8..1e42b82231b 100644 --- a/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mixture.lua +++ b/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mixture.lua @@ -6,7 +6,7 @@ local buckets = { local lowerRoshamuulMixtune = Action() function lowerRoshamuulMixtune.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if (target == nil) or not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mortar.lua b/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mortar.lua index f62c18dc089..9add87e1b51 100644 --- a/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mortar.lua +++ b/data-otservbr-global/scripts/quests/roshamuul_quest/actions_mortar.lua @@ -1,6 +1,6 @@ local lowerRoshamuulMortar = Action() function lowerRoshamuulMortar.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if (target == nil) or not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/roshamuul_quest/actions_trough.lua b/data-otservbr-global/scripts/quests/roshamuul_quest/actions_trough.lua index c511ae3d921..11613fe68d6 100644 --- a/data-otservbr-global/scripts/quests/roshamuul_quest/actions_trough.lua +++ b/data-otservbr-global/scripts/quests/roshamuul_quest/actions_trough.lua @@ -1,7 +1,7 @@ local lowerRoshamuulTrough = Action() function lowerRoshamuulTrough.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if (target == nil) or not target:isItem() then + if not target or type(target) ~= "userdata" or not target:isItem() then return false end diff --git a/data-otservbr-global/scripts/quests/spike_tasks/actions_fertilizer.lua b/data-otservbr-global/scripts/quests/spike_tasks/actions_fertilizer.lua index c97e06e98a4..5965fce6d54 100644 --- a/data-otservbr-global/scripts/quests/spike_tasks/actions_fertilizer.lua +++ b/data-otservbr-global/scripts/quests/spike_tasks/actions_fertilizer.lua @@ -8,7 +8,7 @@ function spikeTasksFertilizer.onUse(player, item, fromPosition, target, toPositi return false end - if (target == nil) or not target:isItem() or (target:getId() ~= 19215) then + if not target or type(target) ~= "userdata" or not target:isItem() or (target:getId() ~= 19215) then return false end diff --git a/data-otservbr-global/scripts/quests/spike_tasks/actions_lode_stone.lua b/data-otservbr-global/scripts/quests/spike_tasks/actions_lode_stone.lua index 7a3060a1fc9..b976684a818 100644 --- a/data-otservbr-global/scripts/quests/spike_tasks/actions_lode_stone.lua +++ b/data-otservbr-global/scripts/quests/spike_tasks/actions_lode_stone.lua @@ -11,7 +11,7 @@ function spikeTasksStone.onUse(player, item, fromPosition, target, toPosition, i return false end - if (target == nil) or not target:isItem() or (target:getId() ~= 19217) then + if not target or type(target) ~= "userdata" or not target:isItem() or (target:getId() ~= 19217) then return false end diff --git a/data-otservbr-global/scripts/quests/spike_tasks/actions_spirit_shovel.lua b/data-otservbr-global/scripts/quests/spike_tasks/actions_spirit_shovel.lua index 51979b622ca..f2d2c13fc42 100644 --- a/data-otservbr-global/scripts/quests/spike_tasks/actions_spirit_shovel.lua +++ b/data-otservbr-global/scripts/quests/spike_tasks/actions_spirit_shovel.lua @@ -12,7 +12,7 @@ function spikeTasksShovel.onUse(player, item, fromPosition, target, toPosition, return player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) end - if (target == nil) or not target:isItem() or (target:getId() ~= 19211) then + if not target or type(target) ~= "userdata" or not target:isItem() or (target:getId() ~= 19211) then return player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) end diff --git a/data-otservbr-global/scripts/quests/spike_tasks/actions_tuning_fork.lua b/data-otservbr-global/scripts/quests/spike_tasks/actions_tuning_fork.lua index 2ae79bd368c..74086b9408f 100644 --- a/data-otservbr-global/scripts/quests/spike_tasks/actions_tuning_fork.lua +++ b/data-otservbr-global/scripts/quests/spike_tasks/actions_tuning_fork.lua @@ -4,7 +4,7 @@ function spikeTasksFork.onUse(player, item, fromPosition, target, toPosition, is return player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) end - if (target == nil) or not target:isItem() or (target:getId() ~= 19208) then + if not target or type(target) ~= "userdata" or not target:isItem() or (target:getId() ~= 19208) then return player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) end diff --git a/data-otservbr-global/scripts/spells/monster/time_guardiann.lua b/data-otservbr-global/scripts/spells/monster/time_guardiann.lua index f98ee4195c9..9e4ffe6ae81 100644 --- a/data-otservbr-global/scripts/spells/monster/time_guardiann.lua +++ b/data-otservbr-global/scripts/spells/monster/time_guardiann.lua @@ -3,51 +3,94 @@ local monsters = { [2] = { pos = Position(32815, 32664, 14) }, } -local function functionBack(position, oldpos) - local guardian = Tile(position):getTopCreature() - local bool, diference, health = false, 0, 0 - local spectators, spectator = Game.getSpectators(Position(32813, 32664, 14), false, false, 15, 15, 15, 15) - for v = 1, #spectators do - spectator = spectators[v] - if spectator:getName():lower() == "the blazing time guardian" or spectator:getName():lower() == "the freezing time guardian" then - oldpos = spectator:getPosition() - bool = true +local function functionBack(pos, oldPos) + local position = Position(pos) + if not position then + return + end + + local tile = Tile(position) + if not tile then + return + end + + local guardian = tile:getTopCreature() + if not guardian then + return + end + + local haveGuardianMonster = false + local spectator1 = nil + + local spectators1 = Game.getSpectators(Position(32813, 32664, 14), false, false, 15, 15, 15, 15) + for index = 1, #spectators1 do + spectator1 = spectators1[index] + if spectator1 then + if spectator1:isMonster() and spectator1:getName():lower() == "the blazing time guardian" or spectator1:getName():lower() == "the freezing time guardian" then + oldPos = spectator1:getPosition() + haveGuardianMonster = true + end end end - if not bool then + + if not haveGuardianMonster then guardian:remove() return true end - local specs, spec = Game.getSpectators(Position(32813, 32664, 14), false, false, 15, 15, 15, 15) - for i = 1, #specs do - spec = specs[i] - if spec:isMonster() and spec:getName():lower() == "the blazing time guardian" or spec:getName():lower() == "the freezing time guardian" then - spec:teleportTo(position) - health = spec:getHealth() - diference = guardian:getHealth() - health + + local diference = 0 + local spectator = nil + + local spectators2, spectator2 = Game.getSpectators(Position(32813, 32664, 14), false, false, 15, 15, 15, 15) + for i = 1, #spectators2 do + spectator2 = spectators2[i] + if spectator2 then + if spectator2:isMonster() and spectator2:getName():lower() == "the blazing time guardian" or spectator2:getName():lower() == "the freezing time guardian" then + spectator2:teleportTo(position) + diference = guardian:getHealth() - spectator2:getHealth() + end end end - guardian:addHealth(-diference) - guardian:teleportTo(oldpos) + + if diference > 0 then + guardian:addHealth(-diference) + end + + guardian:teleportTo(oldPos) end local spell = Spell("instant") function spell.onCastSpell(creature, var) - local index = math.random(1, 2) local monsterPos = creature:getPosition() if monsterPos.z ~= 14 then return true end + + local index = math.random(1, 2) local position = monsters[index].pos - local form = Tile(position):getTopCreature() - creature:teleportTo(position) - local diference, health = 0, 0 - health = creature:getHealth() - diference = form:getHealth() - health - form:addHealth(-diference) - form:teleportTo(monsterPos) - addEvent(functionBack, 30 * 1000, position, monsterPos) + if position then + local tile = Tile(position) + if not tile then + return true + end + + local form = tile:getTopCreature() + if not form then + return true + end + + creature:teleportTo(position) + + local diference = form:getHealth() - creature:getHealth() + if diference and diference > 0 then + form:addHealth(-diference) + end + + form:teleportTo(monsterPos) + addEvent(functionBack, 30 * 1000, position, monsterPos) + end + return true end diff --git a/data/scripts/actions/items/bed_modification_kits.lua b/data/scripts/actions/items/bed_modification_kits.lua index a406f7fd5b2..a50a7a683ec 100644 --- a/data/scripts/actions/items/bed_modification_kits.lua +++ b/data/scripts/actions/items/bed_modification_kits.lua @@ -19,8 +19,12 @@ end local bedModificationKits = Action() function bedModificationKits.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if not target or type(target) ~= "userdata" or not target:isItem() then + return false + end + local newBed = setting[item:getId()] - if not newBed or not target or not target:isItem() then + if not newBed then return false end diff --git a/data/scripts/actions/items/exercise_training_weapons.lua b/data/scripts/actions/items/exercise_training_weapons.lua index 3c62d7c1183..52730ad6edb 100644 --- a/data/scripts/actions/items/exercise_training_weapons.lua +++ b/data/scripts/actions/items/exercise_training_weapons.lua @@ -133,7 +133,7 @@ end local exerciseTraining = Action() function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not target or type(target) == "table" or not target:getId() then + if not target or type(target) ~= "userdata" or not target:isItem() then return true end