• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Reduce Damage on OnStatsChange helpme!

beenii

Well-Known Member
Joined
Jul 26, 2010
Messages
586
Solutions
1
Reaction score
58
Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then
value = value - 10
doTargetCombatHealth(attacker, cid, combat, -value, -value, type)
end
return true
end


how reduce damage in players?
i use tfs 0.4
and how reduce damage by elements its posible?
 
value is the amount of damage, if you want to reduce by a percentage, do this:
for 10%
Code:
value = value * (1 - 0.1)
if you want to skip the extra math step, just do
Code:
value = value * 0.9

to reduce based on elements, use the type. Type is the element. you can do an if statement, like
Code:
if type == COMBAT_FIREDAMAGE then
value = value * 0.9
end

for reference, you can check out http://pastebin.com/5ytquKms
This is an advanced resistance system for my alchemy system. It's TFS 1.1, but it's the same general concept.
 
value is the amount of damage, if you want to reduce by a percentage, do this:
for 10%
Code:
value = value * (1 - 0.1)
if you want to skip the extra math step, just do
Code:
value = value * 0.9

to reduce based on elements, use the type. Type is the element. you can do an if statement, like
Code:
if type == COMBAT_FIREDAMAGE then
value = value * 0.9
end

for reference, you can check out http://pastebin.com/5ytquKms
This is an advanced resistance system for my alchemy system. It's TFS 1.1, but it's the same general concept.

thanks, your formule increase attack xD! need reduce, when i put for testing: value = value - 10 (the damage increase i confused) xD
 
if you multiply something by a decimal below 1, it will reduce it.
value * 0.9 will result in 90% of the original value

i create new test basic.
Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then
value = value / 2
doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "your attack reduce "..value.."")
end
return value
end

here:
"your attack reduce "..value..""
sendme msg correct. attack is 7 in msg show 3.5 etc.

attack is normal, no reduce, how send "value" to damage? have idea?
 
not 100% sure on how the function works in this version, but in your first post, you had
Code:
doTargetCombatHealth(attacker, cid, combat, -value, -value, type)
I imagine you would need to include this after setting value, but as I said I'm not 100% sure
 
not 100% sure on how the function works in this version, but in your first post, you had
Code:
doTargetCombatHealth(attacker, cid, combat, -value, -value, type)
I imagine you would need to include this after setting value, but as I said I'm not 100% sure

with
doTargetCombatHealth(attacker, cid, combat, -value, -value, type)

attack increase, beacuse have normal damage + doTargetCombartHealth :c xD!
 
ah. In 1.1, you just return the damages. it doesn't seem to work that way in this version. what you could do is just add the damage back.
Code:
local temp = value * 0.1
doTargetCombatHealth(attacker, cid, combat, value, value, type)
this will make it do normal damage, then heal back 10% of the original damage
 
Did you tried returning false?
i try this:

Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then
value = value / 2
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, ""..value.."")
doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "your attack reduce "..value.."")
doTargetCombatHealth(attacker, cid, combat, -value, -value, type)
return false
end
return true
end

and dont have damage, and try move
doTargetCombatHealth(attacker, cid, combat, -value, -value, type)
before
return false
end

and same result.

ah. In 1.1, you just return the damages. it doesn't seem to work that way in this version. what you could do is just add the damage back.
Code:
local temp = value * 0.1
doTargetCombatHealth(attacker, cid, combat, value, value, type)
this will make it do normal damage, then heal back 10% of the original damage

yes ur code give health to cid, but need protection for my script xD
jq6kox.png
 
Last edited by a moderator:
Code:
if(combatType == COMBAT_PHYSICALDAMAGE && target && target->getPlayer()) 
                { 
                    double absorbPower = 0, damageChange = 0;
                    int32_t hape = target->getPlayer()->getHealth();
                    int32_t skillShield = target->getPlayer()->getSkill(SKILL_SHIELD, SKILL_LEVEL);
                    if(skillShield >= 10) 
                    {
                        absorbPower = (std::floor(skillShield / 5) - 2) * 1;
                        damageChange = std::ceil((damage * absorbPower) / 100);
                    }                       
             int32_t demejdz = damage - damageChange;
            if(hape > damage)
            if(hape > demejdz)
                    if((int32_t)damageChange != 0) 
                    { 
                        damage -= (int32_t)damageChange + 1; 
                        char buffer[150]; 
                        sprintf(buffer, "%d hitpoint%s has been absorbed by your defense.", (int32_t)damageChange, ((int32_t)damageChange == 1 ? "" : "s")); 
                        target->getPlayer()->sendTextMessage(MSG_EVENT_DEFAULT, buffer); 
                    } 
                }
 
Back
Top