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

TFS 0.X Critical script problem

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
854
Solutions
3
Reaction score
141
Location
Egypt
Hello

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)
123.png

Any help?
 
Solution
Adding the toggle state, will tell the script to apply the damage, after it's been changed, without worrying about checking for the critical stuff a 2nd/3rd/4th time, since we already know it's been modified, and about to come through again.
Lua:
local config = {
    storage = PlayerStorageKeys.critical_chance_storage,
    damage = 1.5
}

local toggle = 0

function onStatsChange(cid, attacker, type, combat, value)
    if toggle ~= 0 then
        toggle = 0
        return true
    end
    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...
Hello

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)
View attachment 57361

Any help?

Adding the toggle state, will tell the script to apply the damage, after it's been changed, without worrying about checking for the critical stuff a 2nd/3rd/4th time, since we already know it's been modified, and about to come through again.
Lua:
local config = {
    storage = PlayerStorageKeys.critical_chance_storage,
    damage = 1.5
}

local toggle = 0

function onStatsChange(cid, attacker, type, combat, value)
    if toggle ~= 0 then
        toggle = 0
        return true
    end
    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)
            toggle = 1
            return false
        end
    end
    return true
end
 
Adding the toggle state, will tell the script to apply the damage, after it's been changed, without worrying about checking for the critical stuff a 2nd/3rd/4th time, since we already know it's been modified, and about to come through again.
Lua:
local config = {
    storage = PlayerStorageKeys.critical_chance_storage,
    damage = 1.5
}

local toggle = 0

function onStatsChange(cid, attacker, type, combat, value)
    if toggle ~= 0 then
        toggle = 0
        return true
    end
    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)
            toggle = 1
            return false
        end
    end
    return true
end
Thanks for answering, but i tried it and the problem still there.

I was looking here in the forum and i found a change you did before to someone and it worked for me.
link

script after change and it worked.
Lua:
local config = {
    storage = PlayerStorageKeys.critical_chance_storage,
    damage = 1.5
}
local creatures = {}

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and (not (attacker == cid)) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
        if creatures[cid] and creatures[cid] == 1 then
            creatures[cid] = 0
            return true
        end
        creatures[cid] = 1
        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
 
Solution
Back
Top