• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    Pet System TFs 1.2

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1Pet System TFs 1.2  Empty Pet System TFs 1.2 Miér Jun 08, 2016 5:28 am

    Cheka

    Cheka
    Miembro
    Miembro
    Bueno le traigo un pet system ojala le guste.

    primero vamos  a lib y vamos a crear un archivo llamado.

    Código:
    ('data.lib/pets_lib.lua')

    despues vamos a data/chatchannels/chatchannels.xml y agregamos esto

    Código:
    <channel id="10" name="Pet" script="pet.lua" />

    despues creamos un script y pegamos esto con este nombre

    data/chatchannels/scripts/pet.lua


    ahora abrimos y pegamos esto

    Código:
    function onJoin(player)
       player:petSystemMessage("Type '!petcommands' to see pet commands list.")
       local petUid = player:getPetUid()
       if petUid == 0 then
         player:summonPet( player:getPosition() )

       elseif petUid == -1 then
         player:petSystemMessage("You don't have pet.")
        
       elseif petUid == -2 then
         player:petSystemMessage("Your pet is dead.")
        
       end
       return true
    end

    function onLeave(player)
       player:doRemovePet()
       return true
    end

    function onSpeak(player, type, message)
       return
    end

    ahora en, data/creaturescripts/creaturescripts  pegamos esto

    Código:
    <event type="preparedeath" name="PetDeath" script="pet_creaturescript.lua" />
    <event type="kill" name="PetKill" script="pet_creaturescript.lua" />

    <event type="login" name="PetOwnerLogin" script="pet_owner_creaturescripts.lua" />
    <event type="logout" name="PetOwnerLogout" script="pet_owner_creaturescripts.lua" />
     <event type="preparedeath" name="PetOwnerDeath" script="pet_owner_creaturescripts.lua" />

    ahora creamos los  archivos y abrimos el primero data/creaturescripts/scripts/pet_creaturescript.lua   y pegamos esto

    Código:
    function onPrepareDeath(creature, killer)
     local player = creature:getMaster()
     if player then
     player:setPetUid(-2)
     player:setPetLostHealth(0)
     player:petSystemMessage("Your pet has died.")
     end
     return true
    end

    function onKill(creature, target)
     if target:isMonster() then
     local player = creature:getMaster()
     local experience = (target:getType()):getExperience()
     player:addPetExp(experience)
     end
     return true
    end

    ahora este, data/creaturescripts/scripts/pet_owner_creaturescripts.lua.

    Código:
    function onLogin(player)
     for _, event in pairs({"PetOwnerLogout", "PetOwnerDeath"}) do
     player:registerEvent(event)
     end
     player:openChannel(PETS.CHANNELID)
     return true
    end

    function onLogout(player)
     return player:doRemovePet()
    end

    function onPrepareDeath(creature, killer)
     local petUid = creature:getPetUid()
     local pet = Creature(petUid)
     if pet and pet:isCreature() then
     creature:doRemovePet()
     creature:setPetUid(-2)
     creature:setPetLostHealth(0)
     end
     return true
    end

    ahora vamos a data/talkactions/talkactions.xml y pegamos esto

    Código:
    <talkaction words="!petadd" separator=" " script="pet_add.lua" />
    <talkaction words="!petcatch" script="pet_catch.lua" />
    <talkaction words="!petcommands" script="pet_commands.lua" />
    <talkaction words="!petheal" script="pet_heal.lua" />
    <talkaction words="!petrelease" script="pet_release.lua" />
    <talkaction words="!petrevive" script="pet_revive.lua" />
    <talkaction words="!petinfo" script="pet_status.lua" />

    Ahora creamos los archivos.

    Código:
    data/talkactions/scripts/pet_add.lua

    Código:
    function onSay(player, words, param, channel)
     if player:getGroup():getId() >= 3 then
     if tonumber(param) ~= nil and tonumber(param) <= table.maxn(PETS.IDENTIFICATION) then
     player:doRemovePet()
     player:doResetPet()
     if player:doAddPet(tonumber(param)) then
     player:petSystemMessage("New pet added!")
     else
     player:petSystemMessage("Can't add pet!")
     end
     end
     end
     return false
    end

    ahora el otro

    Código:
    data/talkactions/scripts/pet_catch.lua

    Código:
    function onSay(player, words, param, channel)
     local target = player:getTarget()
     local ropeId = 2120

     if player:getItemCount(ropeId) == 0 then
     player:petSystemMessage('You need rope to catch any monster.')
     return false
     end

     if player:getPetUid() > -1 then
     player:petSystemMessage("You have one pet!")
     return false
     end

     if not target or not target:isMonster() then
     player:petSystemMessage("You can catch only monsters!")
     return false
     end

     local targetMaster = target:getMaster()
     if targetMaster and targetMaster:isPlayer() then
     player:petSystemMessage("You can catch only wild monster.")
     return false
     end

     -- addPetByName
     local mobName = ''
     local mobNumber = ''
     for number_, name_ in ipairs(PETS.IDENTIFICATION) do
     if name_.name == getCreatureName(target) then
     mobName = name_.name
     mobNumber = number_
     break
     end
     end

     if mobName == '' then
     player:petSystemMessage("You can't catch this monster.")
     return false
     end
     -- / addPetByName

     if not player:canGetPet(mobNumber) then
     player:petSystemMessage(PETS.IDENTIFICATION[mobNumber].info)
     return false
     end

     local catchChance = 1 + (1 - target:getHealth() / target:getMaxHealth() ) *100
     if catchChance >= math.random(100) then
     player:doResetPet()
     player:doAddPet(tonumber(mobNumber))
     player:setPetLostHealth(catchChance * player:getPetMaxHealth() / 100 )
     local targetPosition = target:getPosition()
     target:remove()
     targetPosition:sendMagicEffect(CONST_ME_POFF)
     player:petSystemMessage("You catched a " .. string.lower(mobName) .."!")
     else
     player:petSystemMessage("Try one more time!")
     end
     return false
    end

    el 3 archivo.

    Código:
    data/talkactions/scripts/pet_commands.lua

    Código:
    function onSay(player, words, param, channel)
     player:petSystemMessage("!petinfo")
     player:petSystemMessage("!petcatch")
     player:petSystemMessage("!petrevive")
     player:petSystemMessage("!petrelease")
     player:petSystemMessage("!petheal")
     return false
    end

    el 4 archivo.

    Código:
    data/talkactions/scripts/pet_heal.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     if petUid == -1 then
     player:petSystemMessage("You don't have a pet!")

     elseif petUid == -2 then
     player:petSystemMessage("Your pet is death!")

     elseif petUid == 0 then
     local lostHealth = player:getPetLostHealth()
     local soulNeded = PETS.CONFIG.healSoulBase + lostHealth * PETS.CONFIG.healSoulCost

     if lostHealth == 0 then
     player:petSystemMessage("Your don't need healing!")

     elseif player:getSoul() >= soulNeded then
     player:addSoul(-soulNeded)
     player:setPetLostHealth(0)

     player:petSystemMessage("You healed pet ".. lostHealth .. " health, it cost " .. soulNeded .." soul points.")
     else
     player:petSystemMessage("You don't have ".. soulNeded .." soul points!")

     end

     elseif petUid >= 0 then
     local pet = Creature(petUid)

     local lostHealth = pet:getMaxHealth() - pet:getHealth()
     local soulNeded = PETS.CONFIG.healSoulBase + lostHealth * PETS.CONFIG.healSoulCost

     if lostHealth == 0 then
     player:petSystemMessage("Your don't need healing!")

     elseif player:getSoul() >= soulNeded then
     player:addSoul(-soulNeded)
     pet:addHealth(lostHealth)

     player:petSystemMessage("You healed pet ".. lostHealth .. " health, it cost " .. soulNeded .." soul points.")
     else
     player:petSystemMessage("You don't have ".. soulNeded .." soul points!")

     end
     end
     return false
    end

    el 5 archivo .

    Código:
    data/talkactions/scripts/pet_release.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     if petUid >= 0 or petUid == -2 then
     player:doRemovePet()
     player:doResetPet()
     player:petSystemMessage("Pet released!")
     elseif petUid == -1 then
     player:petSystemMessage("You don't have pet!")
     end
     return false
    end

    el 6 archivo.

    Código:
    data/talkactions/scripts/pet_revive.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     if petUid == -1 then
     player:petSystemMessage("You don't have a pet!")

     elseif petUid >= 0 then
     player:petSystemMessage("Your pet is live!")

     elseif petUid == -2 then
     local petLevel = player:getPetLevel()
     local soulNeded = petLevel * PETS.CONFIG.reviveSoulLevelCost + PETS.CONFIG.reviveSoulBaseCost
     soulNeded = soulNeded > 100 and 100 or soulNeded

     if player:getSoul() >= soulNeded then
     player:addSoul(-soulNeded)
     player:setPetUid(0)
     player:setPetLostHealth(0)
     local playerPosition = player:getPosition()
     playerPosition:sendMagicEffect(CONST_ME_HOLYAREA)
     player:petSystemMessage("Your pet is revived!")

     else
     player:petSystemMessage("You don't have enought souul points!")
     end
     end
     return false
    end

    el 7 archivo y ultimo.

    Código:
    data/talkactions/scripts/pet_status.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     local text = ''
     if petUid == nil or petUid == -1 then
     text = "You don't have pet."
     elseif petUid == -2 then
     text = "Your pet is dead."
     else
     local pet = Creature(petUid)
     if pet ~= nil and pet:isCreature() then
     text = "\n Type: "..pet:getName()..
     " \n Health: "..pet:getHealth().."/"..pet:getMaxHealth()..
     " \n Exp: "..player:getPetExperience()..
     "\n Lvl: "..player:getPetLevel()
     else
     text = "Your's pet is offline."
     end
     end
     player:petSystemMessage(text)
     return false
    end

    Ahora creen los mostros.

    Código:
    data/monster/monsters.xml

    Código:
    <monster name="PET_Cat" file="pets/cat.xml"/>
        <monster name="PET_Dog" file="pets/dog.xml"/>
        <monster name="PET_Husky" file="pets/husky.xml"/>
        <monster name="PET_Wolf" file="pets/wolf.xml"/>
        <monster name="PET_War Wolf" file="pets/war wolf.xml"/>
        <monster name="PET_Bear" file="pets/bear.xml"/>
        <monster name="PET_Seagull" file="pets/seagull.xml"/> <!-- -->
        <monster name="PET_Parrot" file="pets/parrot.xml"/>
        <monster name="PET_Chicken" file="pets/chicken.xml"/>
        <monster name="PET_Sheep" file="pets/sheep.xml"/>
        <monster name="PET_Elephant" file="pets/elephant.xml"/>
      
        <monster name="PET_Lion" file="pets/lion.xml"/>
        <monster name="PET_Tiger" file="pets/tiger.xml"/>
        <monster name="PET_Penguin" file="pets/penguin.xml"/> <!-- -->
        <monster name="PET_Mechanic Golem" file="pets/mechanic golem.xml"/>
        <monster name="PET_Undead Slave" file="pets/undead slave.xml"/>
        <monster name="PET_Stronger Husky" file="pets/stronger husky.xml"/>
        <monster name="PET_Black Sheep" file="pets/black sheep.xml"/>
      
        <monster name="PET_Mammoth" file="pets/mammoth.xml"/>
        <monster name="PET_Snake" file="pets/snake.xml"/>
        <monster name="PET_Cobra" file="pets/cobra.xml"/>

    pegan esto en cada mostro que crean con estas caracteristicas.

    Código:
    <?xml version="1.0" encoding="UTF-8"?>
    <monster name="Wolf" nameDescription="a wolf" race="blood" experience="18" speed="195" manacost="0">
     <health now="25" max="25"/>
     <look type="27" corpse="5968"/>
     <targetchange interval="2000" chance="0"/>
     <strategy attack="100" defense="0"/>
     <flags>
     <flag summonable="0"/>
     <flag attackable="1"/>
     <flag hostile="1"/>
     <flag illusionable="1"/>
     <flag convinceable="1"/>
     <flag pushable="1"/>
     <flag canpushitems="0"/>
     <flag canpushcreatures="0"/>
     <flag targetdistance="1"/>
     <flag staticattack="90"/>
     <flag runonhealth="1"/>
     </flags>
     <attacks>
     <attack name="melee" interval="1500" skill="19" attack="22"/>
     </attacks>
     <defenses armor="1" defense="4"/>
     <elements>
     <element earthPercent="10"/>
     <element holyPercent="10"/>
     <element icePercent="-5"/>
     <elemetn deathPercent="-5"/>
     </elements>
    </monster>

    bueno si quieren todos los mostros bajan este archivo.

    Código:
    https://github.com/yrpen/lua-scripts/tree/master/pets_system/monsters/pets

    ya me largo bueno si tienen problema avisan denme me gusta chaolin. aaa otra cosa no probar con el GM con player.

    +2
    slarrr
    Cheka
    6 participantes

    2Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Lun Ago 28, 2017 10:39 pm

    slarrr

    slarrr
    Nuevo Miembro
    Nuevo Miembro
    Justo lo que buscaba , sabras como agregarle slots y que las pets usen magia ?

    +2
    slarrr
    Cheka
    6 participantes

    3Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Miér Ene 10, 2018 6:58 pm

    dementeser

    dementeser
    Miembro
    Miembro
    muchas gracias amigo pero me sale error todo el server es un 10.10 baiack pero sale error todo como le ago

    +2
    slarrr
    Cheka
    6 participantes

    4Pet System TFs 1.2  Empty AYUDA Vie Ene 11, 2019 2:28 am

    Invitado

    Anonymous
    Invitado
    [Tienes que estar registrado y conectado para ver este vínculo]

    +2
    slarrr
    Cheka
    6 participantes

    5Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Vie Ene 11, 2019 4:08 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    jaydeepoin escribió:[Tienes que estar registrado y conectado para ver este vínculo]

    La funcion pets y doremovepet no la reconoce como.una funcion compatible para tfs 1.3

    +2
    slarrr
    Cheka
    6 participantes
    http://www.tibiaface.com

    6Pet System TFs 1.2  Empty ayuda Vie Ene 11, 2019 9:15 pm

    Invitado

    Anonymous
    Invitado
    como puedo areglar este problema???

    +2
    slarrr
    Cheka
    6 participantes

    7Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Dom Ene 13, 2019 11:38 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    jaydeepoin escribió:como puedo areglar este problema???

    tranformacion funciones y adaaptando el sistema para su protocolo de servidor



    Pet System TFs 1.2  YNU5B25
    +2
    slarrr
    Cheka
    6 participantes
    http://www.tibiaface.com

    8Pet System TFs 1.2  Empty [Ayuda] hola Mar Ene 15, 2019 10:09 am

    God Frosty

    God Frosty
    Nuevo Miembro
    Nuevo Miembro
    se desaparesen los pet cuando suvo una escalera. me podrian ayudar con eso porfis,,,

    +2
    slarrr
    Cheka
    6 participantes

    9Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Mar Ene 15, 2019 10:16 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    God Frosty escribió:se desaparesen los pet cuando suvo una escalera. me podrian ayudar con eso porfis,,,

    se desaparece por sale fuera de rango



    Pet System TFs 1.2  YNU5B25
    +2
    slarrr
    Cheka
    6 participantes
    http://www.tibiaface.com

    10Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Mar Ene 15, 2019 11:27 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Cheka escribió:Bueno le traigo un pet system ojala le guste.

    primero vamos  a lib y vamos a crear un archivo llamado.

    Código:
    ('data/lib/pets_lib.lua')

    en data/lib/ creamos un archivo llamado pets_lib.lua y pegamos esto

    Código:

    ---- based on Jordanhenry pet system version 1.77 (changelog)
    ---- edited by hellboy

    -- config
    PETS = {
        PREFIX = "PET_",
        CHANNELID = 10,

        CONFIG = {
            introduction = "You may catch pets using command '!petcatch'. If your pet dies, you have to revive it in order to re-summon it. Some pets have a special requirement in order to catch them, some cannot be catched at all and can only be gotten by evolution. Type 'commands' for a list of available commands.",
            sameSpeed = true,

            healSoulCost = 0.1,
            healSoulBase = 10,

            healOnLevelUp = true,
            standardHpAdd = 5,
            expMultipler = 1,
            shareExpMultipler = 0.3,
            maxLevel = 30,

            reviveSoulBaseCost = 50,
            reviveSoulLevelCost = 0.2
        },

        SYSTEM = {
            EVOLUTION = true,
            MOUNTS = false,
            TELEPORT = true,
            PLAYER_SHARE_EXPERIENCE = false,
       DUELS_ONLY = false
        },

        IDENTIFICATION = {
            [1] = {
                name = "Cat",
                health = 100,
                evolve = {
                    to = 3,
                    at = 10
                },
                check = true
            },
            [2] = {
                name = "Dog",
                health = 100,
                evolve = {
                    to = 4,
                    at = 10
                },
                check = true
            },
            [3] = {
                name = "Tiger",
                health = 300,
                check = false,
                info = "Evolves from Cat."
            },
            [4] = {
                name = "Lion",
                health = 300,
                mountId = 40,
                check = false,
                info = "Evolves from Dog."
            },
            [5] = {
                name = "Husky",
                health = 150,
                check = function(player) return player:getPremiumDays() > 0 end,
                info = "Requires a premium account."
            },
            [6] = {
                name = "Wolf",
                health = 200,
                evolve = {
                    to = 7,
                    at = 4
                },
                check = function(player) return player:getLevel() >= 10 end,
                info = "Requires level 10."
            },
            [7] = {
                name = "War Wolf",
                health = 500,
                evolve = {
                    to = 8,
                    at = 55
                },
                check = false,
                info = "Evolves from Wolf."
            },
            [8] = {
                name = "Werewolf",
                health = 1000,
                check = false,
                info = "Evolves from War Wolf."
            },
            [9] = {
                name = "Bear",
                health = 300,
                mountId = 3,
                check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
                info = "Only available to druids above level 10."
            },
            [10] = {
                name = "Panda",
                health = 300,
                mountId = 19,
                check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
                info = "Only available to druids above level 10."
            },
            [11] = {
                name = "Chicken",
                health = 50,
                check = true
            },
            [12] = {
                name = "Sheep",
                health = 50,
                check = true
            },
            [13] = {
                name = "Seagull",
                health = 100,
                check = function(player) return player:getPremiumDays() > 0 end,
                info = "Requires a premium account."
            },
            [14] = {
                name = "Parrot",
                health = 100,
                check = function(player) return player:getPremiumDays() > 0 end,
                info = "Requires a premium account."
            },
            [15] = {
                name = "Penguin",
                health = 100,
                check = function(player) return player:getPremiumDays() > 0 end,
                info = "Requires a premium account."
            },
            [16] = {
                name = "Elephant",
                health = 300,
                check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 10 end,
                contain = 5,
                info = "Only available to Premium accounts above level 10."
            },
            [17] = {
                name = "Dragon Hatchling",
                health = 300,
                evolve = {
                    to = 18,
                    at = 20
                },
                check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 25 and player:isSorcerer() end,
                info = "Only available to Premium Sorcerers above level 25."
            },
            [18] = {
                name = "Dragon",
                health = 1000,
                check = false,
                info = "Evolves from Dragon Hatchling."
            }
        },

        STORAGE = {
            TYPE = 10000,
            UID = 10001,
            LOSTHEALTH = 10002,
            MAXHEALTH = 10003,
            EXPERIENCE = 10004,
            LEVEL = 10005
        },

        CONSTANS = {
            STATUS_OK = 0,
            STATUS_DOESNT_EXIST = -1,
            STATUS_DEAD = -2,
            STATUS_MOUNT = -3
        }
    }

    --/ config
    function Player.petSystemMessage(self, txt, talkType)
        local playerId = self:getId()
        talkType = (talkType == nil) and TALKTYPE_CHANNEL_O or talkType

        local function eventMessage(playerId, text, talkType)
            local player = Player(playerId)
            if not player then
                return false
            end
            player:sendChannelMessage('[PET-SYSTEM]', txt, talkType, PETS.CHANNELID)
        end
        addEvent(eventMessage, 150, playerId, text, talkType)

        --self:sendChannelMessage('[PET-SYSTEM]', txt, ((talkType == nil) and TALKTYPE_CHANNEL_O or talkType), PETS.CHANNELID)
        --self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '[PET-SYSTEM] '..txt)
        return true
    end

    -- get
    function Player.getPetExperience(self)
        return self:getStorageValue(PETS.STORAGE.EXPERIENCE)
    end

    function Player.getPetLevel(self)
        return self:getStorageValue(PETS.STORAGE.LEVEL)
    end

    function Player.getPetType(self)
        return self:getStorageValue(PETS.STORAGE.TYPE)
    end

    function Player.getPetUid(self)
        return self:getStorageValue(PETS.STORAGE.UID)
    end

    function Player.getPetMaxHealth(self)
        return self:getStorageValue(PETS.STORAGE.MAXHEALTH)
    end

    function Player.getPetLostHealth(self)
        return self:getStorageValue(PETS.STORAGE.LOSTHEALTH)
    end

    function Player.getPetMountId(self)
        local petType = self:getPetType()
        local mountId = PETS.IDENTIFICATION[petType].mountId
        return mountId
    end

    -- set
    function Player.setPetExperience(self, experience)
        return self:setStorageValue(PETS.STORAGE.EXPERIENCE, experience)
    end

    function Player.setPetLevel(self, petLevel)
        return self:setStorageValue(PETS.STORAGE.LEVEL, petLevel)
    end

    function Player.setPetType(self, petType)
        return self:setStorageValue(PETS.STORAGE.TYPE, petType)
    end

    function Player.setPetUid(self, petUid)
        return self:setStorageValue(PETS.STORAGE.UID, petUid)
    end

    function Player.setPetMaxHealth(self, health)
        return self:setStorageValue(PETS.STORAGE.MAXHEALTH, health)
    end

    function Player.setPetLostHealth(self, health)
        return self:setStorageValue(PETS.STORAGE.LOSTHEALTH, health)
    end

    -- other
    function Player.doAddPet(self, petType)
        local pet = Creature(self:getStorageValue(PETS.STORAGE.UID))
        if pet then
            return false
        end

        self:setPetUid(PETS.CONSTANS.STATUS_OK)
        self:setPetExperience(0)
        self:setPetLevel(1)
        self:setPetType(petType)

        self:setPetMaxHealth(PETS.IDENTIFICATION[petType].health)
        self:setPetLostHealth(0)

        if PETS.SYSTEM.MOUNTS then
            local mountId = self:getPetMountId()
            if mountId ~= nil and mountId ~= 0 then
                self:addMount(mountId)
            end
        end
        return true
    end

    function Player.doResetPet(self)
        for _, i in pairs(PETS.STORAGE) do
            self:setStorageValue(i, -1)
        end
        return true
    end

    function Player.doRemovePet(self)
        local petUid = self:getPetUid()
        local pet = Creature(petUid)

        if not pet or not pet:isCreature() then
            return true
        end
        local maxHealth = pet:getMaxHealth()

        self:setPetMaxHealth(maxHealth)
        self:setPetLostHealth(maxHealth - pet:getHealth() )
        self:setPetUid(PETS.CONSTANS.STATUS_OK)

        pet:remove()

        if PETS.SYSTEM.MOUNTS then
            local mountId = self:getPetMountId()
            if mountId ~= nil then
                self:addMount(mountId)
            end
        end
        return true
    end

    function Player.doKillPet(self, removeBody)
        if removeBody then
            self:doRemovePet()
        end
        self:setPetUid(PETS.CONSTANS.STATUS_DEAD)
        self:setPetLostHealth(0)

        if PETS.SYSTEM.MOUNTS then
            local mountId = self:getPetMountId()
            if mountId ~= nil then
                self:removeMount(mountId)
            end
        end
        return true
    end

    function Player.summonPet(self, position)
        local petUid = self:getPetUid()
        local pet = Creature(petUid)
        if pet and pet:isCreature() then
            return false
        end

        if (Tile(position)):hasFlag(TILESTATE_PROTECTIONZONE) then
          return false
        end

        if PETS.SYSTEM.MOUNTS then
            local mountId = self:getPetMountId()
            local currentMount = self:getOutfit()['lookMount']
            if mountId ~= nil and currentMount ~= nil and currentMount ~= 0 and currentMount == mountId then
                return false
            end
        end

        local pet = Game.createMonster(PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name), position)
        if pet then
            position:sendMagicEffect(CONST_ME_TELEPORT)
            pet:setMaster(self)
            local maxHealth = self:getPetMaxHealth()
            pet:setMaxHealth(maxHealth)
            pet:addHealth(maxHealth - pet:getHealth() - self:getPetLostHealth() )
            self:setPetUid( pet:getId() )
            pet:setSkull(SKULL_GREEN)
            pet:changeSpeed(PETS.CONFIG.sameSpeed and (self:getBaseSpeed() - pet:getBaseSpeed()) or 0)

            for _, eventName in pairs({"PetDeath", "PetKill"}) do
                pet:registerEvent(eventName)
            end

            if PETS.SYSTEM.TELEPORT then
                pet:registerEvent("PetTeleport")
            end

            if PETS.SYSTEM.DUELS_ONLY then
                pet:registerEvent("PetHealthChange")
            end

            if PETS.SYSTEM.MOUNTS then
                local mountId = self:getPetMountId()
                if mountId ~= nil then
                    self:removeMount(mountId)
                end
            end

            return pet
        end
        return false
    end

    function getExpNeeded(level)
        return ( (50 *level^3) -(150 *level^2) +(400 *level) )/3 *PETS.CONFIG.expMultipler
    end

    function Player.addPetExp(self, amount)
        local pet = Creature(petUid)
        if not pet then
            return false
        end

        if self:getPetLevel() >= PETS.CONFIG.maxLevel then
            return false
        end

        local totalExp = self:getPetExperience() + amount
        self:setPetExperience(totalExp)
        local petLevel, petType, petUid = self:getPetLevel(), self:getPetType(), self:getPetUid()

        if totalExp >= getExpNeeded(petLevel + 1) then
            pet:setMaxHealth(pet:getMaxHealth() + (PETS.IDENTIFICATION[petType].hpAdd or PETS.CONFIG.standardHpAdd))
            self:setPetLevel(petLevel +1)
            self:petSystemMessage("Your pet "..PETS.IDENTIFICATION[petType].name.." has advanced to level "..(petLevel +1)..".")

            if PETS.CONFIG.healOnLevelUp then
                pet:addHealth( pet:getMaxHealth() )
            end

            if PETS.SYSTEM.EVOLUTION and (PETS.IDENTIFICATION[petType]).evolve and ((PETS.IDENTIFICATION[petType]).evolve.at <= (petLevel +1)) then
                local position = pet:getPosition()
                self:doRemovePet()
                self:setPetType( (PETS.IDENTIFICATION[petType]).evolve.to)
                self:setPetMaxHealth( (PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).health )
                self:setPetLostHealth(0)
                self:petSystemMessage("Your pet "..(PETS.IDENTIFICATION[petType]).name.." has evolved to a "..((PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).name)..".")
                self:summonPet(position)
            end

            -- save max hp fix
            self:setPetMaxHealth(pet:getMaxHealth())
        end

        return true
    end

    function Player.canGetPet(self, petId)
        if self:getGroup():getId() >= 3 then
            return true
        end

        if type(PETS.IDENTIFICATION[petId].check) == "function" then
            return PETS.IDENTIFICATION[petId].check(self)
        end
        return PETS.IDENTIFICATION[petId].check
    end

    -- is Pet
    function Player.isPet(self)
        return false
    end

    function Npc.isPet(self)
        return false
    end

    function Monster.isPet(self)
        if self:isSummon() then
            local owner = self:getMaster()
            if owner:isPlayer() and owner:getPetUid() == self:getId() then
                return true
            end
        end
        return false
    end


    despues vamos a data/chatchannels/chatchannels.xml y agregamos esto

    Código:
    <channel id="10" name="Pet" script="pets_channels.lua" />

    despues creamos un script y pegamos esto con este nombre

    data/chatchannels/scripts/pets_channels.lua


    ahora abrimos y pegamos esto

    Código:

    function onJoin(player)
        player:petSystemMessage("Type '!petcommands' to see pet commands list.")
        local petUid = player:getPetUid()
        if petUid == PETS.CONSTANS.STATUS_OK then
            player:summonPet( player:getPosition() )

        elseif petUid == PETS.CONSTANS.STATUS_DOESNT_EXIST then
            player:petSystemMessage("You don't have a pet.")
           
        elseif petUid == PETS.CONSTANS.STATUS_DEAD then
            player:petSystemMessage("Your pet is dead.")
           
        elseif petUid == PETS.CONSTANS.STATUS_MOUNT then
            player:petSystemMessage("Your pet is a mount.")
            player:setPetUid(PETS.CONSTANS.OK)
           
        end
        return true
    end

    function onLeave(player)
        player:doRemovePet()
        return true
    end

    function onSpeak(player, type, message)
        return type
    end


    ahora en, data/creaturescripts/creaturescripts  pegamos esto

    Código:
    <event type="preparedeath" name="PetDeath" script="pet_creaturescript.lua" />
    <event type="kill" name="PetKill" script="pet_creaturescript.lua" />

    <event type="login" name="PetOwnerLogin" script="pet_owner_creaturescripts.lua" />
    <event type="logout" name="PetOwnerLogout" script="pet_owner_creaturescripts.lua" />
     <event type="preparedeath" name="PetOwnerDeath" script="pet_owner_creaturescripts.lua" />

    ahora creamos los  archivos y abrimos el primero data/creaturescripts/scripts/pet_creaturescript.lua   y pegamos esto

    Código:
    function onPrepareDeath(creature, killer)
     local player = creature:getMaster()
     if player then
     player:setPetUid(-2)
     player:setPetLostHealth(0)
     player:petSystemMessage("Your pet has died.")
     end
     return true
    end

    function onKill(creature, target)
     if target:isMonster() then
     local player = creature:getMaster()
     local experience = (target:getType()):getExperience()
     player:addPetExp(experience)
     end
     return true
    end

    ahora este, data/creaturescripts/scripts/pet_owner_creaturescripts.lua.

    Código:
    function onLogin(player)
     for _, event in pairs({"PetOwnerLogout", "PetOwnerDeath"}) do
     player:registerEvent(event)
     end
     player:openChannel(PETS.CHANNELID)
     return true
    end

    function onLogout(player)
     return player:doRemovePet()
    end

    function onPrepareDeath(creature, killer)
     local petUid = creature:getPetUid()
     local pet = Creature(petUid)
     if pet and pet:isCreature() then
     creature:doRemovePet()
     creature:setPetUid(-2)
     creature:setPetLostHealth(0)
     end
     return true
    end

    ahora vamos a data/talkactions/talkactions.xml y pegamos esto

    Código:
    <talkaction words="!petadd" separator=" " script="pet_add.lua" />
    <talkaction words="!petcatch" script="pet_catch.lua" />
    <talkaction words="!petcommands" script="pet_commands.lua" />
    <talkaction words="!petheal" script="pet_heal.lua" />
    <talkaction words="!petrelease" script="pet_release.lua" />
    <talkaction words="!petrevive" script="pet_revive.lua" />
    <talkaction words="!petinfo" script="pet_status.lua" />

    Ahora creamos los archivos.

    Código:
    data/talkactions/scripts/pet_add.lua

    Código:
    function onSay(player, words, param, channel)
     if player:getGroup():getId() >= 3 then
     if tonumber(param) ~= nil and tonumber(param) <= table.maxn(PETS.IDENTIFICATION) then
     player:doRemovePet()
     player:doResetPet()
     if player:doAddPet(tonumber(param)) then
     player:petSystemMessage("New pet added!")
     else
     player:petSystemMessage("Can't add pet!")
     end
     end
     end
     return false
    end

    ahora el otro

    Código:
    data/talkactions/scripts/pet_catch.lua

    Código:
    function onSay(player, words, param, channel)
     local target = player:getTarget()
     local ropeId = 2120

     if player:getItemCount(ropeId) == 0 then
     player:petSystemMessage('You need rope to catch any monster.')
     return false
     end

     if player:getPetUid() > -1 then
     player:petSystemMessage("You have one pet!")
     return false
     end

     if not target or not target:isMonster() then
     player:petSystemMessage("You can catch only monsters!")
     return false
     end

     local targetMaster = target:getMaster()
     if targetMaster and targetMaster:isPlayer() then
     player:petSystemMessage("You can catch only wild monster.")
     return false
     end

     -- addPetByName
     local mobName = ''
     local mobNumber = ''
     for number_, name_ in ipairs(PETS.IDENTIFICATION) do
     if name_.name == getCreatureName(target) then
     mobName = name_.name
     mobNumber = number_
     break
     end
     end

     if mobName == '' then
     player:petSystemMessage("You can't catch this monster.")
     return false
     end
     -- / addPetByName

     if not player:canGetPet(mobNumber) then
     player:petSystemMessage(PETS.IDENTIFICATION[mobNumber].info)
     return false
     end

     local catchChance = 1 + (1 - target:getHealth() / target:getMaxHealth() ) *100
     if catchChance >= math.random(100) then
     player:doResetPet()
     player:doAddPet(tonumber(mobNumber))
     player:setPetLostHealth(catchChance * player:getPetMaxHealth() / 100 )
     local targetPosition = target:getPosition()
     target:remove()
     targetPosition:sendMagicEffect(CONST_ME_POFF)
     player:petSystemMessage("You catched a " .. string.lower(mobName) .."!")
     else
     player:petSystemMessage("Try one more time!")
     end
     return false
    end

    el 3 archivo.

    Código:
    data/talkactions/scripts/pet_commands.lua

    Código:
    function onSay(player, words, param, channel)
     player:petSystemMessage("!petinfo")
     player:petSystemMessage("!petcatch")
     player:petSystemMessage("!petrevive")
     player:petSystemMessage("!petrelease")
     player:petSystemMessage("!petheal")
     return false
    end

    el 4 archivo.

    Código:
    data/talkactions/scripts/pet_heal.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     if petUid == -1 then
     player:petSystemMessage("You don't have a pet!")

     elseif petUid == -2 then
     player:petSystemMessage("Your pet is death!")

     elseif petUid == 0 then
     local lostHealth = player:getPetLostHealth()
     local soulNeded = PETS.CONFIG.healSoulBase + lostHealth * PETS.CONFIG.healSoulCost

     if lostHealth == 0 then
     player:petSystemMessage("Your don't need healing!")

     elseif player:getSoul() >= soulNeded then
     player:addSoul(-soulNeded)
     player:setPetLostHealth(0)

     player:petSystemMessage("You healed pet ".. lostHealth .. " health, it cost " .. soulNeded .." soul points.")
     else
     player:petSystemMessage("You don't have ".. soulNeded .." soul points!")

     end

     elseif petUid >= 0 then
     local pet = Creature(petUid)

     local lostHealth = pet:getMaxHealth() - pet:getHealth()
     local soulNeded = PETS.CONFIG.healSoulBase + lostHealth * PETS.CONFIG.healSoulCost

     if lostHealth == 0 then
     player:petSystemMessage("Your don't need healing!")

     elseif player:getSoul() >= soulNeded then
     player:addSoul(-soulNeded)
     pet:addHealth(lostHealth)

     player:petSystemMessage("You healed pet ".. lostHealth .. " health, it cost " .. soulNeded .." soul points.")
     else
     player:petSystemMessage("You don't have ".. soulNeded .." soul points!")

     end
     end
     return false
    end

    el 5 archivo .

    Código:
    data/talkactions/scripts/pet_release.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     if petUid >= 0 or petUid == -2 then
     player:doRemovePet()
     player:doResetPet()
     player:petSystemMessage("Pet released!")
     elseif petUid == -1 then
     player:petSystemMessage("You don't have pet!")
     end
     return false
    end

    el 6 archivo.

    Código:
    data/talkactions/scripts/pet_revive.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     if petUid == -1 then
     player:petSystemMessage("You don't have a pet!")

     elseif petUid >= 0 then
     player:petSystemMessage("Your pet is live!")

     elseif petUid == -2 then
     local petLevel = player:getPetLevel()
     local soulNeded = petLevel * PETS.CONFIG.reviveSoulLevelCost + PETS.CONFIG.reviveSoulBaseCost
     soulNeded = soulNeded > 100 and 100 or soulNeded

     if player:getSoul() >= soulNeded then
     player:addSoul(-soulNeded)
     player:setPetUid(0)
     player:setPetLostHealth(0)
     local playerPosition = player:getPosition()
     playerPosition:sendMagicEffect(CONST_ME_HOLYAREA)
     player:petSystemMessage("Your pet is revived!")

     else
     player:petSystemMessage("You don't have enought souul points!")
     end
     end
     return false
    end

    el 7 archivo y ultimo.

    Código:
    data/talkactions/scripts/pet_status.lua

    Código:
    function onSay(player, words, param, channel)
     local petUid = player:getPetUid()
     local text = ''
     if petUid == nil or petUid == -1 then
     text = "You don't have pet."
     elseif petUid == -2 then
     text = "Your pet is dead."
     else
     local pet = Creature(petUid)
     if pet ~= nil and pet:isCreature() then
     text = "\n Type: "..pet:getName()..
     " \n Health: "..pet:getHealth().."/"..pet:getMaxHealth()..
     " \n Exp: "..player:getPetExperience()..
     "\n Lvl: "..player:getPetLevel()
     else
     text = "Your's pet is offline."
     end
     end
     player:petSystemMessage(text)
     return false
    end

    Ahora creen los mostros.

    Código:
    data/monster/monsters.xml

    Código:
    <monster name="PET_Cat" file="pets/cat.xml"/>
        <monster name="PET_Dog" file="pets/dog.xml"/>
        <monster name="PET_Husky" file="pets/husky.xml"/>
        <monster name="PET_Wolf" file="pets/wolf.xml"/>
        <monster name="PET_War Wolf" file="pets/war wolf.xml"/>
        <monster name="PET_Bear" file="pets/bear.xml"/>
        <monster name="PET_Seagull" file="pets/seagull.xml"/> <!-- -->
        <monster name="PET_Parrot" file="pets/parrot.xml"/>
        <monster name="PET_Chicken" file="pets/chicken.xml"/>
        <monster name="PET_Sheep" file="pets/sheep.xml"/>
        <monster name="PET_Elephant" file="pets/elephant.xml"/>
      
        <monster name="PET_Lion" file="pets/lion.xml"/>
        <monster name="PET_Tiger" file="pets/tiger.xml"/>
        <monster name="PET_Penguin" file="pets/penguin.xml"/> <!-- -->
        <monster name="PET_Mechanic Golem" file="pets/mechanic golem.xml"/>
        <monster name="PET_Undead Slave" file="pets/undead slave.xml"/>
        <monster name="PET_Stronger Husky" file="pets/stronger husky.xml"/>
        <monster name="PET_Black Sheep" file="pets/black sheep.xml"/>
      
        <monster name="PET_Mammoth" file="pets/mammoth.xml"/>
        <monster name="PET_Snake" file="pets/snake.xml"/>
        <monster name="PET_Cobra" file="pets/cobra.xml"/>

    pegan esto en cada mostro que crean con estas caracteristicas.

    Código:
    <?xml version="1.0" encoding="UTF-8"?>
    <monster name="Wolf" nameDescription="a wolf" race="blood" experience="18" speed="195" manacost="0">
     <health now="25" max="25"/>
     <look type="27" corpse="5968"/>
     <targetchange interval="2000" chance="0"/>
     <strategy attack="100" defense="0"/>
     <flags>
     <flag summonable="0"/>
     <flag attackable="1"/>
     <flag hostile="1"/>
     <flag illusionable="1"/>
     <flag convinceable="1"/>
     <flag pushable="1"/>
     <flag canpushitems="0"/>
     <flag canpushcreatures="0"/>
     <flag targetdistance="1"/>
     <flag staticattack="90"/>
     <flag runonhealth="1"/>
     </flags>
     <attacks>
     <attack name="melee" interval="1500" skill="19" attack="22"/>
     </attacks>
     <defenses armor="1" defense="4"/>
     <elements>
     <element earthPercent="10"/>
     <element holyPercent="10"/>
     <element icePercent="-5"/>
     <elemetn deathPercent="-5"/>
     </elements>
    </monster>


    data/events/events.xml

    <event class="Creature" method="onTargetCombat" enabled="1" />
    <event class="Player" method="onGainExperience" enabled="1" />

    add content of player_on_gain_experience.lua and pet_look.lua into data/events/scripts/player.lua
    add content of creature_on_target_combat.lua into data/events/scripts/creature.lua

    bueno si quieren todos los mostros bajan este archivo.

    Código:
    https://github.com/yrpen/lua-scripts/tree/master/pets_system/monsters/pets

    ya me largo bueno si tienen problema avisan denme me gusta chaolin. aaa otra cosa no probar con el GM con player.


    link del sistema: [Tienes que estar registrado y conectado para ver este vínculo]



    Pet System TFs 1.2  YNU5B25
    +2
    slarrr
    Cheka
    6 participantes
    http://www.tibiaface.com

    11Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Dom Mayo 05, 2019 3:00 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Código:

    <event type="preparedeath" name="PetDeath" script="pet_creaturescript.lua" />  ----> necesita estar registrado en login.lua
            <event type="kill" name="PetKill" script="pet_creaturescript.lua" /> ----> necesita estar registrado en login.lua

            <event type="login" name="PetOwnerLogin" script="pet_owner_creaturescripts.lua" /> ----> necesita estar registrado en login.lua
            <event type="logout" name="PetOwnerLogout" script="pet_owner_creaturescripts.lua" /> ----> necesita estar registrado en login.lua
            <event type="preparedeath" name="PetOwnerDeath" script="pet_owner_creaturescripts.lua" /> ----> necesita estar registrado en login.lua



    Pet System TFs 1.2  YNU5B25
    +2
    slarrr
    Cheka
    6 participantes
    http://www.tibiaface.com

    12Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Lun Mayo 06, 2019 9:44 am

    Fokme

    Fokme
    Nuevo Miembro
    Nuevo Miembro
    Lua Script Error: [CreatureScript Interface]
    data/creaturescripts/scripts/pet_creaturescript.lua:onKill
    data/creaturescripts/scripts/pet_creaturescript.lua:15: attempt to index local 'player' (a nil value)


    Además, la mascota no se convoca cuando se abre el canal después de capturar una mascota. No hay error de consola tampoco. TFS 1.3


    login.lua
    player:registerEvent("PetKill")
    player:registerEvent("PetOwnerLogin")
    player:registerEvent("PetOwnerLogout")
    player:registerEvent("PetOwnerDeath")
    player:registerEvent("PetDeath")

    +2
    slarrr
    Cheka
    6 participantes

    13Pet System TFs 1.2  Empty Re: Pet System TFs 1.2 Mar Mayo 07, 2019 7:53 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Fokme escribió:Lua Script Error: [CreatureScript Interface]
    data/creaturescripts/scripts/pet_creaturescript.lua:onKill
    data/creaturescripts/scripts/pet_creaturescript.lua:15: attempt to index local 'player' (a nil value)


    Además, la mascota no se convoca cuando se abre el canal después de capturar una mascota. No hay error de consola tampoco. TFS 1.3


    login.lua
    player:registerEvent("PetKill")
    player:registerEvent("PetOwnerLogin")
    player:registerEvent("PetOwnerLogout")
    player:registerEvent("PetOwnerDeath")
    player:registerEvent("PetDeath")

    no te preocupes amigo que este fin de semanavoy a revisar bien este sistema lamentablemente el trabajo no me deja hora de respiro solo fin de semana puedo ver con calma estos scipts gigantescos



    Pet System TFs 1.2  YNU5B25
    +2
    slarrr
    Cheka
    6 participantes
    http://www.tibiaface.com

    Contenido patrocinado


    +2
    slarrr
    Cheka
    6 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).