• 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!

TFS 1.X+ Pet system is not working right

sagelantropus

New Member
Joined
Sep 28, 2018
Messages
17
Reaction score
0
when I climb the stairs the pet stays down and is not transported towards me.

I'm using tfs 1.3

I leave the code:

Code:
local petNames = {
    [1] = 'thundergiant',
    [2] = 'grovebeast',
    [3] = 'emberwing',
    [4] = 'skullfrost'
}

local STORAGE_PET = Storage.PetSummon

function onLogin(cid)
    local player = Player(cid)

    local vocationid = player:getVocation():getId()
    local pet
    local petTimeLeft = player:getStorageValue(STORAGE_PET) - player:getLastLogout()

    if petTimeLeft > 0 then
        if vocationid == 5 then
            pet = "thundergiant"
        elseif vocationid == 6 then
            pet = "grovebeast"
        elseif vocationid == 7 then
            pet = "emberwing"
        elseif vocationid == 8 then
            pet = "skullfrost"
        end
    end

    if pet then
        position = player:getPosition()
        summonpet = Game.createMonster(pet, position, true, false, cid)
        player:addSummon(summonpet)
        player:setStorageValue(STORAGE_PET, os.time() + petTimeLeft)
        summonpet:registerEvent('petdeath')
        position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end


function onThink(cid, interval, item, position, lastPosition, fromPosition, toPosition)
    local player = Player(cid)

    if player and player:getStorageValue(STORAGE_PET) <= os.time() and player:getStorageValue(STORAGE_PET) > 0 then
        doRemoveCreature (getCreatureSummons(cid)[1])
        player:setStorageValue(STORAGE_PET,0)
    end
    return true
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local player = creature:getMaster()
    if not player then
        return false
    end

    if table.contains(petNames,creature:getName():lower()) then
        player:setStorageValue(STORAGE_PET, os.time()) --imeddiately expire creature

        -- maybe we need to remove creature from the game manually?
        -- doRemoveCreature (getCreatureSummons(player)[1])
    end

    return true
end
 
Solution
hi, it did not work, the console does not give me error

Creaturescripts:

Code:
<event type="think" name="teleportpet" script="teleportpet.lua" />

teleportpet.lua:

Code:
function onThink(interval)

  for _, player in ipairs(Game.getPlayers()) do
    local player_position = player:getPosition()
    if not player_position:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
      local summons = player:getSummons()
      if #summons > 0 then
        for i = 1, #summons do
          if summons[i]:getPosition().z ~= player_position.z then
            summons[i]:teleportTo(player_position)
          end
        end
      end
    end
  end
  return true
end

pet.lua:

Code:
--By Igor Labanca
--Fixes by Leu (jlcvp)

