its work like this damage +(damage*(storage*2.5)/100)@heba
Worked but now testing I think the formula isnt right because with 0 storage I deal 2800 and with 25 I deal 16k
local lvlcrit = 48913
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(attacker) and (not (attacker == cid)) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
if (getPlayerStorageValue(attacker, lvlcrit)*0.85) >= math.random (0,1000) then
local multiplier = isPlayer(cid) and 2.5 or 1.5
dano = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255)
doSendMagicEffect(getCreaturePos(cid), 64)
return false
end
end
return true
end
Let's start by printing to console some values, to see where the issue is.@Elgenady Can you help me with a completation of this script? I use a critical system but when the critical the damage that return it is absurd when there is often storage that we put in the source
Example:
Player without damage from the storage that added in sources normaly hits 3000 and critical 4500 (max critical increase +50%) = its ok.
Player with +150% damage from the storage that added in sources normaly hits 4500 and get critical 20k+ (instead 4500+50% = 6750)
Lua:local lvlcrit = 48913 function onStatsChange(cid, attacker, type, combat, value) if isPlayer(attacker) and (not (attacker == cid)) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then if (getPlayerStorageValue(attacker, lvlcrit)*0.85) >= math.random (0,1000) then local multiplier = isPlayer(cid) and 2.5 or 1.5 dano = math.ceil(value*(multiplier)) doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255) doSendMagicEffect(getCreaturePos(cid), 64) return false end end return true end
local lvlcrit = 48913
function onStatsChange(cid, attacker, type, combat, value)
print("--------")
if isPlayer(attacker) and (not (attacker == cid)) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
if (getPlayerStorageValue(attacker, lvlcrit)*0.85) >= math.random (0,1000) then
local multiplier = isPlayer(cid) and 2.5 or 1.5
dano = math.ceil(value*(multiplier))
print("value: " .. value)
print("multiplier: " .. multiplier)
print("dano: " .. dano)
doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255)
doSendMagicEffect(getCreaturePos(cid), 64)
return false
end
end
return true
end
Let's start by printing to console some values, to see where the issue is.
Lua:local lvlcrit = 48913 function onStatsChange(cid, attacker, type, combat, value) print("--------") if isPlayer(attacker) and (not (attacker == cid)) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then if (getPlayerStorageValue(attacker, lvlcrit)*0.85) >= math.random (0,1000) then local multiplier = isPlayer(cid) and 2.5 or 1.5 dano = math.ceil(value*(multiplier)) print("value: " .. value) print("multiplier: " .. multiplier) print("dano: " .. dano) doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255) doSendMagicEffect(getCreaturePos(cid), 64) return false end end return true end
Mmm gotcha.There is, looks like sometime the damage accumulate
View attachment 58915View attachment 58916
but pay attention, when this damage accumulates they are the same attack, they are not followed
as below, all these return are from just 1 attack, not 5 in a row
View attachment 58917
local lvlcrit = 48913
local creatures = {}
function onStatsChange(cid, attacker, type, combat, value)
if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then
if creatures[cid] and creatures[cid] == 1 then -- here we check if the damage was multiplied previously
creatures[cid] = 0 -- if yes, we reset the check so the next damage to come through has a chance of being multiplied
return true -- and here we say yes, do the damage
end
if isPlayer(attacker) and attacker ~= cid then
if getPlayerStorageValue(attacker, lvlcrit) * 0.85 >= math.random (1000) then
local multiplier = isPlayer(cid) and 2.5 or 1.5
dano = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255) -- we send the new damage to cid
doSendMagicEffect(getCreaturePos(cid), 64)
creatures[cid] = 1 -- here we hold the creature information, saying that the damage was multiplied
return false -- we deny the original damage by returning false
end
end
end
return true
end
Mmm gotcha.
So this is a feedback loop caused by returning the new damage and allowing it to go through the same statschange script as before.
Since it's going through a 2nd/3rd/4th time, it continues to multiply the damage everytime the critical 'hits'.
What we need to do is make sure that the system cannot infinitely loop the critical damage calculations.
So what we'll do is create a table to hold creature information, and verify if the damage needs to be multiplied, or applied to the creature.
Something like this, should work.
Lua:local lvlcrit = 48913 local creatures = {} function onStatsChange(cid, attacker, type, combat, value) if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then if creatures[cid] and creatures[cid] == 1 then -- here we check if the damage was multiplied previously creatures[cid] = 0 -- if yes, we reset the check so the next damage to come through has a chance of being multiplied return true -- and here we say yes, do the damage end if isPlayer(attacker) and attacker ~= cid then if getPlayerStorageValue(attacker, lvlcrit) * 0.85 >= math.random (1000) then local multiplier = isPlayer(cid) and 2.5 or 1.5 dano = math.ceil(value*(multiplier)) doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255) -- we send the new damage to cid doSendMagicEffect(getCreaturePos(cid), 64) creatures[cid] = 1 -- here we hold the creature information, saying that the damage was multiplied return false -- we deny the original damage by returning false end end end return true end
That's impossible, because there is no prints in the new code.The same thing
View attachment 58918
That's impossible, because there is no prints in the new code.
You forgot to restart your server, or didn't save the file.
I really have no idea how it's not working. xDI restarted, i added the prints to your code to see the damages because dont work =/
local lvlcrit = 48913
local creatures = {}
function onStatsChange(cid, attacker, type, combat, value)
if not creatures[cid] then
creatures[cid] = 0
end
print("------")
print("cid: " .. cid)
print("attacker: " .. attacker)
if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then
print("creatures[cid] = " .. creatures[cid])
if creatures[cid] and creatures[cid] == 1 then
print("Critical damage delivered.")
creatures[cid] = 0
return true
end
if isPlayer(attacker) and attacker ~= cid then
if getPlayerStorageValue(attacker, lvlcrit) * 0.85 >= math.random (1000) then
print("Critical damage succeeded.")
local multiplier = isPlayer(cid) and 2.5 or 1.5
dano = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255)
doSendMagicEffect(getCreaturePos(cid), 64)
creatures[cid] = 1
print("initial value: " .. value)
print("multiplier: " .. multiplier)
print("damage to be applied: " .. dano)
return false
else
print("Critical failed.")
end
else
print("Not a player attacking.")
end
end
return true
end
I really have no idea how it's not working. xD
I added more prints, I guess.
Lua:local lvlcrit = 48913 local creatures = {} function onStatsChange(cid, attacker, type, combat, value) if not creatures[cid] then creatures[cid] = 0 end print("------") print("cid: " .. cid) print("attacker: " .. attacker) if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then print("creatures[cid] = " .. creatures[cid]) if creatures[cid] and creatures[cid] == 1 then print("Critical damage delivered.") creatures[cid] = 0 return true end if isPlayer(attacker) and attacker ~= cid then if getPlayerStorageValue(attacker, lvlcrit) * 0.85 >= math.random (1000) then print("Critical damage succeeded.") local multiplier = isPlayer(cid) and 2.5 or 1.5 dano = math.ceil(value*(multiplier)) doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255) doSendMagicEffect(getCreaturePos(cid), 64) creatures[cid] = 1 print("initial value: " .. value) print("multiplier: " .. multiplier) print("damage to be applied: " .. dano) return false else print("Critical failed.") end else print("Not a player attacking.") end end return true end
Try this.
local lvlcrit = 48913
local creatures = {}
function onStatsChange(cid, attacker, type, combat, value)
if not creatures[cid] then
creatures[cid] = 0
end
print("------")
print("cid: " .. cid)
print("attacker: " .. attacker)
if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then
print("creatures[cid] = " .. creatures[cid])
if creatures[cid] and creatures[cid] == 1 then
print("Critical damage delivered.")
creatures[cid] = 0
return true
end
if isPlayer(attacker) and attacker ~= cid then
if getPlayerStorageValue(attacker, lvlcrit) * 0.85 >= math.random (1000) then
creatures[cid] = 1
print("Critical damage succeeded.")
local multiplier = isPlayer(cid) and 2.5 or 1.5
dano = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255)
doSendMagicEffect(getCreaturePos(cid), 64)
print("initial value: " .. value)
print("multiplier: " .. multiplier)
print("damage to be applied: " .. dano)
return false
else
print("Critcal failed.")
end
else
print("Not a player attacking.")
end
end
return true
end
Try this.
Lua:local lvlcrit = 48913 local creatures = {} function onStatsChange(cid, attacker, type, combat, value) if not creatures[cid] then creatures[cid] = 0 end print("------") print("cid: " .. cid) print("attacker: " .. attacker) if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then print("creatures[cid] = " .. creatures[cid]) if creatures[cid] and creatures[cid] == 1 then print("Critical damage delivered.") creatures[cid] = 0 return true end if isPlayer(attacker) and attacker ~= cid then if getPlayerStorageValue(attacker, lvlcrit) * 0.85 >= math.random (1000) then creatures[cid] = 1 print("Critical damage succeeded.") local multiplier = isPlayer(cid) and 2.5 or 1.5 dano = math.ceil(value*(multiplier)) doTargetCombatHealth(attacker, cid, combat, -dano, -dano, 255) doSendMagicEffect(getCreaturePos(cid), 64) print("initial value: " .. value) print("multiplier: " .. multiplier) print("damage to be applied: " .. dano) return false else print("Critcal failed.") end else print("Not a player attacking.") end end return true end