SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 01/07/2020, 09:57 AM   #1
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Server Sided Health/Armour Functions.

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.
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs

Last edited by SkyFlare; 01/07/2020 at 10:32 AM.
SkyFlare is offline   Reply With Quote
Old 01/07/2020, 10:05 AM   #2
SharpenBlade
Huge Clucker
 
Join Date: May 2020
Posts: 202
Reputation: 25
Default Re: Server Sided Health/Armour Functions.

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
SharpenBlade is offline   Reply With Quote
Old 01/07/2020, 10:14 AM   #3
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Re: Server Sided Health/Armour Functions.

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.
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 01/07/2020, 10:24 AM   #4
SharpenBlade
Huge Clucker
 
Join Date: May 2020
Posts: 202
Reputation: 25
Default Re: Server Sided Health/Armour Functions.

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
SharpenBlade is offline   Reply With Quote
Old 01/07/2020, 10:26 AM   #5
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Re: Server Sided Health/Armour Functions.

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); 
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 01/07/2020, 11:32 AM   #6
SharpenBlade
Huge Clucker
 
Join Date: May 2020
Posts: 202
Reputation: 25
Default Re: Server Sided Health/Armour Functions.

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
SharpenBlade is offline   Reply With Quote
Old 01/07/2020, 11:37 AM   #7
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Re: Server Sided Health/Armour Functions.

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
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 01/07/2020, 12:40 PM   #8
SharpenBlade
Huge Clucker
 
Join Date: May 2020
Posts: 202
Reputation: 25
Default Re: Server Sided Health/Armour Functions.

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.
SharpenBlade is offline   Reply With Quote
Old 01/07/2020, 02:14 PM   #9
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Re: Server Sided Health/Armour Functions.

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.
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 01/07/2020, 02:23 PM   #10
ShadowMortar
Huge Clucker
 
ShadowMortar's Avatar
 
Join Date: Jul 2016
Location: Croatia
Posts: 303
Reputation: 109
Default Re: Server Sided Health/Armour Functions.

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 
__________________
If you appreciate(d) my help, I will appreciate +REP .

Quote:
Originally Posted by CheezIt View Post
Follow your heart and own style.
Feel free to PM me if you need help.
Quote:
Originally Posted by Pottus View Post
That is perfectly fine, I'm just pointing out where you made mistakes what does hearing "good job" get you? Absolutely nothing. You need to hear the problems otherwise you'll keep making the same mistakes
ShadowMortar 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
Server sided health/custom damage. JamesT85 Scripting Help 2 07/07/2018 12:33 PM
Server sided health. iLearner Scripting Help 3 20/02/2017 11:46 AM
Server sided health & armour NeXoR Scripting Help 2 30/10/2016 11:46 AM
server-sided health problem. Crystallize Scripting Help 5 26/05/2016 11:36 PM
[Include] Advanced Server Side Health/Armour VSM Includes 22 07/05/2014 03:54 PM


All times are GMT. The time now is 03:35 AM.


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