Solved Hp/Mana % Bug

Discussion in 'Support' started by Niioxce, Apr 17, 2018.

  1. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    I currently have a problem with Crypton3's hp/mana % source code. The problem is that after a certain level then the % just stops working and shows the normal number again (65,535) untill i level up some more and then it resets at 1% and goes up to 11% and then back to 65,535 and the it just resets over and over again. Here's a gif that shows it. I'm on 8.6 tfs 0.3.7 rev 5969
    Imgur GIF
     
  2. Best Answer:
    Post #13 by MaR0, Apr 18, 2018
  3. Sarah Wesker

    Sarah Wesker S.E ©

    Joined:
    Mar 16, 2017
    Messages:
    279
    Likes Received:
    122
    Best Answers:
    20
    Code (Text):
    1.  
    2. msg->put<uint16_t>(player->getHealth() / player->getPlayerInfo(PLAYERINFO_MAXHEALTH) * 100);
    3. msg->put<uint16_t>(100);
    4.  
    5. msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_MANA) / player->getPlayerInfo(PLAYERINFO_MAXMANA) * 100);
    6. msg->put<uint16_t>(100);
     
  4. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    That kinda works! Sometimes it gets stuck at 0 and then goes back upto 100 when i level up. It also goes down to 0 when i get attacked. That's most likely why.
     
  5. Sarah Wesker

    Sarah Wesker S.E ©

    Joined:
    Mar 16, 2017
    Messages:
    279
    Likes Received:
    122
    Best Answers:
    20
    Show source code ........
     
  6. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    Code (C++):
    1.  
    2.     if (player->getPlayerInfo(PLAYERINFO_MAXHEALTH) > 0)
    3.     {
    4.         msg->put<uint16_t>(uint16_t(player->getHealth() * 100 / player->getPlayerInfo(PLAYERINFO_MAXHEALTH)));
    5.         msg->put<uint16_t>(100);
    6.     }
    7.     else
    8.     {
    9.         msg->put<uint16_t>(0);
    10.         msg->put<uint16_t>(0);
    11.     }
    12.  
    Code (C++):
    1.  
    2.     if (player->getPlayerInfo(PLAYERINFO_MAXMANA) > 0)
    3.     {
    4.         msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_MANA) * 100 / player->getPlayerInfo(PLAYERINFO_MAXMANA));
    5.         msg->put<uint16_t>(100);
    6.     }
    7.     else
    8.     {
    9.         msg->put<uint16_t>(0);
    10.         msg->put<uint16_t>(0);
    11.     }
    12.  
    What i use right now
     
    Last edited: Apr 18, 2018
  7. ZeeBeast

    ZeeBeast Preferable Beta Tester

    Joined:
    Dec 5, 2013
    Messages:
    204
    Likes Received:
    8
    Best Answers:
    0
    Is it just the mana doing it now?
    Did you fix the health?
     
  8. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    Nope, with that code i posted above it is exactly as i described it in the original post.
     
  9. Sarah Wesker

    Sarah Wesker S.E ©

    Joined:
    Mar 16, 2017
    Messages:
    279
    Likes Received:
    122
    Best Answers:
    20
    Code (C):
    1.  
    2. if (player->getPlayerInfo(PLAYERINFO_MAXMANA) > 0)
    3.     {
    4.         msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_MANA) * 100 / player->getPlayerInfo(PLAYERINFO_MAXMANA));
    5.         msg->put<uint16_t>(100);
    6.     }
    7.     else
    8.     {
    9.         msg->put<uint16_t>(0);
    10.         msg->put<uint16_t>(100); // <----------- is 100 not 0
    11. }
    the condition is not necessary.
    if > 0
     
  10. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    Now it's even more weird Imgur GIF

    Code (C++):
    1.     if (player->getPlayerInfo(PLAYERINFO_MAXMANA))
    2.     {
    3.         msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_MANA) * 100 / player->getPlayerInfo(PLAYERINFO_MAXMANA));
    4.         msg->put<uint16_t>(100);
    5.     }
    6.     else
    7.     {
    8.         msg->put<uint16_t>(0);
    9.         msg->put<uint16_t>(100);
    10.     }
     
  11. adric21

    adric21 Member

    Joined:
    Apr 26, 2016
    Messages:
    159
    Likes Received:
    11
    Best Answers:
    1
    I can fix bro
     
  12. Sarah Wesker

    Sarah Wesker S.E ©

    Joined:
    Mar 16, 2017
    Messages:
    279
    Likes Received:
    122
    Best Answers:
    20
    Code (Lua):
    1.  
    2. uint16_t resultPercentHp(uint16_t now, uint16_t max) {
    3.     if (now < 1) {
    4.         return 0;
    5.     }
    6.     uint16_t total = ((now / max) * 100);
    7.     return total;
    8. }
    9.  
    10. void ProtocolGame::AddPlayerStats(NetworkMessage_ptr msg)
    11. {
    12.     msg->put<char>(0xA0);
    13.     msg->put<uint16_t>(resultPercentHp(player->getHealth(), player->getPlayerInfo(PLAYERINFO_MAXHEALTH)));
    14.     msg->put<uint16_t>(100);
    15.     msg->put<uint32_t>(uint32_t(player->getFreeCapacity() * 100));
    16.     uint64_t experience = player->getExperience();
    17.     if(experience > 0x7FFFFFFF) // client debugs after 2,147,483,647 exp
    18.         msg->put<uint32_t>(0x7FFFFFFF);
    19.     else
    20.         msg->put<uint32_t>(experience);
    21.  
    22.     msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_LEVEL));
    23.     msg->put<char>(player->getPlayerInfo(PLAYERINFO_LEVELPERCENT));
    24.     msg->put<uint16_t>(resultPercentHp(player->getPlayerInfo(PLAYERINFO_MANA), player->getPlayerInfo(PLAYERINFO_MAXMANA)));
    25.     msg->put<uint16_t>(100);
    26.     msg->put<char>(player->getPlayerInfo(PLAYERINFO_MAGICLEVEL));
    27.     msg->put<char>(player->getPlayerInfo(PLAYERINFO_MAGICLEVELPERCENT));
    28.     msg->put<char>(player->getPlayerInfo(PLAYERINFO_SOUL));
    29.     msg->put<uint16_t>(player->getStaminaMinutes());
    30. }
     
  13. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    Okay so, it kinda works again. The ONLY problem there is that it goes to 0 when im attacked or use a spell (but thats the mana). I don't see 65,535 anymore atleast Imgur GIF
    Seems like it can either only be 0 or 100
     
    Last edited: Apr 18, 2018
  14. MaR0

    MaR0 Member

    Joined:
    Apr 16, 2018
    Messages:
    109
    Likes Received:
    8
    Best Answers:
    2
    Best Answer
    try this
    Code (C++):
    1. void ProtocolGame::AddPlayerStats(NetworkMessage_ptr msg)
    2. {
    3.     msg->put<char>(0xA0);
    4.     if (player->getPlayerInfo(PLAYERINFO_MAXHEALTH) > 0)
    5. {
    6.   msg->put<uint16_t>(uint16_t(player->getHealth() * 100ULL / player->getPlayerInfo(PLAYERINFO_MAXHEALTH)));
    7.   msg->put<uint16_t>(100);
    8. }
    9. else
    10. {
    11.   msg->put<uint16_t>(0);
    12.   msg->put<uint16_t>(0);
    13. }
    14.     msg->put<uint32_t>(uint32_t(player->getFreeCapacity() * 100));
    15.     uint64_t experience = player->getPlayerInfo(PLAYERINFO_LEVEL);
    16.     if(experience > 0x7FFFFFFF)
    17.         msg->put<uint32_t>(0x7FFFFFFF);
    18.     else
    19.         msg->put<uint32_t>(experience);
    20.  
    21.     msg->put<uint16_t>(0);
    22.     msg->put<char>(player->getPlayerInfo(PLAYERINFO_LEVELPERCENT));
    23.     if (player->getPlayerInfo(PLAYERINFO_MAXMANA) > 0)
    24. {
    25.   msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_MANA) * 100ULL / player->getPlayerInfo(PLAYERINFO_MAXMANA));
    26.   msg->put<uint16_t>(100);
    27. }
    Code (C++):
    1. void ProtocolGame::AddCreatureHealth(NetworkMessage_ptr msg,const Creature* creature)
    2. {
    3.     msg->put<char>(0x8C);
    4.     msg->put<uint32_t>(creature->getID());
    5.     if(!creature->getHideHealth())
    6.         msg->put<char>((uint8_t)std::ceil(creature->getHealth() * 100. / std::max(creature->getMaxHealth(), (int32_t)1)));
    7.     else
    8.         msg->put<char>(0x00);
    9. }
    Code (C++):
    1. msg->put<char>((uint8_t)std::ceil(creature->getHealth() * 100. / std::max(creature->getMaxHealth(), 1)));
     
    Niioxce likes this.
  15. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    Yes, this worked. Thank you so much MaRo!
     
    MaR0 likes this.
  16. MaR0

    MaR0 Member

    Joined:
    Apr 16, 2018
    Messages:
    109
    Likes Received:
    8
    Best Answers:
    2
    We are here to help :p
     
    Niioxce likes this.

Share This Page

Loading...