'If' Statement not being called
#1

If I log in before spawning, then one of the checks will not run. If I spawn, then login, there is no conflict. I've stared at the code for about 3 hours, trying various possibilities to which they have all failed.

OnPlayerSpawn code:
pawn Код:
if(iRoundStarted == false)
{
        SendClientMessage(playerid, COLOR_NOTICE, "[NOTICE]: The current round has not started yet, please wait for it to do so.");
        TogglePlayerSpectating(playerid, true);
        PlayerSpectatePlayer(playerid, playerid);
        return 1;
}
// -- Code will stop here -- //
if(GetPVarInt(playerid, "NextVehicle") != 0)
{
        SetPVarInt(playerid, "Vehicle", CreateVehicle(GetPVarInt(playerid, "NextVehicle"), SumoSpawns[iMap][playerid][0], SumoSpawns[iMap][playerid][1], SumoSpawns[iMap][playerid][2], SumoSpawns[iMap][playerid][3], -1, -1, 10000));
        SetPVarInt(playerid, "NextVehicle", 0);
}
else
{
        SetPVarInt(playerid, "Vehicle", CreateVehicle(SumoModels[random(sizeof(SumoModels))],        SumoSpawns[iMap][playerid][0], SumoSpawns[iMap][playerid][1], SumoSpawns[iMap][playerid][2], SumoSpawns[iMap][playerid][3], -1, -1, 10000));
}
SetPVarInt(playerid, "Spawned", 1);
SetPlayerColor(playerid, COLOR_GREEN);
SetPlayerScore(playerid, 0);
PutPlayerInVehicle(playerid, GetPVarInt(playerid, "Vehicle"), 0);
return 1;
The login command:
pawn Код:
if(!strcmp(cmdtext, "/login", true))
{
        if(GetPVarInt(playerid, "Logged") == 1) return SendClientMessage(playerid, COLOR_RED, "Error: You are already logged in.");
        format(file, sizeof(file), "Sumo/%s.ini", PlayerName(playerid));
        if(!fexist(file)) SendClientMessage(playerid, COLOR_RED, "Error: Your username is not registered. Use (\"/register\") to register.");
        else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account", "Please insert your password below and click \"Submit\".\n\nTo cancel, click \"Cancel\"", "Submit", "Cancel");
        return 1;
}
Dialog response code for Login
pawn Код:
case DIALOG_LOGIN:
{
    format(file, sizeof(file), "Sumo/%s.ini", PlayerName(playerid));
    open_file = fopen(file, io_read);
    fread(open_file, str);
    new key[50];
    key = ini_GetKey(str);
    if(!strcmp(key, "Password", true))
        {
                new p[50];
        p = ini_GetValue(str);
        strmid(Pass[playerid], p, 0, strlen(p)-2, 255);
        if(!strcmp(Pass[playerid], encrypt(inputtext), true))
        {
                  while(fread(open_file, str))
              {
                            key = ini_GetKey(str);
                    if(!strcmp(key, "Money", true))
                    {
                         GivePlayerMoney(playerid, strval(ini_GetValue(str)));
                     }
               }
               SendClientMessage(playerid, COLOR_GREEN, "Successfully logged in.");
               SetPVarInt(playerid, "Logged", 1);
               fclose(open_file);
               return 1;
           }
               SendClientMessage(playerid, COLOR_RED, "Error: Incorrect password.");
    }
    fclose(open_file);
}
Every thing loads correctly from the file. At first, I thought it was a PVar screw up of some how, but after clearing all variables and a lot of debugging, I found that wasn't the problem. I then checked if it was only that if statement that didn't check, and I was right. The following code printed.
pawn Код:
new x = 3;
if(x == 3) { print("hi"); }
else { print("bye"); }
It was placed under the OnPlayerSpawn. I checked and it printed correctly, depending on which value I set X to.

So the only thing I can figure now is that there is something with that if statement. I honestly have no idea what COULD be wrong, but I might be overlooking something.

Any suggestions are welcomed, and very much appreciated.
Reply
#2

Quote:
Originally Posted by Grim_
Посмотреть сообщение
If I log in before spawning, then one of the checks will not run. If I spawn, then login, there is no conflict. I've stared at the code for about 3 hours, trying various possibilities to which they have all failed.

OnPlayerSpawn code:
pawn Код:
if(iRoundStarted == false)
{
        SendClientMessage(playerid, COLOR_NOTICE, "[NOTICE]: The current round has not started yet, please wait for it to do so.");
        TogglePlayerSpectating(playerid, true);
        PlayerSpectatePlayer(playerid, playerid);
        return 1;
}
// -- Code will stop here -- //
if(GetPVarInt(playerid, "NextVehicle") != 0)
{
        SetPVarInt(playerid, "Vehicle", CreateVehicle(GetPVarInt(playerid, "NextVehicle"), SumoSpawns[iMap][playerid][0], SumoSpawns[iMap][playerid][1], SumoSpawns[iMap][playerid][2], SumoSpawns[iMap][playerid][3], -1, -1, 10000));
        SetPVarInt(playerid, "NextVehicle", 0);
}
else
{
        SetPVarInt(playerid, "Vehicle", CreateVehicle(SumoModels[random(sizeof(SumoModels))],        SumoSpawns[iMap][playerid][0], SumoSpawns[iMap][playerid][1], SumoSpawns[iMap][playerid][2], SumoSpawns[iMap][playerid][3], -1, -1, 10000));
}
SetPVarInt(playerid, "Spawned", 1);
SetPlayerColor(playerid, COLOR_GREEN);
SetPlayerScore(playerid, 0);
PutPlayerInVehicle(playerid, GetPVarInt(playerid, "Vehicle"), 0);
return 1;
There is a return in the first loop so of course it would stop there...
Reply
#3

There is no loop, only another statement.

And I'm aware, I used print after that statement. (Note where the "Code will stop here" is)
Reply
#4

Okay, after a lot more debugging and pulling of my hair, I've found out the problem - but not a solution.

For some reason, the variable in my script "iMap" is being increased at an unknown value for unknown reasons. The only time the variable is updated is when a map ends, which is only called when a players wins the game, which didn't happen. After about 30 seconds on the server, the iMap variable was set to 65.

Any reports of variables being set to random values? (When I declare the variable, I set it to '0' ( new iMap=0; ))
Reply
#5

Try using the other method of doing vaiables, SetPVarInt is kinda buggy, classic is better
Reply
#6

@The_Moddler: I haven't had a problem with PVars and there are currently no bug reports about them.

Anyway, I found the actual line where the value of 'iMap' is jumping from 0 to 65, it's this line:
pawn Код:
strmid(Pass[playerid], p, 0, strlen(p)-2, 255);
Which is..weird since iMap is not used anywhere near the function, and especially isn't in either of the arrays that are being extracted/filled.
Reply
#7

I have fixed the whole problem that has occurred. It seems using the last argument in the strmid function caused the changing of the variable, which in turn, screwed the rest of the script up.

I'm still clueless as to why one argument in a function would change a variable value, that has absolutely nothing to do with it. However, I'm glad I fixed it and if anyone else has this major problem, they will be able to fix it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)