• 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+ [TFS 1.3] What could be wrong with this onHealthChange?

Demnish

Tibian Hero
Joined
Sep 28, 2011
Messages
402
Solutions
2
Reaction score
65
Location
Sweden
Trying to add a boss monster which gets healed instead of damaged when it has a certain outfit:
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker then
        if creature:getOutfit() == 9 then
            primaryDamage = -primaryDamage
            secondaryDamage = -secondaryDamage
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

I've added the script to the creature, but it won't execute correctly, it does work however since if I make an error and attack the monster I get a console output
.
Something is wonky with creature:getOutfit() but I have no idea what.
9 is the lookType it should heal on.
 
Thank you, it worked. :D
However I can't seem to use these:
Lua:
primaryDamage = -primaryDamage
secondaryDamage = -secondaryDamage
Any ideas on an alternative? Because - doesn't work.

EDIT: Never mind, I solved it.
This works until a better method has been found:
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker then
        if creature:getOutfit().lookType == 9 then
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            creature:addHealth(-primaryDamage)
            creature:addHealth(-secondaryDamage)
            return true
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Last edited:
The damage will be negative either way, there's no need for you to manually send the damage yourself, all you have to do is use the return values.
 
But having "-primaryDamage" for example won't make the damage positive aka heal.
So I'm quite at a loss on how to best implement this script. 🤔
 
You're a legend mate, thank you. :D
Didn't know primary/secondaryType worked that way.
Do you know any good place I can read up on stuff like this?

Here is the script for those that wants it:
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker then
        if creature:getOutfit().lookType == 37 then
            primaryType = COMBAT_HEALING
            secondaryType = COMBAT_HEALING
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Last edited:
Back
Top