• 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.2] Pet system

It would be easier to edit:

data>events>creature.lua

Lua:
function Creature:onTargetCombat(target)
    return true
end
 
exp on death fixed correctly.
DUELS_ONLY working, but not correcly. I did like this.
Code:
if PETS and PETS.SYSTEM.DUELS_ONLY then
        if self:isPet() and target:isPlayer() or target:isPet() and self:isPlayer() or self:isMonster() and target:isPet() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
end
This makes the pet ONLY attackable by other pets, BUT monsters keep targeting the pet, so its inmune and it can tank forever.. (i made this because a demon with big aoe for exemple was killing my pets all the time), any way to make pets untargeteable by monsters? (i thought RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE was doing exactly that). Also pets attack what players attack, if a player cant attack pets, pet vs pet is not possible.

- If pet should get exp for killing monster, then it also should get damage from them. So I won't fix it.
- I don't know how make pets untargetable by monsters.
- I'll fix player targeting pet.

I tried to use something like this instead:
I used this creaturescript and set it to cats.
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
       
        if attacker and attacker:isPlayer()  and (origin == ORIGIN_MELEE) or (origin == ORIGIN_MELEE) or (origin == ORIGIN_MELEE) then
            return 0, primaryType, 0, secondaryType
        end
       
            return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Now even if player attacks pet, no damage is done. Problem is, for some reason, pets doesnt do any damage to pets either. :/

Try this:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
       
        if attacker and attacker:isPlayer() then
            return 0, primaryType, 0, secondaryType
        end
       
            return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
- If pet should get exp for killing monster, then it also should get damage from them. So I won't fix it.
- I don't know how make pets untargetable by monsters.
- I'll fix player targeting pet.



Try this:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
      
        if attacker and attacker:isPlayer() then
            return 0, primaryType, 0, secondaryType
        end
      
            return primaryDamage, primaryType, secondaryDamage, secondaryType
end

-Same result, no pet damage.
-fixed pet getting targeted by monsters. (Just set hostile = "0") on monsters.
So i think the way to go is with creature.lua on events.
Code:
if PETS and PETS.SYSTEM.DUELS_ONLY then
        if self:isPet() and target:isPlayer() or target:isPet() and self:isPlayer() or self:isMonster() and target:isPet()  or self:isPet() and target:isMonster() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
end
But this part need to be changed to something that allows players to target pets without damaging them.
 
-Same result, no pet damage.
-fixed pet getting targeted by monsters. (Just set hostile = "0") on monsters.
So i think the way to go is with creature.lua on events.
Code:
if PETS and PETS.SYSTEM.DUELS_ONLY then
        if self:isPet() and target:isPlayer() or target:isPet() and self:isPlayer() or self:isMonster() and target:isPet()  or self:isPet() and target:isMonster() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
end
But this part need to be changed to something that allows players to target pets without damaging them.

Check updated script on github, with onHealthChange.
Changes:
pet duels fix · yrpen/lua-scripts@b11ef64 · GitHub
 
Hello @hellboy ..
Sometimes i get this error, not always tho, and player exp suddently turn to 1x.
BdvrfGb.png

I've been unable to solve it.
 
@hellboy Im having troubles to adding events, how it should be?? I have this on my creature.lua and player.lua and getting the error
Lua:
data/events/scripts/player.lua:93: <'eof'>expected near 'end'
onTargetCombat

Lua:
function Creature:onTargetCombat(target)
target:registerEvent("UpgradeSystemHealth")
target:registerEvent("UpgradeSystemDeath")
    return RETURNVALUE_NOERROR
    end

onGainExperience

Lua:
function Player:onGainExperience(source, exp, rawExp)
  if PETS and PETS.SYSTEM.PLAYER_SHARE_EXPERIENCE and self:getPetUid() > 0 and source and source:isMonster() then
    local pet_exp = exp * PETS.CONFIG.shareExpMultipler
    self:addPetExp(pet_exp)
  end
    if not source or source:isPlayer() then
        exp = us_onGainExperience(self, source, exp, rawExp)
        return exp
    end
end

onLook

Lua:
function Player:onLook(thing, position, distance)
    if thing:isCreature() and thing:isMonster() then
        local owner = thing:getMaster()

        if owner ~= nil and owner:isPlayer() and thing:getId() == owner:getPetUid() then
            local playerName = (owner:getId() == self:getId()) and "you" or owner:getName()
            local description = "You see a ".. thing:getName() ..", it's belongs to "..playerName.."."

            if self:getGroup():getAccess() or playerName == 'you' then
                description = string.format("%s\nHealth: %d / %d", description, thing:getHealth(), thing:getMaxHealth()) .. "."
                description = string.format("%s\nLvl: %d, Exp: %d", description, owner:getPetLevel(), owner:getPetExperience()) .. "."

                if PETS.SYSTEM.MOUNTS then
                    local mountId = self:getPetMountId()
                    if mountId ~= nil and mountId ~= 0 then
                        description = string.format("%s\nHe can serve as mount.", description)
                    end
                end
            end

            if self:getGroup():getAccess() then
                local position = thing:getPosition()
                description = string.format("%s\nPosition: %d, %d, %d", description, position.x, position.y, position.z)
            end
            self:sendTextMessage(MESSAGE_INFO_DESCR, description)
            return false
        end
    end
