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:HpAmount) HpAmount = Player[playerid][Health];
GetPlayerArmorEx(playerid, &Float:ArmorAmount) ArmorAmount = Player[playerid][Armor];
SetPlayerHealthEx(playerid, Float:HpAmount) Player[playerid][Health] = HpAmount;
SetPlayerArmorEx(playerid, Float:ArmorAmount) Player[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(playerid, Float:HpAmount)
{
Player[playerid][Health] = HpAmount;
SetPlayerHealth(playerid, Player[playerid][Health]);
return 1;
}
SetPlayerArmorEx(playerid, Float:ArmorAmount)
{
Player[playerid][Armor] = ArmorAmount;
SetPlayerArmor(playerid, Player[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
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(playerid, Float:HpAmount)
{
Player[playerid][Health] = HpAmount;
SetPlayerHealth(playerid, Player[playerid][Health]);
return 1;
}
SetPlayerArmorEx(playerid, Float:ArmorAmount)
{
Player[playerid][Armor] = ArmorAmount;
SetPlayerArmor(playerid, Player[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(playerid, Float:HpAmount) return Player[playerid][Health] = HpAmount;
SetPlayerArmorEx(playerid, Float:ArmorAmount) return Player[playerid][Armor] = ArmorAmount;
Re: Server Sided Health/Armour Functions. -
SkyFlare - 01.07.2020
Quote:
Originally Posted by SharpenBlade
Well, then I think your code could work.
PHP Code:
GetPlayerHealthEx(playerid) return Player[playerid][Health];
GetPlayerArmorEx(playerid) return Player[playerid][Armor];
SetPlayerHealthEx(playerid, Float:HpAmount) return Player[playerid][Health] = HpAmount;
SetPlayerArmorEx(playerid, Float: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(playerid, healthdying);
Re: Server Sided Health/Armour Functions. -
SharpenBlade - 01.07.2020
Quote:
Originally Posted by SkyFlare
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(playerid, healthdying);
|
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
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
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:
SetPlayerArmourEx( playerid, Float:armour ) {
PlayerInfo[ playerid ] [ pArmor ] = armour;
return SetPlayerArmour( playerid, PlayerInfo[ playerid ] [ pArmor ] );
}
GetPlayerArmourEx( playerid, &Float:armour ) {
return PlayerInfo[ playerid ] [ 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