SA-MP Forums Archive
infinity health variable issue - 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: infinity health variable issue (/showthread.php?tid=533455)



infinity health variable issue - HeLiOn_PrImE - 24.08.2014

hey, guys, I made a god command which looks kind of like this:
(I stored the player's current health so the command won'g get abused)

PHP код:
YCMD:god(playeridparams[], help)
{
    if(
godmode[playerid]==false)
    {
        
godmode[playerid]=true;
        
ResetPlayerWeapons(playerid);
        
GetPlayerHealth(playeridphealth[playerid]);
        
GetPlayerArmour(playeridparmor[playerid]);
        
SetPlayerHealth(playerid0x7F800000);
    }
    else
    {
        
godmode[playerid]=false;
        
SetPlayerHealth(playeridphealth[playerid]);
        
SetPlayerArmour(playeridparmor[playerid]);
    }
    return 
1;

The problem is, everytime I connect to my server, and type /god for the first time, I die.
After that first time, it works as it should. Does anyone know how can I solve this?


Re: infinity health variable issue - nmader - 24.08.2014

pawn Код:
SetPlayerHealth(playerid, 0x7F800000);
Why are you using a hex, matter of mistake? This should be a float, not a color.


Re: infinity health variable issue - zT KiNgKoNg - 24.08.2014

Quote:
Originally Posted by nmader
Посмотреть сообщение
pawn Код:
SetPlayerHealth(playerid, 0x7F800000);
Why are you using a hex, matter of mistake? This should be a float, not a color.
You're correct, but why not trying helping him out by providing something.

Try this on for size.
pawn Код:
#define  INFINITY (Float:0x7F800000)



Re: infinity health variable issue - SanAndreasMP - 24.08.2014

pawn Код:
YCMD : god ( playerid , params [], help )
{
    if( godmode[ playerid ]== false)
{
godmode[ playerid ]= true ;
ResetPlayerWeapons ( playerid );
GetPlayerHealth ( playerid , phealth[ playerid ]);
GetPlayerArmour ( playerid , parmor[ playerid ]);
SetPlayerHealth ( playerid , 1000000);
}
else
{
godmode[ playerid ]= false;
SetPlayerHealth ( playerid , phealth[ playerid ]);
SetPlayerArmour ( playerid , parmor[ playerid ]);
}
return 1 ;
}
Try this.


Re: infinity health variable issue - HeLiOn_PrImE - 24.08.2014

either 0x7F800000 or 1000000 it's the same result. I get the godmode if I place it on the player spawn. I will get godmode, but the first time I type the command I will get killed.


Re: infinity health variable issue - mamorunl - 24.08.2014

Looks like it goes into the else statement the first time then. Do you set the godmode[playerid] on connect?


Re: infinity health variable issue - HeLiOn_PrImE - 24.08.2014

Yes I did, actually. It's irrelevant. If I am already god, I will die at the first command.
EDIT: Solved

Like I said above, I created a variable phealth in which I stored the player's current health. In that case if a coward had in mid to escape by using /god, his health and armor would be restored upon deactivating.
The problem was, I didn't set the value to 100 on connection, so it was automatically set to 0. That's why I kept dying the 1st time, because the second time, phealth got the correct value.

If anyone tries this sort of thing from now on, keep this in mind! Thank you for your help, guys!


Re: infinity health variable issue - mamorunl - 24.08.2014

Yes, because it did not save your health. So the health variable is set to 0.