tpLook(self, position)
        -- shop onLook -
if (thing:isCreature() and thing:isNpc() and distance <= minDist) then
       self:say("hi", TALKTYPE_PRIVATE_PN, false, thing)
       self:say("trade", TALKTYPE_PRIVATE_PN, false, thing)
       return false 
   end
       ----------------------------
    local description = "You see " .. thing:getDescription(distance) description = onItemUpgradeLook(self, thing, position, distance, description)
        -- this is the code you will add to Player:onLook --------------------------------------------------
    description = ( Tile(thing:getPosition()):hasFlag(TILESTATE_MAGICFIELD) and thing:hasAttribute(ITEM_ATTRIBUTE_OWNER) ) and (description.."\nCasted by "..Creature(thing:getAttribute(ITEM_ATTRIBUTE_OWNER)):getName() .. ".")  or description
    ----------------------------------------------------------------------------------------------------------------
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:isPlayer() and thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

Im using other scripts I need to know how to organize it, thanks in advance!!
 
@hellboy Im having troubles to adding events, how it should be?? I have this on my creature.lua and player.lua and getting the error
Lua:
data/events/scripts/player.lua:93: <'eof'>expected near 'end'
onTargetCombat

Lua:
function Creature:onTargetCombat(target)
target:registerEvent("UpgradeSystemHealth")
target:registerEvent("UpgradeSystemDeath")
    return RETURNVALUE_NOERROR
    end

onGainExperience

Lua:
function Player:onGainExperience(source, exp, rawExp)
  if PETS and PETS.SYSTEM.PLAYER_SHARE_EXPERIENCE and self:getPetUid() > 0 and source and source:isMonster() then
    local pet_exp = exp * PETS.CONFIG.shareExpMultipler
    self:addPetExp(pet_exp)
  end
    if not source or source:isPlayer() then
        exp = us_onGainExperience(self, source, exp, rawExp)
        return exp
    end
end

onLook

Lua:
function Player:onLook(thing, position, distance)
    if thing:isCreature() and thing:isMonster() then
        local owner = thing:getMaster()

        if owner ~= nil and owner:isPlayer() and thing:getId() == owner:getPetUid() then
            local playerName = (owner:getId() == self:getId()) and "you" or owner:getName()
            local description = "You see a ".. thing:getName() ..", it's belongs to "..playerName.."."

            if self:getGroup():getAccess() or playerName == 'you' then
                description = string.format("%s\nHealth: %d / %d", description, thing:getHealth(), thing:getMaxHealth()) .. "."
                description = string.format("%s\nLvl: %d, Exp: %d", description, owner:getPetLevel(), owner:getPetExperience()) .. "."

                if PETS.SYSTEM.MOUNTS then
                    local mountId = self:getPetMountId()
                    if mountId ~= nil and mountId ~= 0 then
                        description = string.format("%s\nHe can serve as mount.", description)
                    end
                end
            end

            if self:getGroup():getAccess() then
                local position = thing:getPosition()
                description = string.format("%s\nPosition: %d, %d, %d", description, position.x, position.y, position.z)
            end
            self:sendTextMessage(MESSAGE_INFO_DESCR, description)
            return false
        end
    end
tpLook(self, position)
        -- shop onLook -
if (thing:isCreature() and thing:isNpc() and distance <= minDist) then
       self:say("hi", TALKTYPE_PRIVATE_PN, false, thing)
       self:say("trade", TALKTYPE_PRIVATE_PN, false, thing)
       return false
   end
       ----------------------------
    local description = "You see " .. thing:getDescription(distance) description = onItemUpgradeLook(self, thing, position, distance, description)
        -- this is the code you will add to Player:onLook --------------------------------------------------
    description = ( Tile(thing:getPosition()):hasFlag(TILESTATE_MAGICFIELD) and thing:hasAttribute(ITEM_ATTRIBUTE_OWNER) ) and (description.."\nCasted by "..Creature(thing:getAttribute(ITEM_ATTRIBUTE_OWNER)):getName() .. ".")  or description
    ----------------------------------------------------------------------------------------------------------------
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:isPlayer() and thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

Im using other scripts I need to know how to organize it, thanks in advance!!

Try to replace
Code:
    end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

with (remove one "end")
Code:
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
 
pet is offline but still alive, can't see him on map, and he isn't summon when join/leave chat any help? tfs 1.2
 
i catch pet, that's ok, i summon him by join the chat (it work correct now) BUT if my summon is online, and i RELOG, my summon disappears and i can't summon him again, need to catch other..
yup tfs 1.2 tibia 10.98View attachment 43411

Take a look at last script version from git:

And show me:
data/creaturescripts/creaturescripts.xml
data/creaturescripts/scripts/
pet_owner_creaturescripts.lua
 
Back
Top