• 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+ The use of the Spell consumes more mana according to the player's level.

Piifafa

Member
Joined
Apr 16, 2023
Messages
67
Reaction score
16
I would like to know how I can increase the mana consumption of certain spells according to the player's level. I can't think of any easy alternative for this.

I would like it to be like the example, after level 200, the use of the magic increases its mana cost according to a rule or something similar, every 10 levels or a small percentage for each level gained.


Lua:
    <instant name="Ultimate Explosion" words="exevo gran mas vis" maglv="40" mana="800" aggressive="1"  selftarget="1" needlearn="0" script="spells/ultimate explosion.lua">
        <vocation name="Sorcerer" />
        <vocation name="Master Sorcerer" />
    </instant>


Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

function onGetFormulaValues(player, level, maglevel)
    local base = 250
    local variation = 50
    
    local formula = 3.0 * maglevel + (2 * level)
    
    local min = (formula * (base - variation)) / 100
    local max = (formula * (base + variation)) / 100
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
Solution
Lua:
local config = {
    manaLevel = 200, -- Additional mana will be consumed every 10 levels after this level
    manaIncrease = 100, -- How much more mana the spell requires for every 10 levels
    defaultMana = 800, -- How much mana the spell normally needs (in spells.xml)
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

function onGetFormulaValues(player, level, maglevel)
    local base = 250
    local variation = 50
  
    local formula = 3.0 * maglevel + (2 * level)
  
    local min...
Lua:
local config = {
    manaLevel = 200, -- Additional mana will be consumed every 10 levels after this level
    manaIncrease = 100, -- How much more mana the spell requires for every 10 levels
    defaultMana = 800, -- How much mana the spell normally needs (in spells.xml)
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

function onGetFormulaValues(player, level, maglevel)
    local base = 250
    local variation = 50
  
    local formula = 3.0 * maglevel + (2 * level)
  
    local min = (formula * (base - variation)) / 100
    local max = (formula * (base + variation)) / 100
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    local playerLevel = creature:getLevel()
    if playerLevel >= config.manaLevel then
        local removeMana = math.floor((playerLevel - config.manaLevel) / 10) * config.manaIncrease
        if creature:getMana() < (removeMana + config.defaultMana) then
            creature:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
            return false
        end
        creature:addMana(-removeMana)
    end
    return combat:execute(creature, variant)
end
 
Solution
I ended up doing it a different way but following your logic!
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

function onGetFormulaValues(player, level, maglevel)
    local base = 250
    local variation = 50
    
    local formula = 3.0 * maglevel + (2 * level)
    
    local min = (formula * (base - variation)) / 100
    local max = (formula * (base + variation)) / 100
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    local player = Player(creature)
    if player then
        -- Se o jogador estiver acima do nível 200, aplica o custo de mana
        if player:getLevel() > 200 then
            local manaCost = 5 + (player:getLevel() - 200) * 5 -- 5 é o custo adicional de mana para cada 10 níveis após 200
            -- Verifica se o jogador tem mana suficiente para lançar a magia
            if player:getMana() >= manaCost then
                player:addMana(-manaCost) -- Reduz a mana do jogador pelo custo da magia
                return combat:execute(creature, variant) -- Executa a magia
            end
        else
            return combat:execute(creature, variant) -- Executa a magia sem custo de mana para jogadores até o nível 200
        end
    end
    
    return false
end
 
Back
Top