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

Lua Making the damage scale based on player's skill stats.

Obito

0x1337
Joined
Feb 17, 2011
Messages
351
Solutions
8
Reaction score
151
Location
Egypt
Hello :) ,

I'm currently working on a script for my server and I would like to make it scale with damage. Specifically, I want the script to deal more damage as the player's stats skills increase. However, I'm not sure how to implement this.
Currently, my script looks like this:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ETHEREALSPEAR)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, -1900, 0, -1900)

function onUseWeapon(cid, var)
    return doCombat(cid, combat, var)
end
As you can see the script uses the COMBAT_FORMULA_SKILL formula with a fixed base damage of -1900. However, I would like to implement a scaling mechanism that adjusts the damage output based on the player's skill stats. The idea is to make the formula more dynamic so that it deals more damage as the player's stats skills increase.

For instance, if the player has 20 magic levels, it should increase the damage output accordingly. Similarly, if the player has 50 distance fighting skills, it should also raise the damage output.

Can anyone suggest how I can achieve this? Any help or suggestions would be greatly appreciated.
 
Last edited:
Use the skill callback
Lua:
function onGetFormulaValues(player, skill, attack, factor)

    local min = 1900 + your_formula
    local max = 1900 + your_formula

    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
 
Use the skill callback
Lua:
function onGetFormulaValues(player, skill, attack, factor)

    local min = 1900 + your_formula
    local max = 1900 + your_formula

    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
Thank you for your assistance @Roddet. I have a question about the specification of damage types in my script. Is it feasible to designate a particular damage type for each skill type? For example, suppose I want a spell to boost both my magic level and distance fighting damage from the script. In that case, can I indicate the specific damage applied for each skill type separately? I noticed
Code:
CALLBACK_PARAM_SKILLVALUE
in the code, and I'm curious if it applies to magic level or distance fighting or both, or all damage types?.
 
Lua:
function onGetFormulaValues(player, skill, attack, factor)
    local mlvl = player:getMagicLevel()
    local distance = player:getSkillLevel(SKILL_DISTANCE)
    local min = 1900 + mlvl * 100 + distance * 100
    local max = 1900 + mlvl * 100 + distance * 100

    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

Something like this?
 
Lua:
function onGetFormulaValues(player, skill, attack, factor)
    local mlvl = player:getMagicLevel()
    local distance = player:getSkillLevel(SKILL_DISTANCE)
    local min = 1900 + mlvl * 100 + distance * 100
    local max = 1900 + mlvl * 100 + distance * 100

    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

Something like this?
Yes, but the damage is only applied from the formula. I'm trying to make it apply from the items themselves to sync with it. When I added your formula, it dealt 7.40k damage even if I didn't have a ring or boots to raise my skills stats. Here is what I'm talking about to explain more:
animation-gif.75239

Edit: This what i have on my items.xml so far
XML:
<item id="2090" article="a" name="Archmages ring">
        <attribute key="weight" value="90"/>
        <attribute key="slotType" value="ring"/>
        <attribute key="armor" value="60"/>
        <attribute key="skillSword" value="100"/>
        <attribute key="skillClub" value="100"/>
        <attribute key="skillAxe" value="100"/>
        <attribute key="skillDist" value="100"/>
        <attribute key="manaGain" value="60000"/>
        <attribute key="manaTicks" value="15"/>
</item>
 

Attachments

Last edited:
Try this:

player:getEffectiveSkillLevel(SKILL_DISTANCE)
Thank you so much for your help levi! your advice was spot-on, and I was able to increase my damage by 17.70k even with ring. I'm so grateful for your help. You're a lifesaver!
 
Last edited:
Back
Top