thalmonn
New Member
- Joined
- Aug 18, 2019
- Messages
- 9
- Reaction score
- 0
So, with help of users from OtLand, we make this code and it is works very well for melee combat. I try use with sword, axe and club. Works very fine.
But now, the question is, how make this work with distance for ranged atk and work with magic level, for druids and sorc? The need is to work when a palladin atk with a bow, and his basic atk with arrow have the chance to do the critical, like the swords, axes and clubs. For sorc and druid, its the same, when use a wand or staff, the atk have a chance to do critical hit too.
Anyone can help me?
The code:
But now, the question is, how make this work with distance for ranged atk and work with magic level, for druids and sorc? The need is to work when a palladin atk with a bow, and his basic atk with arrow have the chance to do the critical, like the swords, axes and clubs. For sorc and druid, its the same, when use a wand or staff, the atk have a chance to do critical hit too.
Anyone can help me?
The code:
Lua:
-- Create the normal attack combatObject
local normalAttack = createCombatObject()
setCombatParam(normalAttack, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
-- Define the formula for a normal attack
function normalAttackFormula(player, level, maglevel)
skill = player:getSkillLevel(SKILL_SWORD)
level = player:getLevel()
min = -((skill*1)+level*1)
max = -((skill*7)+level*1)
return min, max
end
-- Attach the normal attack formula to the normal attack combat object
setCombatCallback(normalAttack, CALLBACK_PARAM_LEVELMAGICVALUE, "normalAttackFormula")
-- Create the critical strike combatObject
local criticalStrike = createCombatObject()
setCombatParam(criticalStrike, COMBAT_PARAM_EFFECT, 32)
setCombatParam(criticalStrike, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
-- Define the formula for a critical strike
function criticalStrikeFormula(player, level, maglevel)
skill = player:getSkillLevel(SKILL_SWORD)
level = player:getLevel()
min = -((skill*9)+level*2)
max = -((skill*12)+level*3)
return min, max
end
-- Attach a delayed condition to the critical strike combatObject
local condition = createConditionObject(CONDITION_EMO)
setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(condition, 100, 3100, -math.random(67,112))
setCombatCondition(criticalStrike, condition)
-- Attach the critical strike formula to the critical strike combat object
setCombatCallback(criticalStrike, CALLBACK_PARAM_LEVELMAGICVALUE, "criticalStrikeFormula")
-- When assigned weapon is used
function onUseWeapon(player, variant)
-- 50 skill / 645 = aprox 7.7% chance of a critical strike
if math.random(1,645) <= player:getSkillLevel(SKILL_SWORD) then
-- If you do a critical strike, there is an additional
-- 1 / 29 = 3.4% chance of saying "For honor!"
if math.random(1,29) == 1 then
player:say("For honor!",TALKTYPE_SAY)
end
-- Heal player 20% of his max health
player:addHealth(player:getMaxHealth()/5)
-- AnimatedText might be deprecated in clients > 8.6
--doSendAnimatedText(getPlayerPosition(cid),"Critical!",129)
player:say("Critical!", TALKTYPE_MONSTER_SAY)
-- Do the critical strike
doCombat(player, criticalStrike, variant)
else
-- Do a regular attack
doCombat(player, normalAttack, variant)
end
end