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

C++ Damage absorb

beliar34

Member
Joined
Feb 28, 2012
Messages
307
Solutions
7
Reaction score
11
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(damage < hape)
                    if(skillShield >= 10)
                    {
                        absorbPower = (std::floor(skillShield / 5) - 2) * 1;
                        damageChange = std::ceil((damage * absorbPower) / 100);
                    }                    
                    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);
                    }
                }

I got little problem wit hthis code without this string : if(damage < hape) when people got low health they are immortals, if player normal hits to other players 5k and then hit player who has 2k health and 30% reduce he hits only by 1700 and then when player had 100 health he hit by 70 and it goes till player got 1 health and he became immortal

With this string that i add problem with immortal and low hits is deleted but when player got 10k health and he got absorbtion lets say 60% and get hited by 10k and 1 dmg (10001) abso would not help him

How to setup that to reduce DMG from DMG that player should recieve not player will recieve becouse he got low health

becouse i got low english skills i will post quick example :

How it works now :
With : if(damage < hape)
if player got 100 health and reduce dmg 10% :
if he get hited by 50 he recieve 45 DMG
if he get hited by 60 he recieve 54 dmg
if he het hited by 90 he recieve 81 dmg
But when he get hited by 100 he recieve 100 dmg < this is not good he should recieve 90 reduced dmg :(

Without if(damage < hape):
if player got 100 health and reduce dmg 10% :
if he get hited by 50 he recieve 45 DMG
if he get hited by 60 he recieve 54 dmg
if he het hited by 90 he recieve 81 dmg
But when he get hited by 100 he recieve 90 dmg < damage is still reduced he recieve 90 dmg

There start problem with script
Now he got 10 health
Player hits now shoul hits him more than 50, but damage and reduce is based on his "gethealth" so he get hited by 10 becouse this is how many health he got left, damage is being reduced to 9
Now he got 1 health
and now all damage is reduced to 0, becouse 1*0.9 is less than 1 and in tibia we cant hit less than 1 !

i want to make Reduced damage based on damage that should be hitted not on damage that player will recieve becouse he got low health


LONG POST :(


Edit : Can i setup diffrent health range for players ? now its 0 to infinity, if i would change health range from -1000 to infinity (all player is dead when health >=0 so no problem here if player would get - health) where i had to search a health range ? in player.cpp or game.cpp ?
 
Last edited:
Debug your code or just put simple printfs to check the values inside when you make test hits.

Seems like it should work:
C++:
                //STATE:
                // PLAYER HP: 10
                // DMG: 50
                // 10% reduced dmg
                {
                    double absorbPower = 0, damageChange = 0;
                    int32_t hape = target->getPlayer()->getHealth();
                    //hape = 10
                   
                    int32_t skillShield = target->getPlayer()->getSkill(SKILL_SHIELD, SKILL_LEVEL);
                    // 60~ skill for 10% dmg redu?
                   
                    //if(damage < hape) not need
                    if(skillShield >= 10)
                    {
                        absorbPower = (std::floor(skillShield / 5) - 2) * 1; // why * 1?
                        //abosrdPower = 10
                       
                       
                        damageChange = std::ceil((damage * absorbPower) / 100);
                        //damageChange = 5
                    }                   
                    if((int32_t)damageChange != 0)
                    {
                        damage -= (int32_t)damageChange + 1;
                        //final damage = 44
                       
                        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);
                    }
                }
                //further player loses 44 hp and dies because its bigger value than his current hp


Whats the purpose of changing players health range? It should be always unsigned value. You should be able to find it in player class, so look in player.h, but with changing its type you will be in need to make a lot of changes in whole sources.
 
absorbPower = (std::floor(skillShield / 5) - 2) * 1; // why * 1? << there should be -1 my mistake :D (1 try to stop bug with 1 health players)
// 60~ skill for 10% dmg redu? << 5 skill 1% redu so yes at 60 shielding we got 10% becouse i delete first 10 skills (-2 in here : (skillShield / 5) - 2))
Going to test you'r code :)

@pasiak12
you'r code works like my one before : "hape" quick fix :(

This dont work becouse script reduce from dmg that player will recieve
If player got 10 health he can recieve dmg = 10 dmg :(
if he got 20 hp left he can recieve only 20hp
if i would set a min player hp at "-" he will be able to recieve more dmg

Anyway, what you edit in my script ? becouse i just see that you deleted my quickfix :
if(damage < hape) and posted my bugged script


Edit : Hmm i got idea to add to player protection like this one in items <attribute key="absorbPercentAll" value="10"

^is there a way to compile it with my script ? in same way ?
1% per 5 shielding skills?
which file
what parameter?
 
Last edited by a moderator:
@pasiak12
you'r code works like my one before : "hape" quick fix :(

Yea, because I did not modify nothing there, just added my debug thougths


Where have you placed that function? The dmg modifiers should be placed in some 'onChangeHealth' method in game.cpp. There you will have raw 50~ dmg, no matter how much hp player has left.
 
Last edited:
Solution
Back
Top