/god can be enabled, but cannot be disabled. -
LeeXian99 - 26.03.2013
What happened to this script actually?
pawn Код:
CMD:god(playerid,params[])
{
if(God[playerid])
{
SetPlayerHealth(playerid, 100000.0);
God[playerid] = 1;
return SendClientMessage(playerid, yellow, "Godmode has been enabled!");
}
else
{
God[playerid] = 0;
SetPlayerHealth(playerid, 100.0);
return SendClientMessage(playerid, red, "Godmode has been disabled!");
}
}
Re: /god can be enabled, but cannot be disabled. -
rbush12 - 26.03.2013
Код:
CMD:god(playerid,params[])
{
if(God[playerid] == 0)
{
SetPlayerHealth(playerid, 100000.0);
God[playerid] = 1;
return SendClientMessage(playerid, yellow, "Godmode has been enabled!");
}
else if(God[playerid] == 1)
{
God[playerid] = 0;
SetPlayerHealth(playerid, 100.0);
return SendClientMessage(playerid, red, "Godmode has been disabled!");
}
}
Re: /god can be enabled, but cannot be disabled. -
RajatPawar - 26.03.2013
Only booleans can be checked like that ! (true, false, 0, 1)
Use == 1 || == 0 here.
Re: /god can be enabled, but cannot be disabled. -
glbracer - 26.03.2013
Also, sometimes for variables like God[playerid] it will set it then go on to perform the next. This happens because Pawn executes the code in the order it's written in. Put return 1; at the end of both if statements, that'll stop it from running through all if statements at once, it'll find the appropriate if statement, then call it, and it won't search the rest.
Re: /god can be enabled, but cannot be disabled. -
LeeXian99 - 26.03.2013
Oh well, my fault, but thanks for correcting me.
pawn Код:
{
if(God[playerid] == false)
{
SetPlayerHealth(playerid, 100000.0);
God[playerid] = true;
return SendClientMessage(playerid, yellow, "Godmode has been enabled!");
}
else
if(God[playerid] == true)
{
God[playerid] = false;
SetPlayerHealth(playerid, 100.0);
return SendClientMessage(playerid, red, "Godmode has been disabled!");
}
Re: /god can be enabled, but cannot be disabled. -
glbracer - 26.03.2013
pawn Код:
{
if(God[playerid] == false)
{
SetPlayerHealth(playerid, 100000.0);
God[playerid] = true;
return SendClientMessage(playerid, yellow, "Godmode has been enabled!");
}
else
if(God[playerid] == true)
{
God[playerid] = false;
SetPlayerHealth(playerid, 100.0);
return SendClientMessage(playerid, red, "Godmode has been disabled!");
}
That's incorrect, for one you have a random 'else' statement, and second if it's a boolean variable (as told by a bool: tag in front of it) then you don't need '== true' or '== false'. Simply do
if it's true and
if it's false.
Re: /god can be enabled, but cannot be disabled. -
Konstantinos - 26.03.2013
It's not necessary to be boolean to use if(!something) or if(something)
Quote:
Originally Posted by LeeXian99
What happened to this script actually?
pawn Код:
CMD:god(playerid,params[]) { if(God[playerid]) { SetPlayerHealth(playerid, 100000.0); God[playerid] = 1; return SendClientMessage(playerid, yellow, "Godmode has been enabled!"); } else { God[playerid] = 0; SetPlayerHealth(playerid, 100.0); return SendClientMessage(playerid, red, "Godmode has been disabled!"); } }
|
Your code does work like this:
if god for the playerid is 1, then set it to 1. So, it's not possible to be 0 unless you disconnect.
Just change the 3rd line to
and it will work just fine!
Re: /god can be enabled, but cannot be disabled. -
LeeXian99 - 26.03.2013
So, "!" means negative?
Re: /god can be enabled, but cannot be disabled. -
Konstantinos - 26.03.2013
Quote:
Originally Posted by LeeXian99
So, "!" means negative?
|
No, not really.
pawn Код:
if(!God[playerid]) print("It's 0!");
// checks if the variable's value is 0 and if it is, then it will print the message.
Re: /god can be enabled, but cannot be disabled. -
glbracer - 26.03.2013
Quote:
Originally Posted by LeeXian99
So, "!" means negative?
|
Sort of, but not really, kind of? Depends how you look at it.