Code:
local cfg = {
minDamageToDodge = 21, -- players will be unable to dodge for example firefield or poison damage
dodgeMeleePhysical = true,
dodgeRangedPhysical = true,
dodgeSpells = true,
values = {
-- vocId = vocationId, melee = chance in % to dodge melee physical attack, etc
[1] = {vocId = 1, melee = 50, ranged = 5, spells = 10},
[2] = {vocId = 2, melee = 50, ranged = 5, spells = 10},
[3] = {vocId = 3, melee = 50, ranged = 15, spells = 10},
[4] = {vocId = 4, melee = 50, ranged = 5, spells = 10},
[5] = {vocId = 5, melee = 50, ranged = 5, spells = 10},
[6] = {vocId = 6, melee = 50, ranged = 5, spells = 10},
[7] = {vocId = 7, melee = 50, ranged = 15, spells = 10},
[8] = {vocId = 8, melee = 50, ranged = 5, spells = 10}
}
}
local buffsAndDebuffs = {
[1] = {id = 54000, melee = 500, ranged = 50, spells = 60}, -- whenever player have CONDITION_REGENERATION with SUBID 54000 then he gains +30% dodge
[2] = {id = 55555, melee = -100, ranged = -100, spells = -100} -- players with CONDITION_REGENERATION with SUBID 55555 are unable to dodge attacks
}
local function doDodge(cid)
local pos = getCreaturePosition(cid)
doSendMagicEffect(pos, CONST_ME_POFF)
doSendAnimatedText(pos, "DODGE", 215)
return true
end
function onChangeHealth(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local voc, x, roll = getPlayerVocation(cid), 0, math.random(1,100)
if isCreature(cid) == true and (primaryType == 1 or primaryType == 3) and primaryDamage >= cfg.minDamageToDodge then
for i = 1, #cfg.values do
if voc == cfg.values[i].vocId then
x = i
end
end
if isCreature(attacker) == true and x ~= 0 then
local v, b = cfg.values[x], buffsAndDebuffs
for j = 1, #b do
if getCreatureCondition(cid, CONDITION_REGENERATION, b[j].id) == true then
v.melee = v.melee + b.melee
v.ranged = v.ranged + b.ranged
v.spells = v.spells + b.spells
end
end
if primaryDamage == COMBAT_PHYSICALDAMAGE then
if getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(attacker)) <= 1 then
if roll <= v.melee then
doDodge(cid)
return false
end
else
if roll <= v.ranged then
doDodge(cid)
return false
end
end
else
if roll <= v.spells then
doDodge(cid)
return false
end
end
end
end
return true
end
What am I doing wrong?