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

How to create your own combat formula with LUA

M1l0rd

New Member
Joined
Aug 13, 2018
Messages
2
Reaction score
0
Is there a way to make my own combat formula using only LUA? something like this:

I don't know if i can get the weapon attack from var parameter
data\weapons\scripts\weapon_name.lua
Lua:
function onUseWeapon(cid, var)
    local player
    local target
    local damage = player.weapon.attack + player.level * 2 - target.armor
    target.hp -= damage
    return true
end

I don't know the functions to get each value that i need and i don't found a documentation of every function with its parameters. This is what i tried:

Lua:
function onUseWeapon(cid, var)
    local target = getCreatureTarget(cid)
    local weapon_attack = 7 -- How to get this value?
    local target_armor = 2 -- How to get this value?
    local minDamage = weapon_attack + getPlayerLevel(cid) * 2 - target_armor
    local maxDamage = minDamage * 1.2
    if math.random(100) <= 30 then
        minDamage = minDamage * 3.5
        maxDamage = maxDamage * 3.5
        doCreatureSay(target, "Critical Strike!", TALKTYPE_MONSTER)
    end
    doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -minDamage, -maxDamage, CONST_ME_NONE)
    return true
end

Edit:
My Server
 
Last edited:
I would suggest going into sources instead, in weapons.cpp/weapons.h and applying your formula there. It would be my first intuition that if you decide to override most of the combat using lua, then your slowing down your server unnecessarily, since your doing one combat formula then immediately overriding it. Plus, most of the things you are looking for, like weapon atk, type, etc, are easily found in the server sources.
Though, more knowledgable users here could probably correct me if I'm wrong...
 
If you want to do it through lua you need to use onHealthChange/onManaChange creaturescripts.
 
I would suggest going into sources instead, in weapons.cpp/weapons.h and applying your formula there. It would be my first intuition that if you decide to override most of the combat using lua, then your slowing down your server unnecessarily, since your doing one combat formula then immediately overriding it. Plus, most of the things you are looking for, like weapon atk, type, etc, are easily found in the server sources.
Though, more knowledgable users here could probably correct me if I'm wrong...
I'm thinking in use COMBAT_FORMULA_DAMAGE and test how defense and armor works in my server because i know that [9.1] Rookgaard Tales+ don't use TFS.

If you want to do it through lua you need to use onHealthChange/onManaChange creaturescripts.
I'll try it following this post, this comment makes things more difficult.

I would like a good documentation to know all lua functions and how to use it correctly(data\lib\050-function.lua is not complete) but the best thing i found was this, it's a bit hard because i don't a expert in C++ and i want to only work with Lua but there so many conditions to check when a hit occurs like this.

Thanks for reply :)
 
Back
Top