/god can be enabled, but cannot be disabled.
#1

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!");
    }
}
Reply
#2

Код:
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!");
    }
}
Reply
#3

Only booleans can be checked like that ! (true, false, 0, 1)
Use == 1 || == 0 here.
Reply
#4

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

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!");
    }
Reply
#6

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
pawn Код:
if(God[playerid])
if it's true and
pawn Код:
if(!God[playerid])
if it's false.
Reply
#7

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
pawn Код:
if(!God[playerid])
and it will work just fine!
Reply
#8

So, "!" means negative?
Reply
#9

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

Quote:
Originally Posted by LeeXian99
Посмотреть сообщение
So, "!" means negative?
Sort of, but not really, kind of? Depends how you look at it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)