CMD:reports(playerid, params) {
for(new i; i < MAX_REPORTS; ++i)
{
if(Reports[i][reportValide]) {
format(string, sizeof(string), "Report: %s", Reports[i][reportDetails]);
SCM(playerid, COLOR_BLUE, string);
}
}
return 1;
}
row 1 - color A row 2 - color B row 3 - color A row 4 - color B
if(i==3) SendClientMessage(playerid, COLOR_RED);
|
Use the `i` as an indicator to the current stage and conditional statement to know what i equals to, if it equals to any i, make it send the message with the color formatted in HEX between {}
Something like so pawn Код:
|
CMD:reports(playerid, params) {
for(new i; i < MAX_REPORTS; ++i)
{
if(Reports[i][reportValide]) {
format(string, sizeof(string), "Report: %s", Reports[i][reportDetails]);
if(i==0) SCM(playerid, COLOR_YELLOW, string);
if(i==1) SCM(playerid, COLOR_BLUE, string);
if(i==2) SCM(playerid, COLOR_YELLOW, string);
if(i==3) SCM(playerid, COLOR_BLUE, string);
}
}
return 1;
}
#define IsOdd(%0) %0 % 2 //checks if a number is odd
for(new i; i < MAX_REPORTS; ++i)
{
if(Reports[i][reportValide])
{
format(string, sizeof(string), "Report: %s", Reports[i][reportDetails]);
if(IsOdd(i)) SCM(playerid, COLOR_YELLOW, string);
else SCM(playerid, COLOR_BLUE, string);
}
}
|
The above is one method, however, I believe it would be quite inefficient with all the if statements.
How I would do it is by checking if your loop 'i' is odd, and using that condition to set the color, see below: Код:
#define IsOdd(%0) %0 % 2 //checks if a number is odd
for(new i; i < MAX_REPORTS; ++i)
{
if(Reports[i][reportValide])
{
format(string, sizeof(string), "Report: %s", Reports[i][reportDetails]);
if(IsOdd(i)) SCM(playerid, COLOR_YELLOW, string);
else SCM(playerid, COLOR_BLUE, string);
}
}
|
new counter = -1;
for (new i; i < MAX_REPORTS; ++i)
{
if (Reports[i][reportValide])
{
string = "Report: ";
strcat(string, Reports[i][reportDetails]);
SCM(playerid, ++counter % 2 ? COLOR_BLUE : COLOR_YELLOW, string);
}
}