Variables -
saffierr - 24.12.2016
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 i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(PlayerInfo[i][Test] != 1 && PlayerInfo[i][TestOK] < 2)
{
SCM(playerid, COLOR_RED, "Error: No Tests are online.");
return 1;
}
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;
}
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.
Re: Variables -
Konstantinos - 24.12.2016
You have to let the loop finish first and then return an error if none was online.
Re: Variables -
saffierr - 24.12.2016
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?
Re: Variables -
Konstantinos - 24.12.2016
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;
}
Re: Variables -
saffierr - 24.12.2016
Your code renders the same as my code. Player can request when there's no: "Test 1 && TestOK > 2".
There must be something else...
Re: Variables -
Amads - 24.12.2016
Am I getting it wrong, or is just replacing && with || the solution?
EDIT: in Konstantinos's code
Re: Variables -
saffierr - 24.12.2016
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.
Re: Variables -
saffierr - 25.12.2016
Anyone?
Re: Variables -
saffierr - 26.12.2016
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.
Re: Variables -
Lordzy - 26.12.2016
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.