Disabling damange once reaching a certain amount
#1

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.
Reply
#2

https://sampwiki.blast.hk/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.
Reply
#3

If the players health is 6, and he gets shot by a Deagle he will just die though.
Reply
#4

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.
Reply
#5

I haven't tested it ingame, but it should work I guess.

PHP Code:
public OnPlayerTakeDamage(playeridissueridFloatamountweaponidbodypart)
{
    new 
Float:HP;
    
GetPlayerHealth(playeridHP);
    if(
HP == 5)
    {
        
SetPlayerHealth(playerid5);//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;

Reply
#6

Quote:
Originally Posted by Zmith
View Post
I haven't tested it ingame, but it should work I guess.

PHP Code:
public OnPlayerTakeDamage(playeridissueridFloatamountweaponidbodypart)
{
    new 
Float:HP;
    
GetPlayerHealth(playeridHP);
    if(
HP == 5)
    {
        
SetPlayerHealth(playerid5);//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.
Reply
#7

PHP Code:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    if(
hittype == BULLET_HIT_TYPE_PLAYER)
    {
        if(
hitid != INVALID_PLAYER_ID)
        {
            new 
Float:hp;
            
GetPlayerHealth(hitidhp);
            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;

Reply
#8

Quote:
Originally Posted by FailerZ
View Post
PHP Code:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    if(
hittype == BULLET_HIT_TYPE_PLAYER)
    {
        if(
hitid != INVALID_PLAYER_ID)
        {
            new 
Float:hp;
            
GetPlayerHealth(hitidhp);
            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 https://sampforum.blast.hk/showthread.php?tid=563387
Reply
#9

Quote:
Originally Posted by DRIFT_HUNTER
View Post
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 https://sampforum.blast.hk/showthread.php?tid=563387
I've tried it before with that, I get these errors.
PHP Code:
C:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(1700) : warning 202number of arguments does not match definition
C
:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(1698) : warning 203symbol is never used"addsiren"
C:\Users\Austin\Desktop\Small-County-RP-Release\pawno\include\weapon-config.inc(5448) : warning 213tag 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 201redefinition 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 
(c1997-2006ITB CompuPhase 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)