SA-MP Forums Archive
which specifier in sscanf - 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: which specifier in sscanf (/showthread.php?tid=569584)



which specifier in sscanf - saffierr - 31.03.2015

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.


Re: which specifier in sscanf - Vince - 31.03.2015

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.


Re: which specifier in sscanf - Crayder - 31.03.2015

Код:
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;
}



Re: which specifier in sscanf - saffierr - 31.03.2015

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.


Re: which specifier in sscanf - Crayder - 31.03.2015

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.


Re: which specifier in sscanf - saffierr - 31.03.2015

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!!!


Re: which specifier in sscanf - saffierr - 31.03.2015

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