Sub-commands Problem
#1

I've been trying to implement sub commands inside a command, I've tried using strcmp and strfind for it but they dont seem to work.
I'm using I-ZCMD, sscanf.

Код:
new cmd[128];
if(sscanf(params, "s[128]", cmd)) return SFM(playerid, COLOR_GREY, "[USAGE] vtrunk (option)"), SFM(playerid, COLOR_GREY, "[OPTIONS] view take put");
if(strfind(cmd, "view") == 0)
{
	new count = 0;
	SFM(playerid, COLOR_GREY, "Trunk Items");
	for(new x = 0; x < 5; x++)
	{
		//getitems pass = count++ and print else nothing
	}
	if(count == 0) SFM(playerid, COLOR_YELLOWGREEN, "No items found in trunk.");
	count = 0;
	SFM(playerid, COLOR_GREY, "Trunk Weapons");
	for(new x = 0; x < 5; x++)
	{
		//getweapons pass = count++ and print else nothing
	}
	if(count == 0) SFM(playerid, COLOR_YELLOWGREEN, "No weapons found in trunk.");
}
else if(strfind(cmd, "take") == 0)
{
	new cmdex[128];
	if(sscanf(cmd, "s[128]", cmdex)) return SFM(playerid, COLOR_GREY, "[USAGE] vtrunk take (weapon/item)");
	if(strfind(cmdex, "weapon") == 0)
	{
		SFM(playerid, COLOR_GREY, "Under Construction!");
	}
	else if(strfind(cmdex, "item") == 0)
	{
		//under construncton
	}
	else
	{
		SFM(playerid, COLOR_GREY, "[USAGE] vtrunk take (weapon/item)");
	}
}
else if(strfind(cmd, "put") == 0)
{
	new cmdex[128];
	if(sscanf(cmd, "s[128]", cmdex)) return SFM(playerid, COLOR_GREY, "[USAGE] vtrunk put (weapon/item)");
	if(strfind(cmdex, "weapon") == 0)
	{
		SFM(playerid, COLOR_GREY, "Under Construction!");
	}
	else if(strfind(cmdex, "item") == 0)
	{
		//under construncton
	}
	else
	{
		SFM(playerid, COLOR_GREY, "[USAGE] vtrunk take (weapon/item)");
	}
}
else
{
	return 1;
}
Error:
Код:
[03:05:36] [USAGE] vtrunk take (weapon/item)

[03:05:45] [USAGE] vtrunk put (weapon/item)
Commands:
Код:
/vtrunk take (and now anything that falls under this)
/vtrunk put (and now anything that falls under this)
Reply
#2

Use something similar to this.

Код:
COMMAND:give(playerid, params[])
{
	new targetid, option[14], param[32], amount;

	if(sscanf(params, "us[14]S()[32]", targetid, option, param))
	{
	    SendClientMessage(playerid, -1, "[Usage]: /give [playerid] [option]");
	    SendClientMessage(playerid, -1, "List of options: Weapon, Cash.");
	    return 1;
	}
	if(!strcmp(option, "weapon", true))
	{
               // Give the weapon the player is currently holding...
	}
	else if(!strcmp(option, "cash", true))
	{
	    if(sscanf(param, "i", amount))
	    {
	        return SendClientMessage(playerid, -1, "[Usage]: /give [playerid] [cash] [amount]");
	    }
            
            // Give the player some cash..

	}
	
	return 1;
}
Reply
#3

Quote:
Originally Posted by m1kas
Посмотреть сообщение
Use something similar to this.

Код:
COMMAND:give(playerid, params[])
{
	new targetid, option[14], param[32], amount;

	if(sscanf(params, "us[14]S()[32]", targetid, option, param))
	{
	    SendClientMessage(playerid, -1, "[Usage]: /give [playerid] [option]");
	    SendClientMessage(playerid, -1, "List of options: Weapon, Cash.");
	    return 1;
	}
	if(!strcmp(option, "weapon", true))
	{
               // Give the weapon the player is currently holding...
	}
	else if(!strcmp(option, "cash", true))
	{
	    if(sscanf(param, "i", amount))
	    {
	        return SendClientMessage(playerid, -1, "[Usage]: /give [playerid] [cash] [amount]");
	    }
            
            // Give the player some cash..

	}
	
	return 1;
}
What about even more parameters? Should I just add a new param?
if(sscanf(params, "us[14]S()[32]S()[32]", targetid, option, param, param2))
Reply
#4

Yes, obviously, just modify the code later on.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)