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

Knight Spells Formula

MarkSmartRemark

Lua-Noob in Training :D
Joined
Jan 27, 2010
Messages
139
Reaction score
3
Hi, Im using 8.6 (tfs 0.3.6)

I need help understanding the formula for knight spells. I understand how they work now but i want to know if theres a way to change it.

heres an example of what im trying to do..

I want the damage be ONLY based on the players weapon attack, and the rest of the formula i put there.. Or at least very close in between the min and max..
I dont want the players skill or level affecting the formula unless theres source editing needed.. which in that case dont worry about it.. But i need to know how the weapon gets put in onGetFormulaValue please!

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

function onGetFormulaValues(cid, weaponAttack, uid)  
    local playerWeapon = getPlayerWeapon(cid)
  
    min = 10 + (getItemAttack(playerWeapon.uid)*1.1)
    max = 20 + (getItemAttack(playerWeapon.uid)*1.1)
    return -min, -max
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end

Heres another version i tried to make but neither worked..
Code:
local function damageFormula(cid)
    local playerWeapon = getPlayerWeapon(cid)
    min = 10 + (getItemAttack(playerWeapon.uid)*1.1)
    max = 20 + (getItemAttack(playerWeapon.uid)*1.1)
    return -math.random(min, max)
end


function onCastSpell(cid, var)
doTargetCombatHealth(cid, getCreatureTarget(cid), COMBAT_PHYSICALDAMAGE, damageFormula(cid), damageFormula(cid), CONST_ME_HITAREA)
    return doCombat(cid, combat, var)
end

I Get this error when trying it out.

Code:
[25/02/2014 23:28:59] [Error - Spell Interface]
[25/02/2014 23:28:59] data/spells/scripts/Warrior/New/Heroic Strike.lua:onCastSpell
[25/02/2014 23:28:59] Description:
[25/02/2014 23:28:59] data/spells/scripts/Warrior/New/Heroic Strike.lua:18: attempt to call global 'getItemAttack' (a nil value)
[25/02/2014 23:28:59] stack traceback:
[25/02/2014 23:28:59]    data/spells/scripts/Warrior/New/Heroic Strike.lua:18: in function 'damageFormula'
[25/02/2014 23:28:59]    data/spells/scripts/Warrior/New/Heroic Strike.lua:25: in function <data/spells/scripts/Warrior/New/Heroic Strike.lua:24>

EDIT: If it cant be done this way, is there another way to get similar results? Thanks to whoever can help!!
 
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

function getSpellDamage(cid, skill, att, attackStrength)
   
local min = -(10 + (attackStrength*1.1))
local max = -(20 + (attackStrength*1.1))

    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "getSpellDamage")

function onCastSpell(cid, var)
return doCombat(cid, combat, var)
end

Try something like that, I'm using similar formula for weapons on my 0.3.6 8.54, but this should work for spells too I think. I'm not any pro scripter tho, but you can try.
 
I had many problems with getPlayerWeapon(cid) in the past.

Change your onGetFormulaValues function to this:
Code:
function onGetFormulaValues(cid)
    local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    local atk, atk1, atk2 = 0, 0, 0
    if item1.uid ~= 0 then
        atk1 = getItemAttack(item1.uid)
    end
    if item2.uid ~= 0 then
        atk2 = getItemAttack(item2.uid)
    end
    if atk1 > atk2 then
        atk = atk1
    else
        atk = atk2
    end

    min = 10 + (atk * 1.1)
    max = 20 + (atk * 1.1)
    return -min, -max
end
 
Last edited:
@andu hey, thanks for looking into it.. its giving me the same error though, i switched it to your formula. still doesnt recognize getItemAttack : /



I had many problems with getPlayerWeapon(cid) in the past.

Change your onGetFormulaValues function to this:
Code:
function onGetFormulaValues(cid)
    local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    local atk, atk1, atk2 = 0, 0, 0
    if item1.uid ~= 0 then
        atk1 = getItemAttack(item1.uid)
    end
    if item2.uid ~= 0 then
        atk2 = getItemAttack(item2.uid)
    end
    if atk1 > atk2 then
        atk = atk1
    else
        atk = atk2
    end

    min = 10 + (atk * 1.1)
    max = 20 + (atk * 1.1)
    return -min, -max
end

@Syryniss This worked! i tested by changing weapons and trying it out with chars that have diff skills and the damage was always grabbed from the weapon.. Thanks alot dude!

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

function getSpellDamage(cid, skill, att, attackStrength)
  
local min = -(10 + (attackStrength*1.1))
local max = -(20 + (attackStrength*1.1))

    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "getSpellDamage")

function onCastSpell(cid, var)
return doCombat(cid, combat, var)
end

Try something like that, I'm using similar formula for weapons on my 0.3.6 8.54, but this should work for spells too I think. I'm not any pro scripter tho, but you can try.
 
Back
Top