How can I do that?
#1

Hello guys.

I have a command /reports only for admins. It shows all the reports submitted by players. I use for something like this:
Код:
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;
}
My question is, how can I make each row to be a different color? Like in this pictures: https://i.imgur.com/6BZU6Jo.png

example
Код:
row 1 - color A
	row 2 - color B
	row 3 - color A
	row 4 - color B
Reply
#2

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 Код:
if(i==3) SendClientMessage(playerid, COLOR_RED);
Reply
#3

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
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 Код:
if(i==3) SendClientMessage(playerid, COLOR_RED);
like this?

Код:
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;
}
Reply
#4

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);
	    }
    }
Reply
#5

Quote:
Originally Posted by MEW273
Посмотреть сообщение
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);
	    }
    }
And if there are 2+ numbers odd or even the color of the report will be the same like the one,two,three before.
Reply
#6

You cannot rely on i as a report may or may not be valid according to what you said. So you will need a counter variable.

pawn Код:
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);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)