Variables
#1

Hey, I've been struggling with this lately; The problem is in the corner, but seems like I can't fix it.

PHP код:
for(new 0GetPlayerPoolSize(); <= ji++)
                {
                    if(
PlayerInfo[i][Test] != && PlayerInfo[i][TestOK] < 2)
                    {
                        
SCM(playeridCOLOR_RED"Error: No Tests are online.");
                        return 
1;
                    }
                    else
                    {
                        
SCM(playeridCOLOR_YELLOW"Test request has been sent.");
                        
format(stringsizeof string"~ %s requested a Test!"PlayerName(playerid));
                        
SendTestMessage(-1string);
                    }
                    
Testrequest[playerid] = 1;
                } 
Whenever there are no players who have 'Test 1, TestOK 2 or higher' I want the error message to be displayed.
However, when a player has 'Test 2 && TestOK 2 or higher' the error message isn't displayed. I hope it was understandable.
Reply
#2

You have to let the loop finish first and then return an error if none was online.
Reply
#3

Hmm, the only way I can think of is, formatting the message inside the loop and sending it outside the loop, However that isn't working either. Do you have another way to do it?
Reply
#4

I don't see using "i" anywhere so the message can be formatted outside. Unless you wrote "playerid" by accident.

pawn Код:
new bool: test_found;

for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
    if (PlayerInfo[i][Test] != 1 && PlayerInfo[i][TestOK] < 2) continue;

    test_found = true;

    break;
}

if (!test_found) SCM(playerid, COLOR_RED, "Error: No Tests are online.")
else
{
    SCM(playerid, COLOR_YELLOW, "Test request has been sent.");
    format(string, sizeof string, "~ %s requested a Test!", PlayerName(playerid));
    SendTestMessage(-1, string);

    Testrequest[playerid] = 1;
}
Reply
#5

Your code renders the same as my code. Player can request when there's no: "Test 1 && TestOK > 2".

There must be something else...
Reply
#6

Am I getting it wrong, or is just replacing && with || the solution?
EDIT: in Konstantinos's code
Reply
#7

Quote:
Originally Posted by Amads
Посмотреть сообщение
Am I getting it wrong, or is just replacing && with || the solution?
EDIT: in Konstantinos's code
I guess you didn't quite comprehend what the code should do, because if I use || it won't be displaying the Error message when there's someone online with: "Test 2 and TestOK 3", Where as I want the error message to be displayed just when there are no "Test 1 and TestOK 2 or higher" online.

And yes, I know the story is quite to be confusing.
Reply
#8

Anyone?
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I don't see using "i" anywhere so the message can be formatted outside. Unless you wrote "playerid" by accident.

pawn Код:
new bool: test_found;

for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
    if (PlayerInfo[i][Test] != 1 && PlayerInfo[i][TestOK] < 2) continue;

    test_found = true;

    break;
}

if (!test_found) SCM(playerid, COLOR_RED, "Error: No Tests are online.")
else
{
    SCM(playerid, COLOR_YELLOW, "Test request has been sent.");
    format(string, sizeof string, "~ %s requested a Test!", PlayerName(playerid));
    SendTestMessage(-1, string);

    Testrequest[playerid] = 1;
}
Oh wait... This actually works, I forgot to upload the new .amx. Thanks.
Reply
#10

Quote:
Originally Posted by saffierr
Посмотреть сообщение
Oh wait... This actually works, I forgot to upload the new .amx. Thanks.
You'll have to use IsPlayerConnected to loop through connected players only. In case if you're not resetting arrays over disconnection, it can lead to misconception.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)