V
verdehile95
Guest
hello, I would like it so that after the pet dies, it cannot be recalled until the npc cures it, I also need this npc, here's the code I have
XML:
<movevent event="Equip" itemid="29565" function="onEquipItem" script="A_Pet/Parrot.lua"/>
<movevent event="DeEquip" itemid="29565" function="onDeEquipItem" script="A_Pet/Parrot.lua"/>
LUA:
local summonName = "[Pet] Parrot"
local MAX_LEVEL = 20
local EXP_PER_KILL = 100 -- Ilość doświadczenia zdobywanego za zabicie potwora
function onEquip(player, item, slot, isCheck)
if isCheck then
return true
end
local playerPosition = player:getPosition()
-- Sprawdź, czy gracz jest w strefie ochronnej
if Tile(playerPosition):hasFlag(TILESTATE_PROTECTIONZONE) then
return player:sendCancelMessage("You mustn't be in PZ!") -- wiadomość o błędzie
end
-- Sprawdź, czy Parrot jest już przyzwany
for _, summon in pairs(player:getSummons()) do
if summon:getName() == summonName then
return player:sendCancelMessage("Parrot is already summoned.") -- wiadomość o błędzie
end
end
-- Przyzwij Parrot
local summon = Game.createMonster(summonName, playerPosition)
summon:setMaster(player)
summon:setDropLoot(false)
summon:registerEvent('SummonThink') -- rejestracja zdarzenia myślenia familiara
summon:registerEvent('onAttack') -- rejestracja zdarzenia ataku
summon:registerEvent('onKill') -- rejestracja zdarzenia zabicia
player:say("Go " .. summonName .. "!", TALKTYPE_MONSTER_SAY) -- opcjonalna wiadomość gracza
return true
end
function onDeEquip(creature, item, slot)
-- Zdejmowanie familiara
for _, summon in pairs(creature:getSummons()) do
if summon:getName() == summonName then
summon:getPosition():sendMagicEffect(6) -- efekt magiczny przy znikaniu
summon:remove() -- usuń familiara
end
end
return true
end
-- Funkcja do atakowania potworów
function onAttack(summon, attacker)
if not summon or not attacker then return end
-- Sprawdź, czy atakujący jest potworem
if attacker:isMonster() then
summon:attack(attacker) -- nakaz ataku potwora
end
end
-- Funkcja do zdobywania doświadczenia po zabiciu potwora
function onKill(summon, target)
if not summon or not target then return end
-- Sprawdź, czy celem jest potwór
if target:isMonster() then
local currentExp = summon:getStorageValue("pet_experience") or 0
local currentLevel = summon:getStorageValue("pet_level") or 1
-- Dodaj doświadczenie
currentExp = currentExp + EXP_PER_KILL
summon:setStorageValue("pet_experience", currentExp)
-- Sprawdź, czy osiągnięto nowy poziom
local nextLevelExp = calculateNextLevelExperience(currentLevel)
if currentExp >= nextLevelExp and currentLevel < MAX_LEVEL then
currentLevel = currentLevel + 1
summon:setStorageValue("pet_level", currentLevel)
summon:sendTextMessage(MESSAGE_INFO_DESCR, "Your Parrot leveled up to level " .. currentLevel .. "!")
end
end
end
-- Funkcja do obliczania doświadczenia potrzebnego do osiągnięcia następnego poziomu
function calculateNextLevelExperience(level)
return level * level * 200
end
-- Zdarzenie myślenia familiara
function onThink(summon)
-- Można dodać logikę, np. sprawdzanie zdrowia, itp.
end