• 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 heal master error console

Michcol94

Member
Joined
Sep 2, 2021
Messages
105
Reaction score
18
I use tfs 1.5 by nekiro 8.6
monster/
Lua:
<monster name="[Pet] Dende" nameDescription="a dende" race="blood" experience="80" speed="750" manacost="255">
    <health now="10000" max="10000" />
    <look type="590" corpse="0" />
    <targetchange interval="4000" chance="0" />
    <flags>
        <!-- Flagi petów -->
        <flag attackable="1" />
        <flag hostile="0" />
        <flag illusionable="1" />
        <flag convinceable="1" />
        <flag pushable="1" />
        <flag canpushitems="0" />
        <flag canpushcreatures="0" />
        <flag targetdistance="1" />
        <flag canwalkonenergy="0" />
        <flag canwalkonfire="0" />
        <flag canwalkonpoison="0" />
    </flags>
    <script>
        <event type="think" name="HealScript" script="heal.lua" />
    </script>
</monster>

creaturescript/
Code:
local healSpell = 10 -- ID zaklęcia "heal"
local healPercentage = 25 -- Procent maksymalnego zdrowia mistrza, który zostanie przywrócony

function onThink(creature)
    if creature:isMonster() and creature:getName() == "[Pet] Dende" then
        local master = creature:getMaster()
        if master then
            local masterMaxHealth = master:getMaxHealth()
            local masterHealth = master:getHealth()
            if masterHealth < masterMaxHealth then
                local healAmount = math.floor(masterMaxHealth * healPercentage / 100)
                creature:say("Dende used heal friends on " .. master:getName() .. "!", TALKTYPE_MONSTER_SAY)
                master:addHealth(healAmount)
                creature:saySpell(healSpell)
            end
        end
    end
    return true
end
creaturescript.xml
Code:
<event type="think" name="HealScript" script="heal.lua" />

movements/
Code:
local summonName = "[Pet] Dende"

function onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end
 
    local playerSummons = player:getSummons(summonName)
    local playerPosition = player:getPosition()
    local summonsCountGamakichi = 0

  
     if Tile(playerPosition):hasFlag(TILESTATE_PROTECTIONZONE) then
        return player:sendCancelMessage("You mustn't be in PZ!")-- error msg
    end
 
    for _,player in pairs(playerSummons) do
        if player:getName() == summonName then
            summonsCountGamakichi = 1
        end
    end
 
    if summonsCountGamakichi == 0 then
        local summon = Game.createMonster(summonName, playerPosition)
        summon:setMaster(player)
        summon:setDropLoot(false)
        summon:registerEvent('SummonThink')
        -- what will player say upon summoning: player:say("Go " .. summonName .. "!", TALKTYPE_MONSTER_SAY)
    else
        player:sendCancelMessage("Dende is already summoned.")-- error msg
    end
 
    return true
end

function onDeEquip(creature, item, slot)

local creatureSummons = creature:getSummons(summonName)
local creaturePosition = creature:getPosition()
 
for _,creature in pairs(creatureSummons) do
    if creature:getName() == summonName  then
        creature:getPosition():sendMagicEffect(6) -- 3 = poff, 6 = explosion
        doRemoveCreature(creature:getId())
    else
        -- nothing happens
    end
end

return true
end
movements.xml
Code:
<movevent event="Equip" itemid="2124" slot="ring" script="A_Pet/Dende.lua" />
<movevent event="DeEquip" itemid="2124" slot="ring" script="A_Pet/Dende.lua" />

the script works, it heals the player by pet, but generates an error:

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/heal.lua:eek:nThink
data/creaturescripts/scripts/heal.lua:14: attempt to call method 'saySpell' (a nil value)
stack traceback:
[C]: in function 'saySpell'
data/creaturescripts/scripts/heal.lua:14: in function <data/creaturescripts/scripts/heal.lua:4>


Other attempts to write such a treatment script have been unsuccessful.
Anyone got any ideas?
 
Back
Top