From 9e271d36100ff87d15b3b6141ffd7fac6009260c Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 6 Sep 2024 00:30:59 -0300 Subject: [PATCH 1/3] fix2728 --- .../actions/objects/imbuement_shrine.lua | 2 +- .../actions/other/bed_modification_kits.lua | 6 +- .../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 +- .../lower_roshamuul/actions_mixture.lua | 2 +- .../quests/lower_roshamuul/actions_mortar.lua | 2 +- .../quests/lower_roshamuul/actions_trough.lua | 2 +- .../magma_bubble_fight.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 +++++++++++++------ .../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 71e3776f2f0..4eb743ef1b8 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-canary/scripts/actions/other/bed_modification_kits.lua b/data-canary/scripts/actions/other/bed_modification_kits.lua index 431e3cef5eb..7d6af0eeba3 100644 --- a/data-canary/scripts/actions/other/bed_modification_kits.lua +++ b/data-canary/scripts/actions/other/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 type(target) ~= "userdata" or not target:isItem() then + if not newBed then return false end diff --git a/data-otservbr-global/scripts/actions/object/imbuement_shrine.lua b/data-otservbr-global/scripts/actions/object/imbuement_shrine.lua index 0fb998a9756..a6abe2abd20 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 b696d44c9c6..e54396ad338 100644 --- a/data-otservbr-global/scripts/lib/register_actions.lua +++ b/data-otservbr-global/scripts/lib/register_actions.lua @@ -240,7 +240,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 17b7ffbc976..f6de8c9d0d2 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 b59b1508430..8c68dd1c9ae 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 449e79dc115..aabae68cf11 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 a256e3bf6c6..387634072f4 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 @@ -4,7 +4,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 84dc7e433fa..4ed1dfff530 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/lower_roshamuul/actions_mixture.lua b/data-otservbr-global/scripts/quests/lower_roshamuul/actions_mixture.lua index 9ba1ecf88cb..ea6014e655f 100644 --- a/data-otservbr-global/scripts/quests/lower_roshamuul/actions_mixture.lua +++ b/data-otservbr-global/scripts/quests/lower_roshamuul/actions_mixture.lua @@ -5,7 +5,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/lower_roshamuul/actions_mortar.lua b/data-otservbr-global/scripts/quests/lower_roshamuul/actions_mortar.lua index f62c18dc089..9add87e1b51 100644 --- a/data-otservbr-global/scripts/quests/lower_roshamuul/actions_mortar.lua +++ b/data-otservbr-global/scripts/quests/lower_roshamuul/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/lower_roshamuul/actions_trough.lua b/data-otservbr-global/scripts/quests/lower_roshamuul/actions_trough.lua index 35888d262d8..930eb1b6426 100644 --- a/data-otservbr-global/scripts/quests/lower_roshamuul/actions_trough.lua +++ b/data-otservbr-global/scripts/quests/lower_roshamuul/actions_trough.lua @@ -1,6 +1,6 @@ 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/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/spike_tasks/actions_fertilizer.lua b/data-otservbr-global/scripts/quests/spike_tasks/actions_fertilizer.lua index 9301633af95..9a534a3a4b9 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 16740c7163b..99b36397482 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 @@ -14,7 +14,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 619c93bf024..21baf6f7620 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 55382b260e8..f438e0af3ca 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..424a0ce91d7 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/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 From 11c4f8f34bb9cbaf7092da733d4d87d97fb268fa Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 6 Sep 2024 03:30:06 +0000 Subject: [PATCH 2/3] Lua code format - (Stylua) --- .../scripts/spells/monster/time_guardiann.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data-otservbr-global/scripts/spells/monster/time_guardiann.lua b/data-otservbr-global/scripts/spells/monster/time_guardiann.lua index 424a0ce91d7..26e90ad738b 100644 --- a/data-otservbr-global/scripts/spells/monster/time_guardiann.lua +++ b/data-otservbr-global/scripts/spells/monster/time_guardiann.lua @@ -74,12 +74,12 @@ function spell.onCastSpell(creature, var) 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() From 6448a46653d7caaed24544d20bda2d588102111c Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 6 Sep 2024 03:46:34 -0300 Subject: [PATCH 3/3] Update time_guardiann.lua --- .../scripts/spells/monster/time_guardiann.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data-otservbr-global/scripts/spells/monster/time_guardiann.lua b/data-otservbr-global/scripts/spells/monster/time_guardiann.lua index 26e90ad738b..9e4ffe6ae81 100644 --- a/data-otservbr-global/scripts/spells/monster/time_guardiann.lua +++ b/data-otservbr-global/scripts/spells/monster/time_guardiann.lua @@ -9,7 +9,7 @@ local function functionBack(pos, oldPos) return end - local tile = TIle(position) + local tile = Tile(position) if not tile then return end @@ -70,7 +70,7 @@ function spell.onCastSpell(creature, var) local index = math.random(1, 2) local position = monsters[index].pos if position then - local tile = TIle(position) + local tile = Tile(position) if not tile then return true end