SA-MP Forums Archive
Server Sided Health/Armour Functions. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Server Sided Health/Armour Functions. (/showthread.php?tid=677133)



Server Sided Health/Armour Functions. - SkyFlare - 01.07.2020

So I am making my own Server Sided Health / Armour in Textdraws, which is complete.

Just looking to upgrade my script a little bit.

in a bonestock standard Script, using GetPlayerHealth(playerid, Player[playerid][Health]);
would get the players Health, and in return save the value into the float specified.
how can I create a function myself like this.. here's what I am doing so far.


PHP Code:
GetPlayerHealthEx(playerid, &Float:HpAmountHpAmount Player[playerid][Health];
GetPlayerArmorEx(playerid, &Float:ArmorAmountArmorAmount Player[playerid][Armor];
SetPlayerHealthEx(playeridFloat:HpAmountPlayer[playerid][Health] = HpAmount;
SetPlayerArmorEx(playeridFloat:ArmorAmountPlayer[playerid][Armor] = ArmorAmount
Note I am moving right away from the whole standard Get/Set PlayerHealth standard CMDS as they are now useless, because every players HP will be infinite in that value.


Re: Server Sided Health/Armour Functions. - SharpenBlade - 01.07.2020

Seems ok, but I don't think you can set player's health without using SetPlayerHealth.
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
GetPlayerArmorEx(playerid) return Player[playerid][Armor];
SetPlayerHealthEx(playeridFloat:HpAmount
{
    
Player[playerid][Health] = HpAmount;
    
SetPlayerHealth(playeridPlayer[playerid][Health]);
    return 
1;
}
SetPlayerArmorEx(playeridFloat:ArmorAmount
{
    
Player[playerid][Armor] = ArmorAmount;
    
SetPlayerArmor(playeridPlayer[playerid][Armor]);
    return 
1;

Or check this: https://forum.sa-mp.com/showpost.php...61&postcount=6


Re: Server Sided Health/Armour Functions. - SkyFlare - 01.07.2020

Quote:
Originally Posted by SharpenBlade
View Post
Seems ok, but I don't think you can set player's health without using SetPlayerHealth.
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
GetPlayerArmorEx(playerid) return Player[playerid][Armor];
SetPlayerHealthEx(playeridFloat:HpAmount
{
    
Player[playerid][Health] = HpAmount;
    
SetPlayerHealth(playeridPlayer[playerid][Health]);
    return 
1;
}
SetPlayerArmorEx(playeridFloat:ArmorAmount
{
    
Player[playerid][Armor] = ArmorAmount;
    
SetPlayerArmor(playeridPlayer[playerid][Armor]);
    return 
1;

Or check this: https://forum.sa-mp.com/showpost.php...61&postcount=6
Yeah, I see your point but the only time ill use SetPlayerHealth Code is upon initial spawn, to set them to infinite Health, other than that, the only data for health im using is from MySQL, the enumerator where the MySQL Data is stored, and the Textdraw where the players health is displayed.

I only want to get players health from the TD now, not the old values from GetPlayerHealth, so I want to mimic the functions that i used to have.


Re: Server Sided Health/Armour Functions. - SharpenBlade - 01.07.2020

Well, then I think your code could work.
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
GetPlayerArmorEx(playerid) return Player[playerid][Armor];
SetPlayerHealthEx(playeridFloat:HpAmount) return Player[playerid][Health] = HpAmount;
SetPlayerArmorEx(playeridFloat:ArmorAmount) return Player[playerid][Armor] = ArmorAmount



Re: Server Sided Health/Armour Functions. - SkyFlare - 01.07.2020

Quote:
Originally Posted by SharpenBlade
View Post
Well, then I think your code could work.
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
GetPlayerArmorEx(playerid) return Player[playerid][Armor];
SetPlayerHealthEx(playeridFloat:HpAmount) return Player[playerid][Health] = HpAmount;
SetPlayerArmorEx(playeridFloat:ArmorAmount) return Player[playerid][Armor] = ArmorAmount
Do you think this would work?
PHP Code:
GetPlayerHealthEx(playerid, &Float:HpAmount)
{
    
HpAmount Player[playerid][Health];

in theory this would be how i use it

PHP Code:
new Float:healthdying;
GetPlayerHealthEx(playeridhealthdying); 



Re: Server Sided Health/Armour Functions. - SharpenBlade - 01.07.2020

Quote:
Originally Posted by SkyFlare
View Post
Do you think this would work?
PHP Code:
GetPlayerHealthEx(playerid, &Float:HpAmount)
{
    
HpAmount Player[playerid][Health];

in theory this would be how i use it

PHP Code:
new Float:healthdying;
GetPlayerHealthEx(playeridhealthdying); 
Well, HpAmount = Player[playerid][Health]; means that you are setting HPAmount value to Player[playerid][Health]. If you want to change Player[playerid][Health] value (you set player health value to the value of HpAmount) use this:
PHP Code:
Player[playerid][Health] = HpAmount



Re: Server Sided Health/Armour Functions. - SkyFlare - 01.07.2020

Quote:
Originally Posted by SharpenBlade
View Post
Well, HpAmount = Player[playerid][Health]; means that you are setting HPAmount value to Player[playerid][Health]. If you want to change Player[playerid][Health] value (you set player health value to the value of HpAmount) use this:
PHP Code:
Player[playerid][Health] = HpAmount
Yeah but that's GetPlayerHealth, not SetPlayerHealth :P


Re: Server Sided Health/Armour Functions. - SharpenBlade - 01.07.2020

Yes, sorry, I have read it wrong. I am not sure about it... Why don't you use it like this?
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
//in command:
new Float:health GetPlayerHealthEx(playerid); 
You are already storing health value in a variable, just use it.


Re: Server Sided Health/Armour Functions. - SkyFlare - 01.07.2020

Quote:
Originally Posted by SharpenBlade
View Post
Yes, sorry, I have read it wrong. I am not sure about it... Why don't you use it like this?
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
//in command:
new Float:health GetPlayerHealthEx(playerid); 
You are already storing health value in a variable, just use it.
Server Sided Damage & values associated will make it quite hard, will be a lot of new variables created and it'll get confusing once i dive in deep with different damage types, so im trying to make a framework which benefits of simplicity from the beginning, if its extra code behind the function, I dont mind, so long as the other side of it is a lot easier to understand.


Re: Server Sided Health/Armour Functions. - ShadowMortar - 01.07.2020

ALS hook SetPlayerHealth/Armour, GetPlayerHealth/Armour, and under OnPlayerTakeDamage do the thing.
Example:
PHP Code:
SetPlayerArmourExplayeridFloat:armour ) {
    
PlayerInfoplayerid ] [ pArmor ] = armour;
    return 
SetPlayerArmourplayeridPlayerInfoplayerid ] [ pArmor ] );
}
GetPlayerArmourExplayerid, &Float:armour ) {
    return 
PlayerInfoplayerid ] [ pArmor ];
}
#if defined _ALS_SetPlayerHealth
    #undef SetPlayerArmour 
#else 
    #define _ALS_SetPlayerArmour
#endif
#define SetPlayerArmour SetPlayerArmourEx
#if defined _ALS_GetPlayerArmour
    #undef GetPlayerArmour 
#else 
    #define _ALS_GetPlayerArmour
#endif
#define GetPlayerArmour GetPlayerArmourEx