[Tutorial] Custom Playerdamage system
#21

I'm new to this scripting, okay I see all of these codes but how to add them to my script? just copy & paste them under each other? please help.
Reply
#22

wrong section post here http://forum.sa-mp.com/forumdisplay.php?f=12
Reply
#23

Quote:
Originally Posted by Colonel
View Post
I'm new to this scripting, okay I see all of these codes but how to add them to my script? just copy & paste them under each other? please help.
The defines should be at the very top of your script.
Underneath the defines should be your OnPlayerTakeDamage callback.
Then inside the OnPlayerTakeDamage, right above return 1 you put the switch, because you need to get the health and armour first, and the return 1 stops the callback.
Reply
#24

This really helped me.
Reply
#25

Why do i get this error
Code:
error 025: function heading differs from prototype
I downloaded latest samp server from sa-mp.com and replaced all includes. Have no idea what to do
Reply
#26

Very good job, i like it!
Reply
#27

Update!

I found a better way to negate damage by putting players to the same teams, which fixes a bug with decreasing damage and makes it look less laggy overall.
Also explained about OnPlayerGiveDamage, and how it differentiates from OnPlayerTakeDamage.

For everyone using the old system
Read "OnPlayerTakeDamage VS OnPlayerGiveDamage", "Part 1 - Setting Teams", and make sure you don't negate the damage anymore, teams does this automatically.

Thanks to everyone for their feedback, much appreciated!
Reply
#28

Amazing one man, This helped me!

EDIT:

PHP Code:
public OnPlayerTakeDamage(playeriddamagedidFloatamountweaponidbodypart)
// playerid = The person that gave the damage.
// damagedid = The player that got damaged.
// Float: amount = The amount of damage given.
// weaponid = The weapon ID that dealt the damage.
// bodypart = The bodypart that was hit. 
Isn't this must be OnPlayerGiveDamage?
Reply
#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.
Reply
#30

Quote:
Originally Posted by oMa37
View Post
Amazing one man, This helped me!

EDIT:

PHP Code:
public OnPlayerTakeDamage(playeriddamagedidFloatamountweaponidbodypart)
// playerid = The person that gave the damage.
// damagedid = The player that got damaged.
// Float: amount = The amount of damage given.
// weaponid = The weapon ID that dealt the damage.
// bodypart = The bodypart that was hit. 
Isn't this must be OnPlayerGiveDamage?
Whoops, fixed.

Quote:
Originally Posted by Manyula
View Post
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.
Armour is just the same as health, just that you put it under "default" in the switch, as i explained in the last line:
Quote:

And then you do the same under "default", just change SetPlayerHealth to SetPlayerArmour, and health - (value) to armour - (value).

And infact i think he would be left with 0.99 health in your example, since GetPlayerHealth rounds the health, while SetPlayerHealth does not.
Atleast that's what it said on the wiki, but even if SetPlayerHealth rounds too, the player would need to receive 49.5 damage to round up to 50.

But if you want to be that accurate you can, it wouldn't differ more than 0.5 at most though.
Reply
#31

Quote:
Originally Posted by CalvinC
View Post
Armour is just the same as health, just that you put it under "default" in the switch, as i explained in the last line.
I am not exactly sure if your implementation accounts for the transition from health to armor, like if a player gets hit with 30 damage and is only left with 15 armor. Do you mind elaborating a little bit on that? I don't know if I'm missing something.

Quote:
Originally Posted by CalvinC
View Post
And infact i think he would be left with 0.99 health in your example, since GetPlayerHealth rounds the health, while SetPlayerHealth does not.
Atleast that's what it said on the wiki, but even if SetPlayerHealth rounds too, the player would need to receive 49.5 damage to round up to 50.

But if you want to be that accurate you can, it wouldn't differ more than 0.5 at most though.
Well, I once had a timer that was supposed to reduce the player's health by 0.1 and ended up reducing it 1.0 per tick. That leads to the assumption that as long as there is ANY decimal number, even if it is really really small, SetPlayerHealth rounds up to the next integer.
Reply
#32

Whenever I use this code, removing the player health works. Yet, when I try and remove the armor, it crashes the server.
Reply
#33

Quote:
Originally Posted by oSAINTo
View Post
Whenever I use this code, removing the player health works. Yet, when I try and remove the armor, it crashes the server.
Bump
Reply
#34

Thank u very much nice tutorial , I was looking for this damage shit
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)