C++ Damage absorb

Discussion in 'Support' started by beliar34, Dec 6, 2017.

  1. beliar34

    beliar34 Member

    Joined:
    Feb 28, 2012
    Messages:
    201
    Likes Received:
    3
    Best Answers:
    5
    Code (Text):
    1.  if(combatType == COMBAT_PHYSICALDAMAGE && target && target->getPlayer())
    2.                 {
    3.                     double absorbPower = 0, damageChange = 0;
    4.                     int32_t hape = target->getPlayer()->getHealth();
    5.                     int32_t skillShield = target->getPlayer()->getSkill(SKILL_SHIELD, SKILL_LEVEL);
    6.                     if(damage < hape)
    7.                     if(skillShield >= 10)
    8.                     {
    9.                         absorbPower = (std::floor(skillShield / 5) - 2) * 1;
    10.                         damageChange = std::ceil((damage * absorbPower) / 100);
    11.                     }                    
    12.                     if((int32_t)damageChange != 0)
    13.                     {
    14.                         damage -= (int32_t)damageChange + 1;
    15.                         char buffer[150];
    16.                         sprintf(buffer, "%d hitpoint%s has been absorbed by your defense.", (int32_t)damageChange, ((int32_t)damageChange == 1 ? "" : "s"));
    17.                         target->getPlayer()->sendTextMessage(MSG_EVENT_DEFAULT, buffer);
    18.                     }
    19.                 }
    20.  
    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: Dec 6, 2017
  2. Best Answer:
    Post #6 by pasiak12, Dec 7, 2017
  3. pasiak12

    pasiak12 Active Member

    Joined:
    Jun 7, 2009
    Messages:
    211
    Likes Received:
    36
    Best Answers:
    8
    Debug your code or just put simple printfs to check the values inside when you make test hits.

    Seems like it should work:
    Code (C++):
    1.  
    2.                 //STATE:
    3.                 // PLAYER HP: 10
    4.                 // DMG: 50
    5.                 // 10% reduced dmg
    6.                 {
    7.                     double absorbPower = 0, damageChange = 0;
    8.                     int32_t hape = target->getPlayer()->getHealth();
    9.                     //hape = 10
    10.                    
    11.                     int32_t skillShield = target->getPlayer()->getSkill(SKILL_SHIELD, SKILL_LEVEL);
    12.                     // 60~ skill for 10% dmg redu?
    13.                    
    14.                     //if(damage < hape) not need
    15.                     if(skillShield >= 10)
    16.                     {
    17.                         absorbPower = (std::floor(skillShield / 5) - 2) * 1; // why * 1?
    18.                         //abosrdPower = 10
    19.                        
    20.                        
    21.                         damageChange = std::ceil((damage * absorbPower) / 100);
    22.                         //damageChange = 5
    23.                     }                  
    24.                     if((int32_t)damageChange != 0)
    25.                     {
    26.                         damage -= (int32_t)damageChange + 1;
    27.                         //final damage = 44
    28.                        
    29.                         char buffer[150];
    30.                         sprintf(buffer, "%d hitpoint%s has been absorbed by your defense.", (int32_t)damageChange, ((int32_t)damageChange == 1 ? "" : "s"));
    31.                         target->getPlayer()->sendTextMessage(MSG_EVENT_DEFAULT, buffer);
    32.                     }
    33.                 }
    34.                 //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.
     
  4. beliar34

    beliar34 Member

    Joined:
    Feb 28, 2012
    Messages:
    201
    Likes Received:
    3
    Best Answers:
    5
    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: Dec 7, 2017
  5. pasiak12

    pasiak12 Active Member

    Joined:
    Jun 7, 2009
    Messages:
    211
    Likes Received:
    36
    Best Answers:
    8
    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: Dec 7, 2017
  6. beliar34

    beliar34 Member

    Joined:
    Feb 28, 2012
    Messages:
    201
    Likes Received:
    3
    Best Answers:
    5
    Last edited: Dec 7, 2017
  7. pasiak12

    pasiak12 Active Member

    Joined:
    Jun 7, 2009
    Messages:
    211
    Likes Received:
    36
    Best Answers:
    8
    Best Answer
    beliar34 likes this.
  8. beliar34

    beliar34 Member

    Joined:
    Feb 28, 2012
    Messages:
    201
    Likes Received:
    3
    Best Answers:
    5
    Done, working in raw, thread can be closed REP+
     

Share This Page

Loading...