• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

simple pet system

  • Thread starter Thread starter verdehile95
  • Start date Start date
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
 
onDeath
creature name = petname
creature:getMaster
master: setstorage -1
onsummon check storage 1
npc set new storage 1 from -1

i think u can write that yourself or get chatgpt to do not rocket science.
 
i add this but don't work
LUA:
local summonName = "[Pet] Parrot"
local MAX_LEVEL = 20
local EXP_PER_KILL = 100 -- Ilość doświadczenia zdobywanego za zabicie potwora
local PET_STORAGE_KEY = 1000 -- Klucz dla stanu posiadania przyzwanego peta

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 pet był już przyzwany (wartość storage)
    if player:getStorageValue(PET_STORAGE_KEY) == 1 then
        return player:sendCancelMessage("Parrot is already summoned.") -- wiadomość o błędzie
    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
    summon:registerEvent('onDeath') -- rejestracja zdarzenia śmierci
    player:setStorageValue(PET_STORAGE_KEY, 1) -- Ustawienie flagi przyzwania
    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
            creature:setStorageValue(PET_STORAGE_KEY, -1) -- Resetuj flagę przyzwania
        end
    end

    return true
end

-- Funkcja do obsługi śmierci familiara
function onDeath(summon, corpse, killer)
    local master = summon:getMaster()
    if master then
        master:setStorageValue(PET_STORAGE_KEY, -1) -- Resetuj flagę przyzwania
        master:sendTextMessage(MESSAGE_INFO_DESCR, "Your Parrot has died!")
    end
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
 
 
Back
Top