PDA

View Full Version : Disabling damange once reaching a certain amount


aoky
12/06/2017, 09:31 AM
I'm trying to find a way to have it to so once a player reaches < = 5 health, he will no longer take damage. I've managed to do it but, it won't work to how I want it. Basically, I want to set if your health is 6 for example, and you get shot my a desert eagle your health will NOT go under 5. I can't figure a way around out it, if possible an explanation below would be helpful. Code isn't needed just an explanation. Thank you.

DRIFT_HUNTER
12/06/2017, 09:53 AM
http://wiki.sa-mp.com/wiki/OnPlayerWeaponShot
returning 0 will prevent from bullet causing damage (there will be no bullet)

Keep in mind that if player fals and looses that 5hp, there is nothing you can do about it. If that is an issue the only way around it is YSF by Kurta or some custom damage system with 3d labels attached to players head.

aoky
12/06/2017, 10:00 AM
If the players health is 6, and he gets shot by a Deagle he will just die though.

GoldenLion
12/06/2017, 11:19 AM
One way is what DRIFT_HUNTER said, but the other way is that you put all players into the same team to disable damages and create your own.

Zmith
12/06/2017, 11:40 AM
I haven't tested it ingame, but it should work I guess.

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
new Float:HP;
GetPlayerHealth(playerid, HP);
if(HP == 5)
{
SetPlayerHealth(playerid, 5);//If this doesn't work, you could set the player's health -1 and create a timer to set it back to 5.
}
return 1;
}

DRIFT_HUNTER
12/06/2017, 12:23 PM
I haven't tested it ingame, but it should work I guess.

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
new Float:HP;
GetPlayerHealth(playerid, HP);
if(HP == 5)
{
SetPlayerHealth(playerid, 5);//If this doesn't work, you could set the player's health -1 and create a timer to set it back to 5.
}
return 1;
}

First, you are checking for exactly 5hp, not less or equal, second you are setting player HP to 5 not to what it was. Third, if im not wrong GetPlayerHealth in these case will return new health (after the hit was processed). And whole public is not meant to be used for these. If player has 15hp, he gets hit by deagle, he will lose all HP and die before server has time to restore it.

FailerZ
12/06/2017, 02:03 PM
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == BULLET_HIT_TYPE_PLAYER)
{
if(hitid != INVALID_PLAYER_ID)
{
new Float:hp;
GetPlayerHealth(hitid, hp);
if(hp <= 5.0 && GetPlayerWeapon(playerid) == WEAPON_DEAGLE) return 0; //Return 0 means the one who got shot (hitid) is not going to take damage
//Change the hp as you wish it but that's how i understand what you said
}
}
return 1;
}

DRIFT_HUNTER
12/06/2017, 02:40 PM
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == BULLET_HIT_TYPE_PLAYER)
{
if(hitid != INVALID_PLAYER_ID)
{
new Float:hp;
GetPlayerHealth(hitid, hp);
if(hp <= 5.0 && GetPlayerWeapon(playerid) == WEAPON_DEAGLE) return 0; //Return 0 means the one who got shot (hitid) is not going to take damage
//Change the hp as you wish it but that's how i understand what you said
}
}
return 1;
}

That's basically it, but you should have leave it to him since its that simple. Anyway the only thing now he has to account for weapon damage. If for example player has 29hp and gets 30 damage he will still die. I guess these will come in handy http://forum.sa-mp.com/showthread.php?t=563387

aoky
12/06/2017, 02:47 PM
That's basically it, but you should have leave it to him since its that simple. Anyway the only thing now he has to account for weapon damage. If for example player has 29hp and gets 30 damage he will still die. I guess these will come in handy http://forum.sa-mp.com/showthread.php?t=563387

I've tried it before with that, I get these errors.

C:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(1700) : warning 202: number of arguments does not match definition
C:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(1698) : warning 203: symbol is never used: "addsiren"
C:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(5448) : warning 213: tag mismatch
C:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(5715) : error 025: function heading differs from prototype
C:\Users\Austin\Desktop\Small-County-RP-Release\gamemodes\SCRP-R39.pwn(92) : warning 201: redefinition of constant/macro (symbol "E_SHOT_INFO")
C:\Users\Austin\Desktop\Small-County-RP-Release\gamemodes\SCRP-R39.pwn(1279) : warning 235: public function lacks forward declaration (symbol "OnPlayerShootPlayer")
C:\Users\Austin\Desktop\Small-County-RP-Release\gamemodes\SCRP-R39.pwn(1322) : warning 209: function "WC_OnPlayerConnect" should return a value
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase