mRefaat
Marketing and Coding
Hello
i am using this script to make a critical hit system.
Everything is working but i figured a problem happens sometimes.
Check the image (sometimes script(dmg) doubled or 3x critical same time)
Any help?
i am using this script to make a critical hit system.
Lua:
local config = {
storage = PlayerStorageKeys.critical_chance_storage,
damage = 1.5
}
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(attacker) and (not (attacker == cid)) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
local chance = getPlayerStorageValue(attacker, config.storage)
if math.random(1, 100) <= chance then
local new_value = math.ceil(value * config.damage)
local new_value2 = math.ceil(value * config.damage * 2)
if isPlayer(cid) then
doTargetCombatHealth(attacker, cid, combat, -new_value2, -new_value2, 255)
end
if isMonster(cid) then
doTargetCombatHealth(attacker, cid, combat, -new_value, -new_value, 255)
end
doSendAnimatedText(getCreaturePos(attacker), "CRITICAL!", COLOR_DARKRED)
return false
end
end
return true
end
Everything is working but i figured a problem happens sometimes.
Check the image (sometimes script(dmg) doubled or 3x critical same time)
Any help?