infinity health variable issue
#1

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

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

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)