• 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+ On health/mana change options?

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
858
Solutions
3
Reaction score
141
Location
Egypt
Hello

I am using tfs 1.3 and i want to use on health/mana change to make some abilities depending on the storage values.
  • Healing bonus
  • Dodge
can someone tell me how they should be ?
 
Solution
The trick is to funnel onManaChange and onHealthChange through another function.
So boosts/reductions work properly regardless if the player has magic shield up or not.

Like this (non revscriptsys example):
Lua:
-- Everything is funnelled through this
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        -- do stuff
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

-- Health
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= 128 then -- Ignore health potions
        -- This is where we push it through statChange...
Can you give example on what you want done?

with more than one word
2 scripts based on (on health/mana change) events one of them gives bonus healing (this bonus healing based on ur storage value) and second one dodge the dmg coming to u depending on percent (this percent based on ur storage value)
I hope i explained it well.
Post automatically merged:

Can you give example on what you want done?

with more than one word
To make it more simple about the bonus healing
Infernum wrote the method here but idk how to write it by the right way
 
Last edited:
The trick is to funnel onManaChange and onHealthChange through another function.
So boosts/reductions work properly regardless if the player has magic shield up or not.

Like this (non revscriptsys example):
Lua:
-- Everything is funnelled through this
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        -- do stuff
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

-- Health
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= 128 then -- Ignore health potions
        -- This is where we push it through statChange
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

-- Mana
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= 64 then -- Ignore mana potions
        -- This is where we push it through statChange
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

So dodges can be done like this:
Lua:
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if creature:getStorageValue(XXXXX) > 0 then
            if math.random(1,100) == 1 then -- 1% dodge
                creature:getPosition():sendMagicEffect(CONST_ME_POFF)
                creature:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You dodged an attack.")
                return false -- this cancels the damage/heal/spell
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

Healing is done by detecting that its type COMBAT_HEALING and buffing the values:
Lua:
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if creature:getStorageValue(XXXXX) > 0 then
            if primaryType = COMBAT_HEALING then -- Healing
                primaryDamage = primaryDamage + ((primaryDamage / 100) * 5) -- 5% healing buff
            end
            if secondaryType = COMBAT_HEALING then -- Healing
                secondaryDamage = secondaryDamage + ((secondaryDamage / 100) * 5) -- 5% healing buff
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

I assume you already know how to register onHealthChange and onManaChange through creaturescripts.xml (or revscriptsys)
XML:
<event type="healthchange" name="CombatModifiersHealth" script="combatmodifiers.lua"/>
<event type="manachange" name="CombatModifiersMana" script="combatmodifiers.lua"/>

And register it on players via login.lua:
Lua:
player:registerEvent("CombatModifiersHealth")
player:registerEvent("CombatModifiersMana")

If your changes affects monsters, you need to register it on each monster too.
I simply use the onSpawn function to do this (just like login.lua does for players):
Lua:
function Monster:onSpawn(position, startup, artificial)
    self:registerEvent("CombatModifiersHealth")
    self:registerEvent("CombatModifiersMana")
    return true
end

Do not use this code as-is, its purely an example.
You need to actively test these sorts of changes as you're creating your new system.
 
Last edited:
Solution
The trick is to funnel onManaChange and onHealthChange through another function.
So boosts/reductions work properly regardless if the player has magic shield up or not.

Like this (non revscriptsys example):
Lua:
-- Everything is funnelled through this
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        -- do stuff
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

-- Health
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= 128 then -- Ignore health potions
        -- This is where we push it through statChange
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

-- Mana
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= 64 then -- Ignore mana potions
        -- This is where we push it through statChange
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

So dodges can be done like this:
Lua:
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if creature:getStorageValue(XXXXX) > 0 then
            if math.random(1,100) == 1 then -- 1% dodge
                creature:getPosition():sendMagicEffect(CONST_ME_POFF)
                creature:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You dodged an attack.")
                return false -- this cancels the damage/heal/spell
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

Healing is done by detecting that its type COMBAT_HEALING and buffing the values:
Lua:
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if creature:getStorageValue(XXXXX) > 0 then
            if primaryType = COMBAT_HEALING then -- Healing
                primaryDamage = primaryDamage + ((primaryDamage / 100) * 5) -- 5% healing buff
            end
            if secondaryType = COMBAT_HEALING then -- Healing
                secondaryDamage = secondaryDamage + ((secondaryDamage / 100) * 5) -- 5% healing buff
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

I assume you already know how to register onHealthChange and onManaChange through creaturescripts.xml
XML:
<event type="healthchange" name="CombatModifiersHealth" script="combatmodifiers.lua"/>
<event type="manachange" name="CombatModifiersMana" script="combatmodifiers.lua"/>

And register it on players via login.lua:
Lua:
player:registerEvent("CombatModifiersHealth")
player:registerEvent("CombatModifiersMana")

If your changes affects monsters, you need to register it on each monster too.
I simply use the onSpawn function to do this (just like login.lua does for players):
Lua:
function Monster:onSpawn(pos, forced)
    self:registerEvent("CombatModifiersHealth")
    self:registerEvent("CombatModifiersMana")
    return true
end

Do not use this code as-is, its purely an example.
You need to actively test these sorts of changes as you're creating your new system.
Thanks for that, u saved me :)
 
Back
Top