Using a player array in switch statement
#1

So essentially, I have a command that displays the same dialog with options green depending on if the task has been finished, based on the values in the array.

new contract1[MAX_PLAYERS][3];
// 0 = option1
// 1 = option2
// 2 = option3

If 0 == 1, I want the first option in the dialog to be coloured green
if 1 == 1, I want the second option in the dialog to be coloured green
if 2 == 1, I want the third option to be colored green

Any number of these options can be green at the same but idk how to do it.

This is the command.
Код:
	if (strcmp("/contracts", cmdtext, true, 10) == 0)
	{
		if(IsPlayerInRangeOfPoint(playerid, 5.0, -138.5305,1075.0895,19.7422))
		{
			if(job[playerid] != 1)
			{
				SendClientMessage(playerid, -1, "You are not a trucker.");

			}
			else
			{

		    	ShowPlayerDialog(playerid, DIALOG_CONTRACT1, DIALOG_STYLE_LIST, "Contracts", "Jim Aarons\nStark Industries\nXen Records", "Select", "Close");
			}
		}
		else
		{
 			SendClientMessage(playerid, -1, "You're not at the delivery station!");
		}
		return 1;
I know I could do long multiple if-else statements to accomplish it, but I want to find out what the quickest, most sufficient way is.
Reply
#2

a for loop would pretty much do the same as the multiple if-else statements but looks more neat in my opinion. You could try that i guess.

Maybe it's better to do it like this?
pawn Код:
new contract1[MAX_PLAYERS];
switch(contract1[playerid])
{
case 0:
case 1:
case 2:
}
Reply
#3

doublepost..
Reply
#4

How do I loop through the for with the array I have though?
Reply
#5

pawn Код:
for(new i; i < 3; i ++)
{
    if(contract1[playerid][i] == 1)
    {
        // Put your code here
        break; // Stops the loop
    }
}
https://sampwiki.blast.hk/wiki/Loops
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)