• 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+ Mana cost per Second

kubix333

New Member
Joined
Apr 20, 2016
Messages
12
Reaction score
0
TFS 1.3
Hello, I have a problem, so I wanted to make a spell for a knight which would give him more damage, but for every second he would take 5 mana or life. Can somebody explain it to me how can you make such a spell?
And if there is not enough life or mana, the spell turns off.
 
Last edited:
Solution
Now i have new error
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/test.lua:14: attempt to compare nil with number
stack traceback:
        [C]: in function '__le'
        data/spells/scripts/test.lua:14: in function <data/spells/scripts/test.lua:9>
can you test it again with the new changes I've made
edit. after some testing now its working

LUA:
local config = {
    milliseconds = 15000,
    interval = 1000,
    damage = 5,
    mode = 'health',
    minimum = 3000
}

function siphon(player, mode, dmg, minimum, interval, milliseconds, n)
    n = n or 1
    local player = Player(player)
    if player then
        if n * interval >= milliseconds then...
LUA:
local config = {
    milliseconds = 15000,
    interval = 1000,
    damage = 5,
    mode = 'health',
    minimum = 3000
}

function siphon(mode, dmg, minimum, interval, milliseconds, n)
    n = n or 1
    if n * interval >= milliseconds then
        return
    end
    if mode == 'health' then
        local newHealth = player:getHealth() - dmg
        if newHealth < minimum then
            return
        end
        player:addHealth(-dmg)
    elseif mode == 'mana' then
        local newMana = player:getMana() - dmg
        if newMana < minimum then
            return
        end
        player:addMana(-dmg)
    end
    addEvent(siphon, mode, dmg, minimum, interval, n + 1)
end

function onCastSpell(creature, variant)
    siphon(config.mode, config.damage, config.minimum, config.interval, config.milliseconds)
    return true
end

Then you'll have to add a storage value in the spell and register an onHealthChange/onManaChange creaturescript for every creature on the server and multiply damage if the attacker has that storage value (buff active), and remove storage value when <minimum hp/mana or when siphon ends (before return).
 
Last edited:
LUA:
local config = {
    milliseconds = 15000,
    interval = 1000,
    damage = 5,
    mode = 'health',
    minimum = 3000
}

function siphon(mode, dmg, minimum, interval, milliseconds, n)
    n = n or 1
    if n * interval >= milliseconds then
        return
    end
    if mode == 'health' then
        local newHealth = player:getHealth() < dmg
        if newHealth < minimum then
            return
        end
        player:addHealth(-dmg)
    elseif mode == 'mana' then
        local newMana = player:getMana() < dmg
        if newMana < minimum then
            return
        end
        player:addMana(-dmg)
    end
    addEvent(siphon, mode, dmg, minimum, interval, n + 1)
end

function onCastSpell(creature, variant)
    siphon(config.mode, config.damage, config.minimum, config.interval, config.milliseconds)
    return true
end

Then you'll have to add a storage value in the spell and register an onHealthChange/onManaChange creaturescript for every creature on the server and multiply damage if the attacker has that storage value (buff active), and remove storage value when <minimum hp/mana or when siphon ends (before return).
player:getHealth() < dmg -> player:getHealth() - dmg
same with mana, or am I wrong?
 
Tell me what i need add to creaturescript ?
what creature script? the script he provided will do everything you need just check the config.

LUA:
local config = {
    milliseconds = 15000, -- will last 15 seconds
    interval = 1000, -- every 1 second
    damage = 5, -- will do 5 damage
    mode = 'health', -- to your health
    minimum = 3000 -- until you are 3k hp
}
 
Console send me Error:
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/test.lua:onCastSpell
data/spells/scripts/test.lua:16: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/test.lua:16: in function 'siphon'
        data/spells/scripts/test.lua:32: in function <data/spells/scripts/test.lua:31>
 
Console send me Error:
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/test.lua:onCastSpell
data/spells/scripts/test.lua:16: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/test.lua:16: in function 'siphon'
        data/spells/scripts/test.lua:32: in function <data/spells/scripts/test.lua:31>
lmao it its actually wrong, give me a few
test this one.

LUA:
local config = {
    milliseconds = 15000,
    interval = 1000,
    damage = 5,
    mode = 'health',
    minimum = 3000
}

function siphon(p, mode, dmg, minimum, interval, milliseconds, n)
    n = n or 1
    local player = Player(p)
    if not player or n * interval >= milliseconds then
        return
    end
    if mode == 'health' then
        local newHealth = player:getHealth() - dmg
        if newHealth < minimum then
            return
        end
        player:addHealth(-dmg)
    elseif mode == 'mana' then
        local newMana = player:getMana() - dmg
        if newMana < minimum then
            return
        end
        player:addMana(-dmg)
    end
    addEvent(siphon, player, mode, dmg, minimum, interval, n + 1)
end

function onCastSpell(creature, variant)
    if creature:isPlayer() then
        siphon(creature, config.mode, config.damage, config.minimum, config.interval, config.milliseconds)
    end
    return true
end
 
Now i have new error
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/test.lua:14: attempt to compare nil with number
stack traceback:
        [C]: in function '__le'
        data/spells/scripts/test.lua:14: in function <data/spells/scripts/test.lua:9>
 
Now i have new error
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/test.lua:14: attempt to compare nil with number
stack traceback:
        [C]: in function '__le'
        data/spells/scripts/test.lua:14: in function <data/spells/scripts/test.lua:9>
can you test it again with the new changes I've made
edit. after some testing now its working

LUA:
local config = {
    milliseconds = 15000,
    interval = 1000,
    damage = 5,
    mode = 'health',
    minimum = 3000
}

function siphon(player, mode, dmg, minimum, interval, milliseconds, n)
    n = n or 1
    local player = Player(player)
    if player then
        if n * interval >= milliseconds then
            return
        end
        if mode == 'health' then
            local newHealth = player:getHealth() - dmg
            if newHealth < minimum then
                return
            end
            player:addHealth(-dmg)
        elseif mode == 'mana' then
            local newMana = player:getMana() - dmg
            if newMana < minimum then
                return
            end
            player:addMana(-dmg)
        end
        addEvent(siphon, interval, player:getId(), mode, dmg, minimum, interval, milliseconds, n + 1)
    end
end

function onCastSpell(creature, variant)
    if creature:isPlayer() then
        siphon(creature:getId(), config.mode, config.damage, config.minimum, config.interval, config.milliseconds)
    end
    return true
end
 
Last edited:
Solution
Back
Top