Server Sided Health/Armour Functions.
#1

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

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
Reply
#3

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

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

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); 
Reply
#6

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

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
Reply
#8

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

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

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 
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)