Using a player array in switch statement - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Using a player array in switch statement (
/showthread.php?tid=524309)
Using a player array in switch statement -
Garr - 06.07.2014
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.
Re: Using a player array in switch statement -
RedFusion - 06.07.2014
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:
}
Re: Using a player array in switch statement -
RedFusion - 06.07.2014
doublepost..
Re: Using a player array in switch statement -
Garr - 06.07.2014
How do I loop through the for with the array I have though?
Re: Using a player array in switch statement -
RedFusion - 06.07.2014
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