From 18baa005cd935201db0decd3786f85f93295e1c7 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 27 Feb 2024 13:16:02 -0300 Subject: [PATCH 1/2] improve: warning about compat file workarounds Co-Authored-By: Luan Luciano --- .../npc/cranky_lizard_crone.lua | 43 ++++--- data-otservbr-global/npc/eruaran.lua | 60 +++++---- .../actions/other/jean_pierre_food.lua | 26 ++-- .../actions/other/string_of_mending.lua | 48 ++----- .../heart_of_destruction/final_lever.lua | 21 ++-- .../heart_of_destruction/sparks_lever.lua | 10 +- .../mysterious_metal_egg.lua | 6 +- .../rottin_wood_and_married_men/corpse.lua | 14 ++- .../rottin_wood_and_married_men/trap.lua | 24 ++-- .../depolarized_death.lua | 9 +- .../scripts/movements/others/trap.lua | 11 +- .../eruption_of_destruction_explosion.lua | 17 +-- .../spells/monster/gaz'haragoth_death.lua | 17 +-- data/libs/compat/compat.lua | 119 +----------------- data/scripts/talkactions/gm/spy.lua | 14 +-- 15 files changed, 173 insertions(+), 266 deletions(-) diff --git a/data-otservbr-global/npc/cranky_lizard_crone.lua b/data-otservbr-global/npc/cranky_lizard_crone.lua index 6d71f873f54..94261410724 100644 --- a/data-otservbr-global/npc/cranky_lizard_crone.lua +++ b/data-otservbr-global/npc/cranky_lizard_crone.lua @@ -48,16 +48,20 @@ local already = "It seems you already have this addon, don't you try to mock me --WAYFARER START -- function WayfarerFirst(npc, creature, message, keywords, parameters, node) - if isPremium(creature) then - local addon = getPlayerStorageValue(creature, Storage.WayfarerOutfit) - if addon == -1 then - if getPlayerItemCount(creature, 11701) >= 1 then - if doPlayerRemoveItem(creature, 11701, 1) then + local player = Player(creature) + if not player then + return + end + + if player:isPremium() then + if player:getStorageValue(Storage.WayfarerOutfit) < 1 then + if player:getItemCount(11701) > 0 then + if player:removeItem(11701, 1) then npcHandler:say(newaddon, npc, creature) - doSendMagicEffect(getCreaturePosition(creature), 13) - doPlayerAddOutfit(creature, 366, 1) - doPlayerAddOutfit(creature, 367, 1) - setPlayerStorageValue(creature, Storage.WayfarerOutfit, 1) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) + player:addOutfitAddon(366, 1) + player:addOutfitAddon(367, 1) + player:setStorageValue(Storage.WayfarerOutfit, 1) end else npcHandler:say(noItems, npc, creature) @@ -69,15 +73,20 @@ function WayfarerFirst(npc, creature, message, keywords, parameters, node) end function WayfarerSecond(npc, creature, message, keywords, parameters, node) - if isPremium(creature) then - if getPlayerStorageValue(creature, Storage.WayfarerOutfit + 1) == -1 then - if getPlayerItemCount(creature, 11700) >= 1 then - if doPlayerRemoveItem(creature, 11700, 1) then + local player = Player(creature) + if not player then + return + end + + if player:isPremium() then + if player:getStorageValue(Storage.WayfarerOutfit + 1) < 1 then + if player:getItemCount(11700) > 0 then + if player:removeItem(11700, 1) then npcHandler:say(newaddon, npc, creature) - doSendMagicEffect(getCreaturePosition(creature), 13) - doPlayerAddOutfit(creature, 366, 2) - doPlayerAddOutfit(creature, 367, 2) - setPlayerStorageValue(creature, Storage.WayfarerOutfit + 1, 1) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) + player:addOutfitAddon(366, 2) + player:addOutfitAddon(367, 2) + player:setStorageValue(Storage.WayfarerOutfit + 1, 1) end else npcHandler:say(noItems, npc, creature) diff --git a/data-otservbr-global/npc/eruaran.lua b/data-otservbr-global/npc/eruaran.lua index 51c5f17d4e0..541d5bd409c 100644 --- a/data-otservbr-global/npc/eruaran.lua +++ b/data-otservbr-global/npc/eruaran.lua @@ -150,15 +150,20 @@ local ACTION = { -- dream START -- local function dreamFirst(npc, creature, message, keywords, parameters, node) - if isPremium(creature) then - if getPlayerStorageValue(creature, storage + 1) == -1 then - if getPlayerItemCount(creature, 20276) >= 1 then - if doPlayerRemoveItem(creature, 20276, 1) then - npcHandler:say(newAddon, npc, creature) - doSendMagicEffect(getCreaturePosition(creature), 13) - doPlayerAddOutfit(creature, 577, 1) - doPlayerAddOutfit(creature, 578, 1) - setPlayerStorageValue(creature, storage + 1, 1) + local player = Player(creature) + if not player then + return + end + + if player:isPremium() then + if player:getStorageValue(storage + 1) < 1 then + if player:getItemCount(20276) > 0 then + if player:removeItem(20276, 1) then + npcHandler:say(newaddon, npc, creature) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) + player:addOutfitAddon(577, 1) + player:addOutfitAddon(577, 1) + player:setStorageValue(storage + 1, 1) end else npcHandler:say(noItems, npc, creature) @@ -170,15 +175,20 @@ local function dreamFirst(npc, creature, message, keywords, parameters, node) end local function dreamSecond(npc, creature, message, keywords, parameters, node) - if isPremium(creature) then - if getPlayerStorageValue(creature, storage) == -1 then - if getPlayerItemCount(creature, 20275) >= 1 then - if doPlayerRemoveItem(creature, 20275, 1) then - npcHandler:say(newAddon, npc, creature) - doSendMagicEffect(getCreaturePosition(creature), 13) - doPlayerAddOutfit(creature, 577, 2) - doPlayerAddOutfit(creature, 578, 2) - setPlayerStorageValue(creature, storage, 1) + local player = Player(creature) + if not player then + return + end + + if player:isPremium() then + if player:getStorageValue(storage) < 1 then + if player:getItemCount(20275) > 0 then + if player:removeItem(20275, 1) then + npcHandler:say(newaddon, npc, creature) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) + player:addOutfitAddon(577, 2) + player:addOutfitAddon(577, 2) + player:setStorageValue(storage, 1) end else npcHandler:say(noItems, npc, creature) @@ -192,7 +202,9 @@ end local function greetCallback(npc, creature) local player = Player(creature) - local playerId = player:getId() + if not player then + return true + end if player:getStorageValue(Storage.EruaranGreeting) > 0 then npcHandler:setMessage(MESSAGE_GREET, "Ashari Lillithy, so we meet {again}! What brings you here this time, general {information}, {transform}, {improve}, {create}, {outfit}, or {talk}?") @@ -204,13 +216,17 @@ local function greetCallback(npc, creature) end local function creatureSayCallback(npc, creature, type, message) - local player = Player(creature) - local playerId = player:getId() - if not npcHandler:checkInteraction(npc, creature) then return false end + local player = Player(creature) + if not player then + return true + end + + local playerId = player:getId() + if MsgContains(message, "create") then npcHandler:say("You can try to create {sword}s, {axe}s, {club}s, {bow}s, {crossbow}s and {spellbook}s.", npc, creature) npcHandler:setTopic(playerId, 1) diff --git a/data-otservbr-global/scripts/actions/other/jean_pierre_food.lua b/data-otservbr-global/scripts/actions/other/jean_pierre_food.lua index 71627cfc61c..2c26d25d7fb 100644 --- a/data-otservbr-global/scripts/actions/other/jean_pierre_food.lua +++ b/data-otservbr-global/scripts/actions/other/jean_pierre_food.lua @@ -63,7 +63,7 @@ function jeanPierreFood.onUse(player, item, frompos, item2, topos) if item.itemid == 9079 then item:remove(1) - Creature(cid):addHealth(getCreatureMaxHealth(cid) - getCreatureHealth(cid)) + player:addHealth(player:getMaxHealth() - player:getHealth()) player:say("Gulp.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your health has been refilled.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) @@ -79,14 +79,14 @@ function jeanPierreFood.onUse(player, item, frompos, item2, topos) return true elseif item.itemid == 9081 then item:remove(1) - Creature(cid):addCondition(condition_shield) + player:addCondition(condition_shield) player:say("Chomp.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel less vulnerable.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) return true elseif item.itemid == 9082 then item:remove(1) - Creature(cid):addCondition(condition_ml) + player:addCondition(condition_ml) player:say("Chomp.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel smarter.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) @@ -99,35 +99,35 @@ function jeanPierreFood.onUse(player, item, frompos, item2, topos) return true elseif item.itemid == 9084 then item:remove(1) - Creature(cid):addCondition(condition_melee) + player:addCondition(condition_melee) player:say("Yum.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel stronger.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) return true elseif item.itemid == 9085 then item:remove(1) - Creature(cid):addCondition(condition_speed) + player:addCondition(condition_speed) player:say("Munch.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your speed has been increased.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) return true elseif item.itemid == 9086 then item:remove(1) - Creature(cid):addMana(Creature(cid):getMaxMana() - Creature(cid):getMana()) + player:addMana(Cplayer:getMaxMana() - player:getMana()) player:say("Chomp.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your mana has been refilled.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) return true elseif item.itemid == 9087 then item:remove(1) - Creature(cid):addCondition(condition_dist) + player:addCondition(condition_dist) player:say("Mmmm.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel more focused.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) return true elseif item.itemid == 9088 then item:remove(1) - Creature(cid):addCondition(condition_f) + player:addCondition(condition_f) player:say("Smack.", TALKTYPE_MONSTER_SAY) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You felt fishing inspiration.") player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) @@ -146,7 +146,7 @@ function jeanPierreFood.onUse(player, item, frompos, item2, topos) else player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You take a gulp from the large bowl, but there's still some blackjack in it.") end - Creature(cid):addHealth(getCreatureMaxHealth(cid) - getCreatureHealth(cid)) + player:addHealth(player:getMaxHealth() - player:getHealth()) player:say("Gulp.", TALKTYPE_MONSTER_SAY) player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) return true @@ -155,17 +155,17 @@ function jeanPierreFood.onUse(player, item, frompos, item2, topos) local c = { condition_shield, condition_ml, condition_melee, condition_dist, condition_speed } local r = math.random(1, 4) if r == 1 then - Creature(cid):addCondition(c[math.random(1, #c)]) + player:addCondition(c[math.random(1, #c)]) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel stronger, but you have no idea what was increased.") elseif r == 2 then doSetCreatureLight(cid, 15, 154, 60 * 60 * 1000) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel enlightened.") elseif r == 3 then - Creature(cid):addCondition(condition_i) + player:addCondition(condition_i) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You became invisible.") elseif r == 4 then - Creature(cid):addHealth(getCreatureMaxHealth(cid) - getCreatureHealth(cid)) - Creature(cid):addMana(Creature(cid):getMaxMana() - Creature(cid):getMana()) + player:addHealth(player:getMaxHealth() - player:getHealth()) + player:addMana(player:getMaxMana() - player:getMana()) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your vitality has been restored.") end player:say("Smack.", TALKTYPE_MONSTER_SAY) diff --git a/data-otservbr-global/scripts/actions/other/string_of_mending.lua b/data-otservbr-global/scripts/actions/other/string_of_mending.lua index f2159f2737d..7689c9b05df 100644 --- a/data-otservbr-global/scripts/actions/other/string_of_mending.lua +++ b/data-otservbr-global/scripts/actions/other/string_of_mending.lua @@ -1,46 +1,22 @@ ------------- --- Alternative to no-magic style. --- Description here ----- - ----- string of mending id "20208"----- -local ITEMS = { - [12737] = { -----Broken Ring Id "12737" Ring of ending "20182" - { "ring of ending", 50.50 }, ----- 1.97 es la probabilidad de crear el item - }, -} - local stringOfMending = Action() ----- onUse [opt] --- @param cid Player ID --- @param item Item ID --- @param fromPosition Current Position --- @param[opt] itemEx Item change --- @param[opt] toPosition Nem position -function stringOfMending.onUse(cid, item, fromPosition, itemEx, toPosition) - local cadena = ITEMS[itemEx.itemid] - if cadena == nil then +function stringOfMending.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if not target or target.itemid ~= 12737 then return false end - local iEx = Item(itemEx.uid) - local random, chance = math.random() * 100, 0 - - for i = 1, #cadena do - chance = chance + cadena[i][2] - if random <= chance then - iEx:transform(cadena[i][1]) - iEx:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) - Item(item.uid):remove(1) - return true - end + local random = math.random(100) + if random <= 50 then + target:transform(20182) -- ring of ending + target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) + item:remove(1) + return true end - iEx:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT) - Item(item.uid):remove(1) - iEx:remove() - doCreatureSay(cid, "50% chance, the item was broken.", TALKTYPE_MONSTER_SAY) + target:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT) + item:remove(1) + target:remove() + player:say("50% chance, the item was broken.", TALKTYPE_MONSTER_SAY) return true end diff --git a/data-otservbr-global/scripts/actions/quests/heart_of_destruction/final_lever.lua b/data-otservbr-global/scripts/actions/quests/heart_of_destruction/final_lever.lua index fe1d83724f1..c2d74bbf885 100644 --- a/data-otservbr-global/scripts/actions/quests/heart_of_destruction/final_lever.lua +++ b/data-otservbr-global/scripts/actions/quests/heart_of_destruction/final_lever.lua @@ -69,9 +69,10 @@ local function changeArea() local creatures = tile:getCreatures() if creatures and #creatures > 0 then if theHungerKilled == false then - for _, c in pairs(creatures) do - if isMonster(c) then - c:teleportTo({ x = 32244, y = 31369, z = 14 }) + for _, creature in pairs(creatures) do + local monster = Monster(creature) + if monster then + monster:teleportTo({ x = 32244, y = 31369, z = 14 }) end end else @@ -97,9 +98,10 @@ local function changeArea() local creatures = tile:getCreatures() if creatures and #creatures > 0 then if theDestructionKilled == false then - for _, c in pairs(creatures) do - if isMonster(c) then - c:teleportTo({ x = 32271, y = 31313, z = 14 }) + for _, creature in pairs(creatures) do + local monster = Monster(creature) + if monster then + monster:teleportTo({ x = 32271, y = 31313, z = 14 }) end end else @@ -125,9 +127,10 @@ local function changeArea() local creatures = tile:getCreatures() if creatures and #creatures > 0 then if theRageKilled == false then - for _, c in pairs(creatures) do - if isMonster(c) then - c:teleportTo({ x = 32299, y = 31369, z = 14 }) + for _, creature in pairs(creatures) do + local monster = Monster(creature) + if monster then + monster:teleportTo({ x = 32299, y = 31369, z = 14 }) end end else diff --git a/data-otservbr-global/scripts/actions/quests/heart_of_destruction/sparks_lever.lua b/data-otservbr-global/scripts/actions/quests/heart_of_destruction/sparks_lever.lua index 9a87b0eea72..8ef36379605 100644 --- a/data-otservbr-global/scripts/actions/quests/heart_of_destruction/sparks_lever.lua +++ b/data-otservbr-global/scripts/actions/quests/heart_of_destruction/sparks_lever.lua @@ -120,11 +120,11 @@ function renewSparks() if tile then local creatures = tile:getCreatures() if creatures and #creatures > 0 then - for _, c in pairs(creatures) do - local cPos = c:getPosition() - if isMonster(c) and c:getName() == "Unstable Spark" then - cPos:sendMagicEffect(3) - c:remove() + for _, creature in pairs(creatures) do + local monster = Monster(creature) + if monster and monster:getName() == "Unstable Spark" then + monster:getPosition():sendMagicEffect(3) + monster:remove() end end end diff --git a/data-otservbr-global/scripts/actions/quests/mysterious_ornate/mysterious_metal_egg.lua b/data-otservbr-global/scripts/actions/quests/mysterious_ornate/mysterious_metal_egg.lua index 0486d075dc8..cf26310169d 100644 --- a/data-otservbr-global/scripts/actions/quests/mysterious_ornate/mysterious_metal_egg.lua +++ b/data-otservbr-global/scripts/actions/quests/mysterious_ornate/mysterious_metal_egg.lua @@ -1,7 +1,7 @@ local mysterious = Action() -function mysterious.onUse(cid, item, fromPosition, itemEx, toPosition) - local p = { x = 33672, y = 31884, z = 5 } -- where to tp to 33672, 31884, 5 - doCreatureSay(cid, "This metal egg seems to be locked by a strange mechanism. The time for it to reveal its contents has not yet come.", TALKTYPE_MONSTER_SAY) + +function mysterious.onUse(player, item, fromPosition, target, toPosition, isHotkey) + player:say("This metal egg seems to be locked by a strange mechanism. The time for it to reveal its contents has not yet come.", TALKTYPE_MONSTER_SAY) end mysterious:id(19065, 22739) diff --git a/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/corpse.lua b/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/corpse.lua index a3b4d32341f..d6699dc7fd6 100644 --- a/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/corpse.lua +++ b/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/corpse.lua @@ -1,11 +1,13 @@ local rottinWoodCorpse = Action() -function rottinWoodCorpse.onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey) + +function rottinWoodCorpse.onUse(player, item, fromPosition, target, toPosition, isHotkey) if item.itemid == 12189 then - if (getPlayerStorageValue(cid, Storage.RottinWoodAndMaried.Mission03) == 5) and getPlayerStorageValue(cid, Storage.RottinWoodAndMaried.Corpse) < 4 then - doCreatureSay(cid, "You take no more gold than you actually need and release the merchant who makes away the very second you remove the ropes.", TALKTYPE_MONSTER_SAY) - doPlayerAddItem(cid, 3031, 100) - doRemoveItem(item.uid, 1) - setPlayerStorageValue(cid, Storage.RottinWoodAndMaried.Corpse, getPlayerStorageValue(cid, Storage.RottinWoodAndMaried.Corpse) + 1) + local storageRottinWoodAndMariedCorpse = player:getStorageValue(Storage.RottinWoodAndMaried.Corpse) + if player:getStorageValue(Storage.RottinWoodAndMaried.Mission03) == 5 and storageRottinWoodAndMariedCorpse < 4 then + player:say("You take no more gold than you actually need and release the merchant who makes away the very second you remove the ropes.", TALKTYPE_MONSTER_SAY) + player:addItem(3031, 1) + player:setStorageValue(Storage.RottinWoodAndMaried.Corpse, storageRottinWoodAndMariedCorpse + 1) + item:remove(1) end end return true diff --git a/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/trap.lua b/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/trap.lua index 54703c2a30d..4d324bb7cd2 100644 --- a/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/trap.lua +++ b/data-otservbr-global/scripts/actions/quests/rottin_wood_and_married_men/trap.lua @@ -1,15 +1,17 @@ function removeMonster() doRemoveItem(getTileItemById({ x = 32662, y = 32190, z = 7 }, 2768).uid, 1) - doSendMagicEffect({ x = 32662, y = 32190, z = 7 }, 45) - TOP_LEFT_CORNER = { x = 32651, y = 32178, z = 7, stackpos = 253 } - BOTTOM_RIGHT_CORNER = { x = 32668, y = 32190, z = 7, stackpos = 253 } + Position(32662, 32190, 7):sendMagicEffect(CONST_ME_STONES) + local TOP_LEFT_CORNER = { x = 32651, y = 32178, z = 7 } + local BOTTOM_RIGHT_CORNER = { x = 32668, y = 32190, z = 7 } + for Py = TOP_LEFT_CORNER.y, BOTTOM_RIGHT_CORNER.y do for Px = TOP_LEFT_CORNER.x, BOTTOM_RIGHT_CORNER.x do - creature = getThingfromPos({ x = Px, y = Py, z = 7, stackpos = 253 }) - if isMonster(creature.uid) then - if getCreatureName(creature.uid) == "Travelling Merchant" then - --doRemoveCreature(creature.uid) - doSendMagicEffect({ x = Px, y = Py, z = 7 }, 45) + local tile = Tile(Position({ x = Px, y = Py, z = 7 })) + if tile then + local monster = tile:getTopCreature() + if monster and monster:isMonster() and monster:getName() == "Travelling Merchant" then + -- monster:remove() + monster:getPosition():sendMagicEffect(CONST_ME_STONES) --setPlayerStorageValue(cid, Storage.RottinWoodAndMaried.Trap, -1) end end @@ -19,8 +21,8 @@ function removeMonster() end function removeTrap() - TOP_LEFT_CORNER = { x = 32651, y = 32178, z = 7, stackpos = 253 } - BOTTOM_RIGHT_CORNER = { x = 32668, y = 32190, z = 7, stackpos = 253 } + local TOP_LEFT_CORNER = { x = 32651, y = 32178, z = 7, stackpos = 253 } + local BOTTOM_RIGHT_CORNER = { x = 32668, y = 32190, z = 7, stackpos = 253 } for Py = TOP_LEFT_CORNER.y, BOTTOM_RIGHT_CORNER.y do for Px = TOP_LEFT_CORNER.x, BOTTOM_RIGHT_CORNER.x do local trap = getTileItemById({ x = Px, y = Py, z = 7 }, 12187) @@ -48,7 +50,7 @@ function rottinWoodtrap.onUse(cid, item, fromPosition, itemEx, toPosition, isHot doRemoveItem(item.uid, 1) Game.createItem(12187, 1, toPosition) doTeleportThing(cid, { x = 32660, y = 32193, z = 7 }) - doSendMagicEffect(getCreaturePosition(cid), 45) + Player(cid):getPosition():sendMagicEffect(CONST_ME_STONES) Game.createItem(2768, 1, { x = 32662, y = 32190, z = 7 }) -- small fir tree ----------------------- SUMMON MERCHANT ----------------------------- doSummonCreature("Travelling Merchant", { x = 32656, y = 32182, z = 7 }) diff --git a/data-otservbr-global/scripts/creaturescripts/quests/heart_of_destruction/depolarized_death.lua b/data-otservbr-global/scripts/creaturescripts/quests/heart_of_destruction/depolarized_death.lua index 1b18872fedd..5713ea3d54c 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/heart_of_destruction/depolarized_death.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/heart_of_destruction/depolarized_death.lua @@ -9,10 +9,11 @@ local function setStorage() if tile then local creatures = tile:getCreatures() if creatures and #creatures > 0 then - for _, c in pairs(creatures) do - if isPlayer(c) then - if c:getStorageValue(14322) < 1 then - c:setStorageValue(14322, 1) -- Access to boss Anomaly + for _, creature in pairs(creatures) do + local player = Player(creature) + if player then + if player:getStorageValue(14322) < 1 then + player:setStorageValue(14322, 1) -- Access to boss Anomaly end end end diff --git a/data-otservbr-global/scripts/movements/others/trap.lua b/data-otservbr-global/scripts/movements/others/trap.lua index 155209b7245..09fa89bfc2d 100644 --- a/data-otservbr-global/scripts/movements/others/trap.lua +++ b/data-otservbr-global/scripts/movements/others/trap.lua @@ -14,11 +14,16 @@ function trap.onStepIn(creature, item, position, fromPosition) return true end - if Tile(position):hasFlag(TILESTATE_PROTECTIONZONE) then + local tile = Tile(position) + if not tile then + return true + end + + if tile:hasFlag(TILESTATE_PROTECTIONZONE) then return true end - if Tile(position):getItemCountById(3482) > 1 then + if tile:getItemCountById(3482) > 1 then return true end @@ -30,7 +35,7 @@ function trap.onStepIn(creature, item, position, fromPosition) item:transform(trap.transformTo) end - if item.itemid == 12368 and getCreatureName(creature.uid) == "Starving Wolf" then + if item.itemid == 12368 and creature:getName() == "Starving Wolf" then position:sendMagicEffect(CONST_ME_STUN) creature:remove() Game.createItem(12369, 1, position) diff --git a/data-otservbr-global/scripts/spells/monster/eruption_of_destruction_explosion.lua b/data-otservbr-global/scripts/spells/monster/eruption_of_destruction_explosion.lua index 0f8a01f2102..fbbe4922f14 100644 --- a/data-otservbr-global/scripts/spells/monster/eruption_of_destruction_explosion.lua +++ b/data-otservbr-global/scripts/spells/monster/eruption_of_destruction_explosion.lua @@ -44,16 +44,17 @@ function onTargetTile(creature, pos) end end if #creatureTable ~= nil and #creatureTable > 0 then + local min = 4000 + local max = 6000 for r = 1, #creatureTable do if creatureTable[r] ~= creature then - local min = 4000 - local max = 6000 - local player = Player(creatureTable[r]) - - if isPlayer(creatureTable[r]) == true and table.contains(vocation, player:getVocation():getBaseId()) then - doTargetCombatHealth(creature, creatureTable[r], COMBAT_FIREDAMAGE, -min, -max, CONST_ME_NONE) - elseif isMonster(creatureTable[r]) == true then - doTargetCombatHealth(creature, creatureTable[r], COMBAT_FIREDAMAGE, -min, -max, CONST_ME_NONE) + local creatureInTable = Creature(creatureTable[r]) + if creatureInTable then + if creatureInTable:isPlayer() == true and table.contains(vocation, creatureInTable:getVocation():getBaseId()) then + doTargetCombatHealth(creature, creatureTable[r], COMBAT_FIREDAMAGE, -min, -max, CONST_ME_NONE) + elseif creatureInTable:isMonster() == true then + doTargetCombatHealth(creature, creatureTable[r], COMBAT_FIREDAMAGE, -min, -max, CONST_ME_NONE) + end end end end diff --git a/data-otservbr-global/scripts/spells/monster/gaz'haragoth_death.lua b/data-otservbr-global/scripts/spells/monster/gaz'haragoth_death.lua index c00b15b6038..ea42a9645fd 100644 --- a/data-otservbr-global/scripts/spells/monster/gaz'haragoth_death.lua +++ b/data-otservbr-global/scripts/spells/monster/gaz'haragoth_death.lua @@ -44,16 +44,17 @@ function onTargetTile(creature, pos) end end if #creatureTable ~= nil and #creatureTable > 0 then + local min = 30000 + local max = 30000 for r = 1, #creatureTable do if creatureTable[r] ~= creature then - local min = 30000 - local max = 30000 - local player = Player(creatureTable[r]) - - if isPlayer(creatureTable[r]) == true and table.contains(vocation, player:getVocation():getBaseId()) then - doTargetCombatHealth(creature, creatureTable[r], COMBAT_ENERGYDAMAGE, -min, -max, CONST_ME_NONE) - elseif isMonster(creatureTable[r]) == true then - doTargetCombatHealth(creature, creatureTable[r], COMBAT_ENERGYDAMAGE, -min, -max, CONST_ME_NONE) + local creatureInTable = Creature(creatureTable[r]) + if creatureInTable then + if creatureInTable:isPlayer() and table.contains(vocation, creatureInTable:getVocation():getBaseId()) then + doTargetCombatHealth(creature, creatureTable[r], COMBAT_ENERGYDAMAGE, -min, -max, CONST_ME_NONE) + elseif creatureInTable:isMonster() then + doTargetCombatHealth(creature, creatureTable[r], COMBAT_ENERGYDAMAGE, -min, -max, CONST_ME_NONE) + end end end end diff --git a/data/libs/compat/compat.lua b/data/libs/compat/compat.lua index ca2c88efe1e..4c001defbfd 100644 --- a/data/libs/compat/compat.lua +++ b/data/libs/compat/compat.lua @@ -7,12 +7,6 @@ result.getDataLong = result.getNumber result.getDataString = result.getString result.getDataStream = result.getStream -STACKPOS_GROUND = 0 -STACKPOS_FIRST_ITEM_ABOVE_GROUNDTILE = 1 -STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE = 2 -STACKPOS_THIRD_ITEM_ABOVE_GROUNDTILE = 3 -STACKPOS_FOURTH_ITEM_ABOVE_GROUNDTILE = 4 -STACKPOS_FIFTH_ITEM_ABOVE_GROUNDTILE = 5 STACKPOS_TOP_CREATURE = 253 STACKPOS_TOP_FIELD = 254 STACKPOS_TOP_MOVABLE_ITEM_OR_CREATURE = 255 @@ -21,9 +15,6 @@ THING_TYPE_PLAYER = CREATURETYPE_PLAYER + 1 THING_TYPE_MONSTER = CREATURETYPE_MONSTER + 1 THING_TYPE_NPC = CREATURETYPE_NPC + 1 -COMBAT_POISONDAMAGE = COMBAT_EARTHDAMAGE -CONDITION_EXHAUST = CONDITION_EXHAUST_WEAPON - function pushThing(thing) local t = { uid = 0, itemid = 0, type = 0, actionid = 0 } if thing then @@ -62,7 +53,7 @@ Combat.setCondition = function(...) end setCombatCondition = function(...) - logger.warn("[setCombatCondition] - Function was renamed to addCombatCondition and will be removed in the future") + logger.warn("[setCombatCondition] - Function was renamed to Combat.addCondition and will be removed in the future") Combat.addCondition(...) end @@ -72,94 +63,9 @@ setConditionFormula = Condition.setFormula addDamageCondition = Condition.addDamage addOutfitCondition = Condition.setOutfit -function doCombat(cid, combat, var) - return combat:execute(cid, var) -end - -function isCreature(cid) - return Creature(cid) ~= nil -end - -function isPlayer(cid) - return Player(cid) ~= nil -end - -function isMonster(cid) - return Monster(cid) ~= nil -end - -function isSummon(cid) - return Creature(cid):getMaster() ~= nil -end - -function isNpc(cid) - return Npc(cid) ~= nil -end - -function isItem(uid) - return Item(uid) ~= nil -end - -function isContainer(uid) - return Container(uid) ~= nil -end - -function getCreatureName(cid) - local c = Creature(cid) - return c and c:getName() or false -end - -function getCreatureHealth(cid) - local c = Creature(cid) - return c and c:getHealth() or false -end - -function getCreatureMaxHealth(cid) - local c = Creature(cid) - return c and c:getMaxHealth() or false -end - -function getCreaturePosition(cid) - local c = Creature(cid) - return c and c:getPosition() or false -end - -function getCreatureOutfit(cid) - local c = Creature(cid) - return c and c:getOutfit() or false -end - -function getCreatureSpeed(cid) - local c = Creature(cid) - return c and c:getSpeed() or false -end - -function getCreatureBaseSpeed(cid) - local c = Creature(cid) - return c and c:getBaseSpeed() or false -end - -function getCreatureTarget(cid) - local c = Creature(cid) - if c then - local target = c:getTarget() - return target and target:getId() or 0 - end - return false -end - -function getCreatureMaster(cid) - local c = Creature(cid) - if c then - local master = c:getMaster() - return master and master:getId() or c:getId() - end - return false -end - function getCreatureSummons(cid) local c = Creature(cid) - if c == nil then + if not c then return false end @@ -172,21 +78,6 @@ end getCreaturePos = getCreaturePosition -function doCreatureAddHealth(cid, health) - local c = Creature(cid) - return c and c:addHealth(health) or false -end - -function doRemoveCreature(cid) - local c = Creature(cid) - return c and c:remove() or false -end - -function doCreatureSetLookDir(cid, direction) - local c = Creature(cid) - return c and c:setDirection(direction) or false -end - function doCreatureSay(cid, text, type, ...) local c = Creature(cid) return c and c:say(text, type, ...) or false @@ -560,7 +451,7 @@ function getPlayerGUIDByName(name) local resultId = db.storeQuery("SELECT `id` FROM `players` WHERE `name` = " .. db.escapeString(name)) if resultId ~= false then local guid = Result.getNumber(resultId, "id") - result.free(resultId) + Result.free(resultId) return guid end return 0 @@ -575,7 +466,7 @@ function getAccountNumberByPlayerName(name) local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) if resultId ~= false then local accountId = Result.getNumber(resultId, "account_id") - result.free(resultId) + Result.free(resultId) return accountId end return 0 @@ -1010,7 +901,7 @@ function getGuildId(guildName) end local guildId = Result.getNumber(resultId, "id") - result.free(resultId) + Result.free(resultId) return guildId end diff --git a/data/scripts/talkactions/gm/spy.lua b/data/scripts/talkactions/gm/spy.lua index 4466bc70d6d..7cd5c68ca56 100644 --- a/data/scripts/talkactions/gm/spy.lua +++ b/data/scripts/talkactions/gm/spy.lua @@ -1,4 +1,4 @@ -local function getItemsInContainer(cont, sep) +local function getItemsInContainer(container, sep) local text = "" local tsep = "" local count @@ -6,9 +6,9 @@ local function getItemsInContainer(cont, sep) tsep = tsep .. "-" end tsep = tsep .. ">" - for i = 0, getContainerSize(cont.uid) - 1 do - local item = getContainerItem(cont.uid, i) - if not isContainer(item.uid) then + for slot = 0, container:getSize() - 1 do + local item = container:getItem(slot) + if not item:isContainer() then if item.type > 0 then count = "(" .. item.type .. "x)" else @@ -16,7 +16,7 @@ local function getItemsInContainer(cont, sep) end text = text .. "\n" .. tsep .. ItemType(item.itemid):getName() .. " " .. count else - if getContainerSize(item.uid) > 0 then + if item:getSize() > 0 then text = text .. "\n" .. tsep .. ItemType(item.itemd):getName() text = text .. getItemsInContainer(item, sep + 2) else @@ -42,12 +42,12 @@ function spy.onSay(player, words, param) if target and target:isPlayer() then local slotName = { "Helmet", "Amulet", "Backpack", "Armor", "Right Hand", "Left Hand", "Legs", "Boots", "Ring", "Arrow" } - local text = "Equipments of " .. Creature(target):getName() + local text = "Equipments of " .. target:getName() for i = 1, 10 do text = text .. "\n\n" local item = target:getSlotItem(i) if item and item.itemid > 0 then - if isContainer(item.uid) then + if item:isContainer() then text = text .. slotName[i] .. ": " .. ItemType(item.itemid):getName() .. getItemsInContainer(item, 1) else local count From 4e77c09f4a6c2d9bedf49ca36ba7305b502b055e Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 27 Feb 2024 16:30:26 -0300 Subject: [PATCH 2/2] add warnings --- data/libs/compat/compat.lua | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/data/libs/compat/compat.lua b/data/libs/compat/compat.lua index 4c001defbfd..061d1dbe47e 100644 --- a/data/libs/compat/compat.lua +++ b/data/libs/compat/compat.lua @@ -63,6 +63,142 @@ setConditionFormula = Condition.setFormula addDamageCondition = Condition.addDamage addOutfitCondition = Condition.setOutfit +function doCombat(cid, combat, var) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'doCombat(cid, combat, var)' is outdated. Please use the new format 'combat:execute(cid, var)'. Update needed at: Line {}, Source: {}.", line, source) + return combat:execute(cid, var) +end + +function isCreature(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isCreature(cid)' is outdated. Please use the new format 'Creature(cid)'. Update needed at: Line {}, Source: {}.", line, source) + return Creature(cid) ~= nil +end + +function isPlayer(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isPlayer(cid)' is outdated. Please use the new format 'Player(cid)'. Update needed at: Line {}, Source: {}.", line, source) + return Player(cid) ~= nil +end + +function isMonster(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isMonster(cid)' is outdated. Please use the new format 'Monster(cid)'. Update needed at: Line {}, Source: {}.", line, source) + return Monster(cid) ~= nil +end + +function isSummon(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isSummon(cid)' is outdated. Please use the new format 'c:getMaster()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + return Creature(cid):getMaster() ~= nil +end + +function isNpc(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isNpc(cid)' is outdated. Please use the new format 'Npc(cid)'. Update needed at: Line {}, Source: {}.", line, source) + return Npc(cid) ~= nil +end + +function isItem(uid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isItem(uid)' is outdated. Please use the new format 'Item(uid)'. Update needed at: Line {}, Source: {}.", line, source) + return Item(uid) ~= nil +end + +function isContainer(uid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'isContainer(uid)' is outdated. Please use the new format 'Container(uid)'. Update needed at: Line {}, Source: {}.", line, source) + return Container(uid) ~= nil +end + +function getCreatureName(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureName(cid)' is outdated. Please use the new format 'c:getName()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getName() or false +end + +function getCreatureHealth(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureHealth(cid)' is outdated. Please use the new format 'c:getHealth()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getHealth() or false +end + +function getCreatureMaxHealth(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureMaxHealth(cid)' is outdated. Please use the new format 'c:getMaxHealth()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getMaxHealth() or false +end + +function getCreaturePosition(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreaturePosition(cid)' is outdated. Please use the new format 'c:getPosition()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getPosition() or false +end + +function getCreatureOutfit(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureOutfit(cid)' is outdated. Please use the new format 'c:getOutfit()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getOutfit() or false +end + +function getCreatureSpeed(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureSpeed(cid)' is outdated. Please use the new format 'c:getSpeed()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getSpeed() or false +end + +function getCreatureBaseSpeed(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureBaseSpeed(cid)' is outdated. Please use the new format 'c:getBaseSpeed()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:getBaseSpeed() or false +end + +function getCreatureTarget(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureTarget(cid)' is outdated. Please use the new format 'c:getTarget():getId()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + if c then + local target = c:getTarget() + return target and target:getId() or 0 + end + return false +end + +function getCreatureMaster(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'getCreatureMaster(cid)' is outdated. Please use the new format 'c:getMaster():getId()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + if c then + local master = c:getMaster() + return master and master:getId() or c:getId() + end + return false +end + function getCreatureSummons(cid) local c = Creature(cid) if not c then @@ -78,6 +214,30 @@ end getCreaturePos = getCreaturePosition +function doCreatureAddHealth(cid, health) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'doCreatureAddHealth(cid, health)' is outdated. Please use the new format 'c:addHealth(health)', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:addHealth(health) or false +end + +function doRemoveCreature(cid) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'doRemoveCreature(cid)' is outdated. Please use the new format 'c:remove()', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:remove() or false +end + +function doCreatureSetLookDir(cid, direction) + local line = debug.getinfo(2).currentline + local source = debug.getinfo(2).source:match("@?(.*)") + logger.warn("Deprecation Warning: The function 'doCreatureSetLookDir(cid, direction)' is outdated. Please use the new format 'c:setDirection(direction)', where 'c' refers to a Creature (player or monster). Update needed at: Line {}, Source: {}.", line, source) + local c = Creature(cid) + return c and c:setDirection(direction) or false +end + function doCreatureSay(cid, text, type, ...) local c = Creature(cid) return c and c:say(text, type, ...) or false