• 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!

Decreases damage for each attack

itzbrhue3

New Member
Joined
Feb 21, 2017
Messages
41
Solutions
1
Reaction score
1
I did this spell, but i don't know how decrease damage for each iteration

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)


function onGetFormulaValues(cid, level, maglevel)
    local levelTotal = level / 5
    local min = levelTotal + (maglevel * 8)
    local max = levelTotal + (maglevel * 12)
    return -min, -max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")


local function choose(...)
    local arg = {...}
    return arg[math.random(1,#arg)]
end

local function check_pos(fromPos, toPos)
    x = fromPos.x - toPos.x
    y = fromPos.y - toPos.y
    if (x == -1) and (y == -1) then
        return choose({-1, -1}, {-1, 0}, {0, -1})
    elseif (x == 0) and (y == -1) then
        return choose({-1, -1}, {0, -1}, {1, -1})
    elseif (x == 1) and (y == -1) then
        return choose({0, -1}, {1, -1}, {1, 0})
    elseif (x == -1) and (y == 0) then
        return choose({-1, -1}, {-1, 0}, {-1, 1})
    elseif (x == 1) and (y == 0) then
        return choose({1, -1}, {1, 0}, {1, 1})
    elseif (x == -1) and (y == 1) then
        return choose({-1, 0}, {-1, 1}, {0, 1})
    elseif (x == 0) and (y == 1) then
        return choose({-1, 1}, {0, 1}, {1, 1})
    elseif (x == 1) and (y == 1) then
        return choose({0, 1}, {1, 0}, {1, 1})
    else
        return choose({-1, -1}, {-1, 0}, {0, -1}, {-1, -1}, {0, -1}, {1, -1}, {0, -1}, {1, -1}, {1, 0}, {-1, -1}, {-1, 0}, {-1, 1}, {1, -1}, {1, 0}, {1, 1}, {-1, 0}, {-1, 1}, {0, 1}, {-1, 1}, {0, 1}, {1, 1}, {0, 1}, {1, 0}, {1, 1})
    end
end

local function distEffect(cid)
    player_pos = getCreaturePosition(cid)
    target_pos = getCreaturePosition(getCreatureTarget(cid))
    var = check_pos(player_pos, target_pos)
    start_pos = {x = player_pos.x+var[1], y = player_pos.y+var[2], z = player_pos.z}
    final_pos = target_pos
    doSendDistanceShoot(start_pos, final_pos, 28)
end
 

function onCastSpell(cid, var)
    max_atk = math.floor(getPlayerMagLevel(cid) / 25)
    for i = 1, max_atk do
        addEvent(function()
            if isCreature(getCreatureTarget(cid)) then
                distEffect(cid)
                doCombat(cid, combat, var)
            end
        end, i * 100)
    end
    return true
end
 
Lua:
function onGetFormulaValues(cid, level, maglevel)
    local levelTotal = level / 5
    local min = levelTotal + (maglevel * 8)
    local max = levelTotal + (maglevel * 12)
    return -min, -max
end
Lua:
 return -min, -max
Changing that to return +min, +max should have more of the desired effect, but if the whole formula is what you want or not, is another question.
Lua:
max_atk = math.floor(getPlayerMagLevel(cid) / 25)
I think this one needs changing too, instead of dividing whatever the player's magic level is with 25, perhaps do addition or multiplication?

[Edit] Hmm, after having read your comment again, I'm not sure whether you're wanting it to decrease damage for every attack (iteration), or if you're wanting to turn the damage into positive/higher numbers.
 
Last edited:
Lua:
function onGetFormulaValues(cid, level, maglevel)
    local levelTotal = level / 5
    local min = levelTotal + (maglevel * 8)
    local max = levelTotal + (maglevel * 12)
    return -min, -max
end
Lua:
 return -min, -max
Changing that to return +min, +max should have more of the desired effect, but if the whole formula is what you want or not, is another question.
Lua:
max_atk = math.floor(getPlayerMagLevel(cid) / 25)
I think this one needs changing too, instead of dividing whatever the player's magic level is with 25, perhaps do addition or multiplication?

[Edit] Hmm, after having read your comment again, I'm not sure whether you're wanting it to decrease damage for every attack (iteration), or if you're wanting to turn the damage into positive/higher numbers.
this "player ml / 25" is how many atk has the spell, i want know decrease 20% from previous atk
example: player ml 100 attack 4x: 1000 -> 800 -> 640 -> 512
 
this "player ml / 25" is how many atk has the spell, i want know decrease 20% from previous atk
example: player ml 100 attack 4x: 1000 -> 800 -> 640 -> 512
Hmm, I think one way is to have a starting damage (number), and then subtract (remove) x % or number with a loop for each usage of the spell.
But I don't know how to write that in lua, only in Python and maybe C++. :D

In Python, it could be something like this:
Python:
starting_damage = 1000

for i in range(starting_damage):
    if starting_damage == 0:
        break
    else:
        starting_damage = starting_damage - 100

maybe this gives you some idea of what you can do?
 
its a little bit tricky to work with spells and do stuff like that, but one thing you can do (and the only one in my mind right now) is to use storage values, something like.

Lua:
            ...
            if isCreature(getCreatureTarget(cid)) then
                -- tfs 0.3 - 0.4 isnt it?
                setPlayerStorageValue(cid, 12345, max_atk + 1 - i) -- max_atk = 5 so 5 + 1 = 6, last attack is 6 - 5 thats equal 1 so multi is one
                distEffect(cid)
                doCombat(cid, combat, var)
            end
            ...

also edit formula values
Lua:
function onGetFormulaValues(cid, level, maglevel)
    local spellMultiple = getPlayerStorageValue(cid, 12345)
    if spellMultiple > 0 then
        local levelTotal = level / 5
        local min = levelTotal + (maglevel * 8)
        local max = levelTotal + (maglevel * 12)
        return -min, -max
    end
    return 0, 0
end

pd. you can also do some fake explotion and call the damage combat event function directly (i dont remember the name, doCombat?)
 
Back
Top