SA-MP Forums Archive
How can i create a command with three space??? - 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: How can i create a command with three space??? (/showthread.php?tid=575870)



How can i create a command with three space??? - JawsPlus - 30.05.2015

Example:

Код:
COMMAND:gang(playerid,params[],option[])
{
    if(!strcmp(params, "create", true))
	{
	  	if(gang[playerid][gid] != -1) return SendClientMessage(playerid,COLOR_GREEN, "[GANG]:{FFFFFF}Leave your gang with /gangleave before creating a new one!");
	  	if(strlen(option) > 49 || strlen(option) < 3) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]:{FFFFFF} /gangcreate (GANG NAME)");
		if(IsgangTaken(option)) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]:{FFFFFF}gang name is already in use!");
		Creategang(option, playerid);
  		return 1;
	}
	return 1;
}
I didn't get any error but it doesn't works.


Re: How can i create a command with three space??? - SickAttack - 30.05.2015

I don't see your logic to name functions like "Creategang(...)", it's weird.
pawn Код:
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

CMD:gang(playerid, params[])
{
    new option[128], rest[128];
    if(sscanf(params, "s[128]s[128]", option, rest)) return SendClientMessage(playerid, COLOR_GREEN, "Options: create, leave.");

    if(strcmp(option, "create", true) == 0)
    {
        if(isnull(rest)) return SendClientMessage(playerid, COLOR_GREEN, "Usage: /gang create (gang name).");
        if(gang[playerid][gid] != -1) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Leave your gang with /gang leave before creating a new one!");
        if(strlen(rest) < 3 || strlen(rest) > 49) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Gang name must remain in the range of 3 and 49 characters.");
        if(IsgangTaken(rest)) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Gang name is already in use!");

        Creategang(rest, playerid);
    }
    else if(strcmp(option, "leave", true) == 0)
    {
        if(gang[playerid][gid] == -1) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}You are not in a gang.");

        gang[playerid][gid] = -1;
    }
    else return SendClientMessage(playerid, COLOR_GREEN, "Options: create, leave.");
    return 1;
}
Parse "rest" for more arguments.


Re: How can i create a command with three space??? - JawsPlus - 30.05.2015

i try this

PHP код:
COMMAND:gang(playerid,option[])
{
if(!
strcmp(option"create"true))
    {
        if(
sscanf(option"s[128]"rest))return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF} /gang create [GANG NAME]");
          if(
gang[playerid][gid] != -1) return SendClientMessage(playerid,COLOR_GREEN"[GANG]:{FFFFFF}Leave your gang with /gangleave before creating a new one!");
        if(
IsgangTaken(rest)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF}gang name is already in use!");
        
Creategang(restplayerid);
          return 
1;
    }
return 
1;

but if i use /gang create it say /gang create [GANG NAME],if i use /gang create GANGABC , it nothing happend


Re: How can i create a command with three space??? - Azula - 30.05.2015

