Sscanf cmd
#1

Hello,

I want to make a cmd like this:
if(!sscanf(params,"s[16]s[16]s[16]d",action[0],action[1],action[2],amount))

But, for example when action 2 and amount isn't inserted I still want to proceed the cmd
So it will be like:

Код:
if(!sscanf(params,"s[16]s[16]s[16]d",action[0],action[1],action[2],amount))
{
	if(strcmp("open",action[0], true ) == 0)
	{
	
	}
	else if(strcmp("close",action[0], true ) == 0)
	{

	}
	if(strcmp("store",action[0], true ) == 0)
	{
		if(strcmp("weapon",action[1], true ) == 0)
		{

		}
	}
}
Something like this, but this doesnt work because when I only use /trunk open
I have to insert something at the others.


[/code]
Reply
#2

try like this :
pawn Код:
if(sscanf(params,"s[16]s[16]s[16]d",action[0],action[1],action[2],amount)) return SendClientMessage(playerid, -1, "Incorrect format.");
Reply
#3

show where you define this
action[]
Reply
#4

Quote:
Originally Posted by MarkoN
Посмотреть сообщение
try like this :
pawn Код:
if(sscanf(params,"s[16]s[16]s[16]d",action[0],action[1],action[2],amount)) return SendClientMessage(playerid, -1, "Incorrect format.");
This won't work when i only use /trunk store
it only works when I use /trunk store materials A 5000
for example.
Reply
#5

NVM, I fixed it on this way:

Код:
COMMAND:trunk(playerid, params[])
{
	new action[3][16],amount;
	sscanf(params,"s[16]s[16]s[16]d",action[0],action[1],action[2],amount);
	if(strlen(action[0]) && strcmp("store",action[0], true ) == 0)
	{
	    for(new slot = 0; slot < 5; slot++) if(slot == 0) break;
		if(strlen(action[1]) && strcmp("weapon",action[1], true ) == 0)
		{
	    }
	    if(strlen(action[1]) && strcmp("briefcase",action[1], true ) == 0)
		{
	    }
	    if(strlen(action[1]) && strcmp("materials",action[1], true ) == 0)
		{
		    if(strlen(action[2]) && strcmp("A",action[2], true ) == 0)
		    {
		        if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store materials A (amount > 0 < 50)");
		        
		    }
		    else if(strlen(action[2]) && strcmp("B",action[2], true ) == 0)
		    {
                if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store materials D (amount > 0 < 50)");
                
		    }
		    else if(strlen(action[2]) && strcmp("C",action[2], true ) == 0)
		    {
                if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store materials C (amount > 0 < 50)");
                
		    }
		    else if(strlen(action[2]) && strcmp("D",action[2], true ) == 0)
		    {
                if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store materials D (amount > 0 < 50)");
                
		    }
		    else return SendPlayerError(playerid,"Usage: /trunk store materials (A,B,C,D)");
	    }
	    if(strlen(action[1]) && strcmp("drugs",action[1], true ) == 0)
		{
		    if(strlen(action[2]) && strcmp("A",action[2], true ) == 0)
		    {
		        if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store drugs A (amount > 0 < 50)");

		    }
		    else if(strlen(action[2]) && strcmp("B",action[2], true ) == 0)
		    {
                if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store drugs D (amount > 0 < 50)");

		    }
		    else if(strlen(action[2]) && strcmp("C",action[2], true ) == 0)
		    {
                if(amount < 1 || amount > 50) return SendPlayerError(playerid,"Usage: /trunk store drugs C (amount > 0 < 50)");

		    }
		    else return SendPlayerError(playerid,"Usage: /trunk store drugs (A,B,C)");
	    }
	    else return SendPlayerError(playerid,"Usage: /trunk store (weapon,briefcase,materials,drugs).");
	}
 	if(strlen(action[0]) && strcmp("take",action[0], true ) == 0)
	{
	    new slot;
	  	if(sscanf(action[1],"%d",slot)) return SendPlayerError(playerid,"Usage: /trunk take (slot 0,1,2,3,4).");
	  	if(slot < 0 && slot > 4) return SendPlayerError(playerid,"Usage: /trunk take (slot 0,1,2,3,4).");
	}
	else if(strlen(action[0]) && strcmp("open",action[0], true ) == 0)
	{


	}
	else if(strlen(action[0]) && strcmp("close",action[0], true ) == 0)
	{



	}
	else return SendPlayerError(playerid,"Usage: /trunk (open - close - search - take - store)");
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)