which specifier in sscanf
#1

I went through the whole sscanf specifiers, and I just could not get which one I had to use, or not even.
The code is /setcolor
PHP код:
CMD:setcolor(playeridparams[])
{
   if(
IsPlayerAdmin(playerid))
   {
       
SetPlayerColor(playeridCOLOR_BLUE);
       
SendClientMessage(playeridCOLOR_LIME"You have set your colour.");
   }
       else
   {
       
SendClientMessage(playerid, -1"SERVER: Unknown command.");
   }
   return 
1;

It is just, when you type /setcolor it will turn MY color to blue. But How do I make it so, that if I type /setcolor it will display a message /setcolor [ID] [COLOR]. I didn't know which specifier I had to use in sscanf.
Reply
#2

u for user, h or x for a hexadecimal number. Although requesting raw hex colors isn't very user friendly. I would recommend letting the user choose from a list or preparing a pallet of swatches to choose from. Perhaps still keeping the raw input as a fallback.
Reply
#3

Код:
SSCANF:color(string[])
{
	static ColorName[6][] = 
	{
		{"Red"}, {"Orange"}, {"Yellow"}, {"Green"}, {"Blue"}, {"Purple"}
	};
	new ret = -1;
	for(new i = 0; i < 5; i++) if(strfind(ColorName[i], string, true) != -1)
	{
		ret = i;
		break;
	}
	switch (ret)
	{
		case 0: return COLOR_RED;
		case 1: return COLOR_ORANGE;
		case 2: return COLOR_YELLOW;
		case 3: return COLOR_GREEN;
		case 4: return COLOR_BLUE;
		case 5: return COLOR_PURPLE;
		default: return -1;
	}
}

CMD:setcolor(playerid, params[]) 
{ 
	if(!IsPlayerAdmin(playerid))
		return 0;
		
	new Target, Color;
	
	if(sscanf(params, "uk<color>", Target, Color))
		return SendClientMessage(playerid, -1, "Error: /setcolor [ID] [COLOR]");
	else if(Color == -1)	
		return SendClientMessage(playerid, -1, "Error: Color must be Red, Orange, Yellow, Green, Blue, or Purple.");
	
	else
	{
		SetPlayerColor(Target, Color); 
		
		SendClientMessage(playerid, COLOR_LIME, "You have a player's color."); 
		SendClientMessage(Target, COLOR_LIME, "An admin set your color."); 
	}
   	return 1;
}
Reply
#4

Ok appreciated guys, although I do not really understand what you meant Vince.

OFF: Eey je bent belgisch ehhe, ik nederlands, geef je skype dan.
Reply
#5

Quote:
Originally Posted by saffierr
Посмотреть сообщение
Ok appreciated guys, although I do not really understand what you meant Vince.

OFF: Eey je bent belgisch ehhe, ik nederlands, geef je skype dan.
I update my code, it now uses an SSCANF (k)custom specifier. You can add more colors to the list if you like.
Reply
#6

Yo Crayder it's really really high appreciated bro, I just get the Last part, I don't get the SSCANF part. I hope you could explain me that, through PM.
Thanks!!!
Reply
#7

Yeah I read that, but I just don't understand how to use it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)