11.02.2013, 03:22
(
Последний раз редактировалось MP2; 13.02.2013 в 23:57.
)
Introduction
This include reports the amount of health and armour lost to OnPlayerGive/TakeDamage. In the default callback it's just 'amount' which is just the amount of damage - it doesn't tell you how much health or armour was lost.
All you need to do is use the new callbacks, with 'Ex' added at the end (and new parameters of course):
NOTE: It's armour, not armor; I'm British!
I made this at like 4AM so it may not be perfect. I went through many (at least 5) different systems before I found one that worked perfectly, and here it is. I have no idea if there's a better way; believe me I tried. I figured it'd just be a bit of simple maths, not requiring any variables, but I was under the assumption that if they took more damage than health they didn't have, they lost armour, but then I realised they could have < 100 health and still have armour (i.e. they took damage to the health THEN got armour).
You may be thinking 'why not just save their old armour AND health, then use GetPlayerHealth + GetPlayerArmour under OnPlayerGive/Take damage to see what was lost? Well. GetPlayerHealth/Armour doesn't work under OnPlayerGive/TakeDamage because they don't sync with the server until the next OnPlayerUpdate call, which would involve pretty much the same amount of code as this did, but you'd have to have a variable to store their health also. Why waste memory?!
This is also well commented so you can figure out my thought process.
DOWNLOAD: http://pastebin.com/jvFZFEqv
Known Issues:
- Players lose 3 health on spawn for some reason. SA:MP bug most likely.
- If a player has 5 health and are shot with a gun that does 10 damage, the healthloss is reported as 10, not 5 (as it should be IMO).
- When players have armour and lose health (i.e. falling and hitting the ground or on fire) it will report an armour loss, as if they were hit with a bullet.
Please report any issues.
This include reports the amount of health and armour lost to OnPlayerGive/TakeDamage. In the default callback it's just 'amount' which is just the amount of damage - it doesn't tell you how much health or armour was lost.
All you need to do is use the new callbacks, with 'Ex' added at the end (and new parameters of course):
pawn Код:
public OnPlayerTakeDamageEx(playerid, issuerid, Float:healthloss, Float:armourloss, weaponid)
{
// Stuff
}
public OnPlayerGiveDamageEx(playerid, damagedid, Float:healthloss, Float:armourloss, weaponid)
{
// Stuff
}
I made this at like 4AM so it may not be perfect. I went through many (at least 5) different systems before I found one that worked perfectly, and here it is. I have no idea if there's a better way; believe me I tried. I figured it'd just be a bit of simple maths, not requiring any variables, but I was under the assumption that if they took more damage than health they didn't have, they lost armour, but then I realised they could have < 100 health and still have armour (i.e. they took damage to the health THEN got armour).
You may be thinking 'why not just save their old armour AND health, then use GetPlayerHealth + GetPlayerArmour under OnPlayerGive/Take damage to see what was lost? Well. GetPlayerHealth/Armour doesn't work under OnPlayerGive/TakeDamage because they don't sync with the server until the next OnPlayerUpdate call, which would involve pretty much the same amount of code as this did, but you'd have to have a variable to store their health also. Why waste memory?!
This is also well commented so you can figure out my thought process.
DOWNLOAD: http://pastebin.com/jvFZFEqv
Known Issues:
- Players lose 3 health on spawn for some reason. SA:MP bug most likely.
- If a player has 5 health and are shot with a gun that does 10 damage, the healthloss is reported as 10, not 5 (as it should be IMO).
- When players have armour and lose health (i.e. falling and hitting the ground or on fire) it will report an armour loss, as if they were hit with a bullet.
Please report any issues.