SA-MP Forums Archive
Some noob questions. :) - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Some noob questions. :) (/showthread.php?tid=128684)



Some noob questions. :) - enkei - 19.02.2010

Код:
SetPlayerTeamFromClass(playerid, classid)
{
	if (classid == 105)
	{
		gTeam[playerid] = TeamGrovest;
This sets class 105 as a member of TeamGrovest. But there are 3 availible classes that all need to be in TeamGrovest. Instead of making three "if's" can i just make one "if" like this?

Код:
SetPlayerTeamFromClass(playerid, classid)
{
	if (classid == 105,106,107)
	{
		gTeam[playerid] = TeamGrovest;
Can i just seperate the three classes by commas? (105,106,107)? Or do they need to all have seperate IF statements?




Re: Some noob questions. :) - Miguel - 19.02.2010

If you're gonna use "if" you'll need to do it like this:
pawn Код:
if(classid == 105 || classid == 106 || classid == 107)
But wait, there's an easier way!
pawn Код:
SetPlayerTeamFromClass(playerid, classid)
{
  switch(classid)
  {
    case 105, 106, 107:
    {
     // code
    }
    case 108:
    {
      // code for if(classid == 108)
    }
    case 109 .. 120: // this mean from 109 to 120 (if (classid == 109 || classif == 110...)
    {
      // code
    }
    default: // this is "else"
    {
      // code
    }
  }
  return 1;
}
I'd do it like:

pawn Код:
SetPlayerTeamFromClass(playerid, classid)
{
  switch(classid)
  {
    case 105 .. 107: gTeam[playerid] = TeamGrovest;
  }
  return 1;
}



Re: Some noob questions. :) - enkei - 19.02.2010

Ok, thanks SAWC.

Another noob question. I want each gang (Grove, Balla, Triad, Vagos) to have their own gang color. (Both blips AND name in chat screen).

I have it like this..

Код:
#define TeamGrovest 1
#define TeamBallas 2
#define TeamVagos 3
#define TeamTriads 4
#define TeamGrovestColor 0x339900AA
#define TeamBallasColor 0xAF00FFAA
#define TeamVagosColor 0xBF00FFAA
#define TeamTriadsColor 0xCF00FFAA   //these are just random colors for testing. I'll change them later.
Then, down some..
Код:
SetPlayerTeamFromClass(playerid, classid)
{
	{
  	if(classid == 105 || classid == 106 || classid == 107)

			gTeam[playerid] = TeamGrovest;
	}
	{
  	if(classid == 102 || classid == 103 || classid == 104)

			gTeam[playerid] = TeamBallas;
	}
	{
  	if(classid == 108 || classid == 109 || classid == 110)

			gTeam[playerid] = TeamVagos;
	}
	{
  	if(classid == 117 || classid == 118 || classid == 120)

			gTeam[playerid] = TeamTriads;
	}
}

SetPlayerToTeamColor(playerid)
{
	if (gTeam[playerid] == TeamGrovest)
	{
		SetPlayerColor(playerid, TeamGrovestColor);
	}
	else if (gTeam[playerid] == TeamBallas)
	{
		SetPlayerColor(playerid, TeamBallasColor);
	}
	else if (gTeam[playerid] == TeamVagos)
	{
		SetPlayerColor(playerid, TeamVagosColor);
	}
	else if (gTeam[playerid] == TeamTriads)
	{
		SetPlayerColor(playerid, TeamTriadsColor);
	}
}



And, under OnPlayerSpawn, i run my function. I cant see why it wouldnt work..


Re: Some noob questions. :) - enkei - 20.02.2010

just a bump.. gotta fix this issue.


Re: Some noob questions. :) - VonLeeuwen - 20.02.2010

Change this:
Код:
#define TeamGrovestColor 0x339900AA
#define TeamBallasColor 0xAF00FFAA
#define TeamVagosColor 0xBF00FFAA
#define TeamTriadsColor 0xCF00FFAA
To this:

Код:
#define TeamGrovestColor 0x33990099
#define TeamBallasColor 0xAF00FF99
#define TeamVagosColor 0xBF00FF99
#define TeamTriadsColor 0xCF00FF99
I am not sure if it works, but I use the same function, this is the only thing which is different.


Re: Some noob questions. :) - enkei - 20.02.2010

Thanks but it didnt work =( All the colors are orange. No matter what team i choose.


Re: Some noob questions. :) - VonLeeuwen - 20.02.2010

I am not sure if this works, but I have read this somewhere, add 'return 1;', so it'll be like this:

Код:
SetPlayerToTeamColor(playerid)
{
	if (gTeam[playerid] == TeamGrovest)
	{
		SetPlayerColor(playerid, TeamGrovestColor);
	}
	else if (gTeam[playerid] == TeamBallas)
	{
		SetPlayerColor(playerid, TeamBallasColor);
	}
	else if (gTeam[playerid] == TeamVagos)
	{
		SetPlayerColor(playerid, TeamVagosColor);
	}
	else if (gTeam[playerid] == TeamTriads)
	{
		SetPlayerColor(playerid, TeamTriadsColor);
	}
return 1;
}



Re: Some noob questions. :) - enkei - 20.02.2010

Sigh.. That didnt work either. :/
Ive seen this in virtually EVERY server, so dont act like there isnt a way. Can someone experienced please help me? Im sure its something simple.

No matter what gang i choose, my color is orange.


Re: Some noob questions. :) - enkei - 21.02.2010

bump, again. Can i get some expert feedback here? Seems like a simple problem.


Re: Some noob questions. :) - enkei - 21.02.2010

Bump again. I've tried re-arranging my code, thinking maybe if one function was above another it may work. But it doesnt. My name is still orange. Supposed to be green. Seems like an easy fix. Can someone please take the time to help me?