local petNames = {...
hi, it did not work, the console does not give me error

Creaturescripts:

Code:
<event type="think" name="teleportpet" script="teleportpet.lua" />

teleportpet.lua:

Code:
function onThink(interval)

  for _, player in ipairs(Game.getPlayers()) do
    local player_position = player:getPosition()
    if not player_position:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
      local summons = player:getSummons()
      if #summons > 0 then
        for i = 1, #summons do
          if summons[i]:getPosition().z ~= player_position.z then
            summons[i]:teleportTo(player_position)
          end
        end
      end
    end
  end
  return true
end

pet.lua:

Code:
--By Igor Labanca
--Fixes by Leu (jlcvp)

local petNames = {
    [1] = 'thundergiant',
    [2] = 'grovebeast',
    [3] = 'emberwing',
    [4] = 'skullfrost'
}

local STORAGE_PET = Storage.PetSummon

function onLogin(cid)
    local player = Player(cid)

    local vocationid = player:getVocation():getId()
    local pet
    local petTimeLeft = player:getStorageValue(STORAGE_PET) - player:getLastLogout()

    if petTimeLeft > 0 then
        if vocationid == 5 then
            pet = "thundergiant"
        elseif vocationid == 6 then
            pet = "grovebeast"
        elseif vocationid == 7 then
            pet = "emberwing"
        elseif vocationid == 8 then
            pet = "skullfrost"
        end
    end

    if pet then
        position = player:getPosition()
                summonpet = Game.createMonster(pet, position, true, false, cid)
        player:addSummon(summonpet)
        player:setStorageValue(STORAGE_PET, os.time() + petTimeLeft)
        summonpet:registerEvent('teleportpet')
        summonpet:registerEvent('petdeath')
        position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end


function onThink(cid, interval, item, position, lastPosition, fromPosition, toPosition)
    local player = Player(cid)

    if player and player:getStorageValue(STORAGE_PET) <= os.time() and player:getStorageValue(STORAGE_PET) > 0 then
        doRemoveCreature (getCreatureSummons(cid)[1])
        player:setStorageValue(STORAGE_PET,0)
    end
    return true
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local player = creature:getMaster()
    if not player then
        return false
    end

    if table.contains(petNames,creature:getName():lower()) then
        player:setStorageValue(STORAGE_PET, os.time()) --imeddiately expire creature

        -- maybe we need to remove creature from the game manually?
        -- doRemoveCreature (getCreatureSummons(player)[1])
    end

    return true
end
 
Last edited:
hi, it did not work, the console does not give me error

Creaturescripts:

Code:
<event type="think" name="teleportpet" script="teleportpet.lua" />

teleportpet.lua:

Code:
function onThink(interval)

  for _, player in ipairs(Game.getPlayers()) do
    local player_position = player:getPosition()
    if not player_position:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
      local summons = player:getSummons()
      if #summons > 0 then
        for i = 1, #summons do
          if summons[i]:getPosition().z ~= player_position.z then
            summons[i]:teleportTo(player_position)
          end
        end
      end
    end
  end
  return true
end

pet.lua:

Code:
--By Igor Labanca
--Fixes by Leu (jlcvp)

local petNames = {
    [1] = 'thundergiant',
    [2] = 'grovebeast',
    [3] = 'emberwing',
    [4] = 'skullfrost'
}

local STORAGE_PET = Storage.PetSummon

function onLogin(cid)
    local player = Player(cid)

    local vocationid = player:getVocation():getId()
    local pet
    local petTimeLeft = player:getStorageValue(STORAGE_PET) - player:getLastLogout()

    if petTimeLeft > 0 then
        if vocationid == 5 then
            pet = "thundergiant"
        elseif vocationid == 6 then
            pet = "grovebeast"
        elseif vocationid == 7 then
            pet = "emberwing"
        elseif vocationid == 8 then
            pet = "skullfrost"
        end
    end

    if pet then
        position = player:getPosition()
                summonpet = Game.createMonster(pet, position, true, false, cid)
        player:addSummon(summonpet)
        player:setStorageValue(STORAGE_PET, os.time() + petTimeLeft)
        summonpet:registerEvent('teleportpet')
        summonpet:registerEvent('petdeath')
        position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end


function onThink(cid, interval, item, position, lastPosition, fromPosition, toPosition)
    local player = Player(cid)

    if player and player:getStorageValue(STORAGE_PET) <= os.time() and player:getStorageValue(STORAGE_PET) > 0 then
        doRemoveCreature (getCreatureSummons(cid)[1])
        player:setStorageValue(STORAGE_PET,0)
    end
    return true
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local player = creature:getMaster()
    if not player then
        return false
    end

    if table.contains(petNames,creature:getName():lower()) then
        player:setStorageValue(STORAGE_PET, os.time()) --imeddiately expire creature

        -- maybe we need to remove creature from the game manually?
        -- doRemoveCreature (getCreatureSummons(player)[1])
    end

    return true
end
This event is a global event that will work for all players, i think you should change it to a creaturescript and register when player summon the pet.
Sorry, i told you to do as creaturescript. My bad.
 
Solution
This event is a global event that will work for all players, i think you should change it to a creaturescript and register when player summon the pet.
Sorry, i told you to do as creaturescript. My bad.
Quick question the The pet.lua do i registers this in Talkaction to make it work?
 
Back
Top