• 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.3] Buff your damage with a spell for 5 sec

Marko999x

999x era
Premium User
Joined
Dec 14, 2017
Messages
2,856
Solutions
82
Reaction score
1,958
Location
Germany
Buff Spell for 5secs :D

data/creaturescripts.xml:
Lua:
<event type="healthchange" name="BuffSystemO" script="BuffSystemO"/>

data/creaturescripts/scripts/BuffSystemO
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature or not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
   
    if attacker:getStorageValue(7373) == 1 then
        primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
        secondaryType = secondaryType + (secondaryType * 50 / 100)
    end
    return primaryDamage, primaryType, primaryDamage, secondaryType
end

login.lua
Lua:
player:registerEvent("BuffSystemO")
Lua:
player:setStorageValue(7373, 0)

data/scripts/BatMan
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 1)

local function castSpellTo(cid, variant)
    local player = Player(cid)
    if player then
        player:setStorageValue(7373, 0)
    end
end

local buff = Spell(SPELL_INSTANT)

function buff.onCastSpell(creature, variant)
    creature:setStorageValue(7373, 1)
    local cid = creature:getId()
        addEvent(castSpellTo, 5000, cid, variant)
    return true
end

buff:name("exura buff")
buff:words("exura buff")
buff:group("support")
buff:vocation("Knight", "master sorecerer")
buff:id(1)
buff:cooldown(1000)
buff:level(200)
buff:manaPercent(1)
buff:blockWalls(true)
buff:register()
 
Buff Spell for 5secs :D

data/creaturescripts.xml:
Lua:
<event type="healthchange" name="BuffSystemO" script="BuffSystemO"/>

data/creaturescripts/scripts/BuffSystemO
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature or not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
  
    if attacker:getStorageValue(7373) == 1 then
        primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
        secondaryType = secondaryType + (secondaryType * 50 / 100)
    end
    return primaryDamage, primaryType, primaryDamage, secondaryType
end

login.lua
Lua:
player:registerEvent("BuffSystemO")
Lua:
player:setStorageValue(7373, 0)

data/scripts/BatMan
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 1)

local function castSpellTo(cid, variant)
    local player = Player(cid)
    if player then
        player:setStorageValue(7373, 0)
    end
end

local buff = Spell(SPELL_INSTANT)

function buff.onCastSpell(creature, variant)
    creature:setStorageValue(7373, 1)
    local cid = creature:getId()
        addEvent(castSpellTo, 5000, cid, variant)
    return true
end

buff:name("exura buff")
buff:words("exura buff")
buff:group("support")
buff:vocation("Knight", "master sorecerer")
buff:id(1)
buff:cooldown(1000)
buff:level(200)
buff:manaPercent(1)
buff:blockWalls(true)
buff:register()
is it possible tfs 1.2 8.0? mine has no folder/script, could adapt, thank you
 
Nice contribution!
But it is worth mentioning that the buff will only apply to post-mitigation damage.
Eg. if your initial hit will be lower than mitigation threshold (armor, shielding, resistances) your damage wont be doubled and you will end up dealing no damage.

There are other suggestions that you might want to apply.
a) using numbers as storage value is bleh, declare a variable for it to label it at least
b) in perfect world, your code should indicate a happy path of execution, and indents should indicate caveats in which you check fe: if the input is correct,
or if player has a storage value.
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature or not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker:getStorageValue(7373) == 1 then
        primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
        secondaryType = secondaryType + (secondaryType * 50 / 100)
    end

    return primaryDamage, primaryType, primaryDamage, secondaryType
end
This onHealthChange callback suppose to increase the attackers damage, right?
So happy path is the case in which we end up increasing the attackers damage.
Lua:
local damageBuffStorage = 7373
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature or not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker:getStorageValue(damageBuffStorage) ~= 1 then
       return primaryDamage, primaryType, primaryDamage, secondaryType
    end

    return primaryDamage + (primaryDamage * 50 / 100), primaryType, 
        secondaryType + (secondaryType * 50 / 100), secondaryType
end
 
Last edited:
Nice contribution!
But it is worth mentioning that the buff will only apply to post-mitigation damage.
Eg. if your initial hit will be lower than mitigation threshold (armor, shielding, resistances) your damage wont be doubled and you will end up dealing no damage.

There are other suggestions that you might want to apply.
a) using numbers as storage value is bleh, declare a variable for it to label it at least
b) in perfect world, your code should indicate a happy path of execution, and indents should indicate caveats in which you check fe: if the input is correct,
or if player has a storage value.
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature or not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker:getStorageValue(7373) == 1 then
        primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
        secondaryType = secondaryType + (secondaryType * 50 / 100)
    end

    return primaryDamage, primaryType, primaryDamage, secondaryType
end
This onHealthChange callback suppose to increase the attackers damage, right?
So happy path is the case in which we end up increasing the attackers damage.
Lua:
local damageBuffStorage = 7373
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature or not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker:getStorageValue(damageBuffStorage) ~= 1 then
       return primaryDamage, primaryType, primaryDamage, secondaryType
    end

    primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
    secondaryType = secondaryType + (secondaryType * 50 / 100)
end

Hmm im not sure if I understand correctly, but if player actually has
Lua:
damageBuffStorage == 1
we will (as we want) increase his damage:
Lua:
primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
secondaryType = secondaryType + (secondaryType * 50 / 100)

But we will not return anything? Is it 100% correct?
 
Hmm im not sure if I understand correctly, but if player actually has
Lua:
damageBuffStorage == 1
we will (as we want) increase his damage:
Lua:
primaryDamage = primaryDamage + (primaryDamage * 50 / 100)
secondaryType = secondaryType + (secondaryType * 50 / 100)

But we will not return anything? Is it 100% correct?
You are right, we should return the damage and the types at the end of the function. I corrected my suggestion.
 
Back
Top