Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: imbuement shrine and time guardian script errors #2877

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 1 deletion data-canary/scripts/actions/other/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 type(target) ~= "userdata" or not target:isItem() then
if not newBed then
return false
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 @@ -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

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 @@ -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

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 @@ -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

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,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

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 @@ -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 @@ -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

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)
luanluciano93 marked this conversation as resolved.
Show resolved Hide resolved
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)
luanluciano93 marked this conversation as resolved.
Show resolved Hide resolved
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
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