29.04.2016, 13:29
Hm, maybe a couple of suggestions for you to consider:
1. You should also include armor since the current version will only work with the standard health bar.
2. As far as I know, you can't set a player's health to an exact floating point value which means that in this case it is slightly inaccurate. Declare the player's health and armor globally, then check for the last value of the respective variable and set the new value right into it. Lastly, set the player's health to that specific value. The function itself will set the health to a rounded integer value, so the HP bar might be slightly off, but the variables that store the health and armor are always accurate.
Let me give you an example of what your implementation does:
- A player has 49.50 health
- The player receives 49.01 damage
- SetPlayerHealth tries to set the health of that particular player to 0.49. However, it rounds the damage up to 50.0 damage, which means that the player would have actually survived that hit, but SetPlayerhealth chose to kill him right away.
1. You should also include armor since the current version will only work with the standard health bar.
2. As far as I know, you can't set a player's health to an exact floating point value which means that in this case it is slightly inaccurate. Declare the player's health and armor globally, then check for the last value of the respective variable and set the new value right into it. Lastly, set the player's health to that specific value. The function itself will set the health to a rounded integer value, so the HP bar might be slightly off, but the variables that store the health and armor are always accurate.
Let me give you an example of what your implementation does:
- A player has 49.50 health
- The player receives 49.01 damage
- SetPlayerHealth tries to set the health of that particular player to 0.49. However, it rounds the damage up to 50.0 damage, which means that the player would have actually survived that hit, but SetPlayerhealth chose to kill him right away.