OnPlayerTakeDamage
#1

Hi, I'm creating a gamemode right now, I added 10.0 additional damage to headshots, but the problem is when I shoot it sets the health to old hp - 10.0. So like if I have 80 hp, get shot in head from any weapon I'll have 70 hp. I've experienced this issue in other gamemode as well so there's nothing wrong with my gamemode.
Here's the code:
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
	if (issuerid != INVALID_PLAYER_ID)
	{
		if (bodypart == 9)
		{
			new Float:health, Float:armor;
			GetPlayerHealth(playerid, health);
			GetPlayerArmour(playerid, armor);
				
			if (armor > 10.0) SetPlayerArmour(playerid, armor - 10.0);
			else if (armor) SetPlayerArmour(playerid, 0.0);
			else if (health > 10.0) SetPlayerHealth(playerid, health - 10.0);
			else SetPlayerHealth(playerid, 0.0);
		}
	}
	return 1;
}
What's up with it? That's like getting the health before the player takes default SAMP damage. One way is just adding 10.0 to "amount" that is in the callback then take the amount from the player's health.
Reply
#2

You need to fix this part of the code....

PHP код:
            if (armor 10.0SetPlayerArmour(playeridarmor 10.0);
            else if (
armorSetPlayerArmour(playerid0.0);
            else if (
health 10.0SetPlayerHealth(playeridhealth 10.0);
            else 
SetPlayerHealth(playerid0.0); 
use something like this
PHP код:
                new Float:armourFloat:hp;
                
GetPlayerArmour(playeridarmour);
                if(
Float:armour 0.0)
                {
                    if(
Float:armour amount)
                    {
                        
GetPlayerArmour(playeridarmour);
                        
SetPlayerArmour(playeridarmour amount);
                    }
                    else
                    {
                        new 
Float:newer;
                        
newer amount armour;
                        
SetPlayerArmour(playerid0);
                        
GetPlayerHealth(playeridhp);
                        
SetPlayerHealth(playeridhp newer);
                    }
                }
                else
                {
                    
GetPlayerHealth(playeridhp);
                    
SetPlayerHealth(playeridhp amount);
                } 
(taken from my gamemode)
Reply
#3

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
You need to fix this part of the code....

PHP код:
            if (armor 10.0SetPlayerArmour(playeridarmor 10.0);
            else if (
armorSetPlayerArmour(playerid0.0);
            else if (
health 10.0SetPlayerHealth(playeridhealth 10.0);
            else 
SetPlayerHealth(playerid0.0); 
use something like this
PHP код:
                new Float:armourFloat:hp;
                
GetPlayerArmour(playeridarmour);
                if(
Float:armour 0.0)
                {
                    if(
Float:armour amount)
                    {
                        
GetPlayerArmour(playeridarmour);
                        
SetPlayerArmour(playeridarmour amount);
                    }
                    else
                    {
                        new 
Float:newer;
                        
newer amount armour;
                        
SetPlayerArmour(playerid0);
                        
GetPlayerHealth(playeridhp);
                        
SetPlayerHealth(playeridhp newer);
                    }
                }
                else
                {
                    
GetPlayerHealth(playeridhp);
                    
SetPlayerHealth(playeridhp amount);
                } 
(taken from my gamemode)
Yeah, I could do that myself, but the thing is that I don't want to do anything with the "amount". Is it the only way to make it work? Does anyone know?
Reply
#4

Set the player's team to 1 upon connecting, this way no damage will be done but the callback will still get called and the amount value still holds the damage it's given. So just simply do whatever you want with it.
Reply
#5

Quote:
Originally Posted by PaulDinam
Посмотреть сообщение
Set the player's team to 1 upon connecting, this way no damage will be done but the callback will still get called and the amount value still holds the damage it's given. So just simply do whatever you want with it.
I know, I've done that in my roleplay gamemode, but I have a TDM gamemode, so I want to keep the default SAMP teams instead of pTeam or something. Also for shotguns I'll need to check distance everytime player gets shot. I'll think about it, but I can still do the "amount" thing. But yeah, setting players to one team and creating custom damages would make the gamemode more enjoyable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)