PHP код:
COMMAND:gang(playeridparams[])
{
    new 
i[7];
     if (
sscanf(params"s[7]"i)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF} /gang create [GANG NAME]");
     if (!
strcmp(i"create"true6))
    {
        if(
sscanf(params"s[128]"rest)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF} /gang create [GANG NAME]");
        if(
gang[playerid][gid] != -1) return SendClientMessage(playerid,COLOR_GREEN"[GANG]:{FFFFFF}Leave your gang with /gangleave before creating a new one!");
        if(
IsgangTaken(rest)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF}gang name is already in use!");
        
Creategang(restplayerid);
    }
    return 
1;




Re: How can i create a command with three space??? - SickAttack - 30.05.2015

Quote:
Originally Posted by JawsPlus
Посмотреть сообщение
i try this

PHP код:
COMMAND:gang(playerid,option[])
{
if(!
strcmp(option"create"true))
    {
        if(
sscanf(option"s[128]"rest))return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF} /gang create [GANG NAME]");
          if(
gang[playerid][gid] != -1) return SendClientMessage(playerid,COLOR_GREEN"[GANG]:{FFFFFF}Leave your gang with /gangleave before creating a new one!");
        if(
IsgangTaken(rest)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF}gang name is already in use!");
        
Creategang(restplayerid);
          return 
1;
    }
return 
1;

but if i use /gang create it say /gang create [GANG NAME],if i use /gang create GANGABC , it nothing happend
You have the solution right in front of you, yet you ignore it!
pawn Код:
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

CMD:gang(playerid, params[])
{
    new option[128], rest[128];
    if(sscanf(params, "s[128]s[128]", option, rest)) return SendClientMessage(playerid, COLOR_GREEN, "Options: create, leave.");

    if(strcmp(option, "create", true) == 0)
    {
        if(isnull(rest)) return SendClientMessage(playerid, COLOR_GREEN, "Usage: /gang create (gang name).");
        if(gang[playerid][gid] != -1) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Leave your gang with /gang leave before creating a new one!");
        if(strlen(rest) < 3 || strlen(rest) > 49) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Gang name must remain in the range of 3 and 49 characters.");
        if(IsgangTaken(rest)) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Gang name is already in use!");

        Creategang(rest, playerid);
    }
    else if(strcmp(option, "leave", true) == 0)
    {
        if(gang[playerid][gid] == -1) return SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}You are not in a gang.");

        gang[playerid][gid] = -1;
    }
    else return SendClientMessage(playerid, COLOR_GREEN, "Options: create, leave.");
    return 1;
}
@JawsPlus & Azula: You guys do realize that you are just storing whatever "params" has and putting it in "rest", meaning that rest contains the exact same thing as params, even the option, right?


Re: How can i create a command with three space??? - Konstantinos - 30.05.2015

I find this way much easier:
PHP код:
CMD:gang(playeridparams[])
{
    new
        
tmp_name[50];
        
    if (!
sscanf(params"'create's[50]"tmp_name))
    {
        if(
gang[playerid][gid] != -1) return SendClientMessage(playerid,COLOR_GREEN"[GANG]:{FFFFFF}Leave your gang with /gang leave before creating a new one!");
        if(!(
<= strlen(tmp_name) <= 49)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF} /gang create (GANG NAME)");
        if(
IsgangTaken(tmp_name)) return SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF}gang name is already in use!");
        
Creategang(tmp_nameplayerid);
    }
    else if (!
strcmp(params"leave"true))
    {
        
// code for "/gang leave"
    
}
    else 
SendClientMessage(playeridCOLOR_GREEN"[GANG]:{FFFFFF} /gang <create (GANG NAME)/leave>");
    return 
1;




Re: How can i create a command with three space??? - JawsPlus - 30.05.2015

not working at all


Re: How can i create a command with three space??? - SickAttack - 30.05.2015

Quote:
Originally Posted by JawsPlus
Посмотреть сообщение
not working at all
Are you sure?


Re: How can i create a command with three space??? - Jefff - 30.05.2015

Here is my version ;p

pawn Код:
CMD:gang(playerid, params[])
{
    if(isnull(params)) SendClientMessage(playerid, COLOR_GREEN, "Usage: /gang [create / leave]");
    else
    {
        if(strcmp(params, "create", true, 6) == 0)
        {
            strdel(params,0,6); // removing 'create' from params
            if(isnull(params)) SendClientMessage(playerid, COLOR_GREEN, "Usage: /gang create (gang name).");
            else if(gang[playerid][gid] != -1) SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Leave your gang with /gang leave before creating a new one!");
            else if(!(2 < strlen(params[1]) < 50)) SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Gang name must remain in the range of 3 and 49 characters.");
            else if(IsgangTaken(params[1])) SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}Gang name is already in use!");
            else Creategang(params[1], playerid);
        }
        else if(strcmp(params, "leave", true, 5) == 0)
        {
            if(gang[playerid][gid] == -1) SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}You are not in a gang.");
            else
            {
                gang[playerid][gid] = -1;
                SendClientMessage(playerid, COLOR_GREEN, "[GANG]: {FFFFFF}You are not in any gang now :>");
            }
        }
        else SendClientMessage(playerid, COLOR_GREEN, "Usage: /gang [create / leave]");
    }
    return 1;
}