Skip to content

Commit

Permalink
fix: imbuement shrine and time guardian script errors (opentibiabr#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 authored and vllworldbuilding committed Jan 10, 2025
1 parent 0175b3d commit 37a358d
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 46 deletions.
2 changes: 1 addition & 1 deletion data-canary/scripts/actions/objects/imbuement_shrine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/lib/register_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
99 changes: 71 additions & 28 deletions data-otservbr-global/scripts/spells/monster/time_guardiann.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion data/scripts/actions/items/bed_modification_kits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/items/exercise_training_weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 37a358d

Please sign in to comment.