SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/06/2017, 09:31 AM   #1
aoky
Huge Clucker
 
aoky's Avatar
 
Join Date: Oct 2016
Location: Ireland
Posts: 493
Reputation: 136
Default Disabling damange once reaching a certain amount

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.
__________________
owner/developer @ koky's deathmatch
aoky is offline   Reply With Quote
Old 12/06/2017, 09:53 AM   #2
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,151
Reputation: 215
Default Re: Disabling damange once reaching a certain amount

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.
DRIFT_HUNTER is offline   Reply With Quote
Old 12/06/2017, 10:00 AM   #3
aoky
Huge Clucker
 
aoky's Avatar
 
Join Date: Oct 2016
Location: Ireland
Posts: 493
Reputation: 136
Default Re: Disabling damange once reaching a certain amount

If the players health is 6, and he gets shot by a Deagle he will just die though.
__________________
owner/developer @ koky's deathmatch
aoky is offline   Reply With Quote
Old 12/06/2017, 11:19 AM   #4
GoldenLion
Gangsta
 
GoldenLion's Avatar
 
Join Date: Sep 2014
Location: Estonia
Posts: 944
Reputation: 142
Default Re: Disabling damange once reaching a certain amount

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.
GoldenLion is offline   Reply With Quote
Old 12/06/2017, 11:40 AM   #5
Zmith
Big Clucker
 
Zmith's Avatar
 
Join Date: Jun 2013
Location: England
Posts: 76
Reputation: 14
Default Re: Disabling damange once reaching a certain amount

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;

Zmith is offline   Reply With Quote
Old 12/06/2017, 12:23 PM   #6
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,151
Reputation: 215
Default Re: Disabling damange once reaching a certain amount

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.
DRIFT_HUNTER is offline   Reply With Quote
Old 12/06/2017, 02:03 PM   #7
FailerZ
Huge Clucker
 
FailerZ's Avatar
 
Join Date: Oct 2013
Posts: 243
Reputation: 43
Default Re: Disabling damange once reaching a certain amount

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;

__________________
My old work:
[FilterScript]Digital Health & Armour [DHA]
[FilterScript]Labels Creator [LC]
[FilterScript]Debug Mode [D-Mode]
[FilterScript]Advance Fish System [AFS]
FailerZ is offline   Reply With Quote
Old 12/06/2017, 02:40 PM   #8
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,151
Reputation: 215
Default Re: Disabling damange once reaching a certain amount

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 http://forum.sa-mp.com/showthread.php?t=563387
DRIFT_HUNTER is offline   Reply With Quote
Old 12/06/2017, 02:47 PM   #9
aoky
Huge Clucker
 
aoky's Avatar
 
Join Date: Oct 2016
Location: Ireland
Posts: 493
Reputation: 136
Default Re: Disabling damange once reaching a certain amount

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 http://forum.sa-mp.com/showthread.php?t=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 
__________________
owner/developer @ koky's deathmatch
aoky is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reaching an enum variable with a filterscript? Outcast Scripting Help 3 29/12/2011 09:08 PM
Not reaching 5th debug message iTorran Scripting Help 3 11/12/2011 09:56 PM
How Do I Do This? On Screen Amount Of Kills And amount Of Deaths HayZatic Help Archive 1 01/07/2011 02:26 PM


All times are GMT. The time now is 07:01 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.