It would be high appreciated
#3

Using sscanf is a very common thing to use along with ZCMD, and I would recommend it. If you don't already have it installed, you can download it here: https://sampforum.blast.hk/showthread.php?tid=120356.

I tried explaining why I had done what, if you need more explanation on it I can do so.

Code:
CMD:setcolor(playerid, params[])
{
	if (!IsPlayerAdmin(playerid)) SendClientMessage(playerid, -1, "SERVER: Unknown command.");
	else if (IsPlayerAdmin(playerid))
	{
		new iTargetID, iColor; //define the variables we want the data from the command going to (written after /setcolor in-game)
		if(sscanf(params, "ud", iTargetID, iColor)) 
		{
			SendClientMessage(playerid, -1, "USAGE: /setcolor [playerid] [color]"); //In sscanf, 'u' is a player id and 'd' is an integer
			SendClientMessage(playerid, -1, "Colors: 1 - Yellow, 2 - White, 3 - Red");
		}
		/* a switch statement is like multiple 'if' and 'else if' statements however compressed to look like this rather than  
		if(iColor == 1) iColor = 0xFFFF0000;
		if(iColor == 2) iColor = 0xFFFFFF00;
		if(iColor == 3) iColor = 0xFF0606FF;
		else iColor = 0xFFFFFF00;
		
		Just like if statements, brackets are optional if it is only 1 line.
		*/
		if(!IsPlayerConnected(iTargetID)) return SendClientMessage(playerid, -1, "The specified player is not connected.");
		switch(iColor)
		{
			case 1: iColor = 0xFFFF0000;
			case 2: iColor = 0xFFFFFF00;
			case 3: iColor = 0xFF0606FF;
			default: iColor = 0xFFFFFF00; //default will set the color as white if the number isnt 1, 2 or 3.
		}
		SetPlayerColor(iTargetID, iColor);
		SendClientMessage(playerid, COLOR_GREEN, "You succesfully changed the player his color.");
	}
	return 1;
}
Reply


Messages In This Thread
It would be high appreciated - by saffierr - 16.07.2014, 00:50
Re: It would be high appreciated - by Miguel - 16.07.2014, 01:27
Re: It would be high appreciated - by BlackSirrah239 - 16.07.2014, 01:30
Re: It would be high appreciated - by saffierr - 16.07.2014, 02:33
Re: It would be high appreciated - by amirab - 16.07.2014, 02:43
Re: It would be high appreciated - by Miguel - 16.07.2014, 02:50

Forum Jump:


Users browsing this thread: 4 Guest(s)