SA-MP Forums Archive
subcmd in zcmd. - 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: subcmd in zcmd. (/showthread.php?tid=529094)



subcmd in zcmd. - Baltimore - 31.07.2014

Hello !

I am a low in zcmd.

How to make a subcmd in zcmd? (ex: /tp lspd)

thx all ++


Re: subcmd in zcmd. - Stinged - 31.07.2014

Use strcmp (string compare) to compare params with lspd and the others.
pawn Код:
CMD:tp(playerid, params[])
{
    if (isnull(params))
        return SendClientMessage(playerid, -1, "Usage: /tp [place]");
       
    if (!strcmp(params, "lspd", true))
    {
        // Do what you want here
        return 1;
    }
    else if (!strcmp(params, "other", true))
    {
        // ...
        return 1;
    }
    return 1;
}



Re : subcmd in zcmd. - Baltimore - 31.07.2014

But i use sscanf ^^'


Re: subcmd in zcmd. - Stinged - 31.07.2014

Even if you use sscanf, just use the code I posted.
sscanf is very good and easy, but it's useless when you're ONLY using 1 string.


Re : subcmd in zcmd. - Baltimore - 31.07.2014

pawn Код:
CMD:tp(playerid, params[])
{
    if (isnull(params))
    {
        return SendClientMessage(playerid, -1, "Usage: /tp [place]");
    }
   
    if(sscanf(params, "lspd", true))
    {
        // ...
        return 1;
    }
    return 1;
}
It's good?


Re: subcmd in zcmd. - BlackM - 31.07.2014

Код:
CMD:tp(playerid, params[])
{
   new place[10];
   if(sscanf(params,"s[10]", place)) return SendClientMessage(playerid, -1,"Usage: /tp [place");
   // ur code here
   return 1;
}



Re: subcmd in zcmd. - Stinged - 31.07.2014

No. Just use what I posted, don't use sscanf in it..


Re: subcmd in zcmd. - Threshold - 31.07.2014

Exactly, even if you use sscanf, you STILL need to use strcmp to find out if they typed 'LSPD' or another place for example. SSCANF isn't a miracle, it won't suddenly make functions like 'strcmp' more efficient or faster. You're literally assigning 'params' to a variable and reusing that variable when you can just be using params the whole way through.

pawn Код:
CMD:tp(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /tp [place]");
    if(!strcmp(params, "lspd", true))
    {
        //Player wants to teleport to LSPD
    }
    else if(!strcmp(params, "los santos", true))
    {
        //Player wants to teleport to Los Santos
    }
    else SendClientMessage(playerid, -1, "You have entered an invalid location, try again.");
    return 1;
}



Re: subcmd in zcmd. - Baltimore - 30.08.2014

With others params?

Ex: /set <id of player> hp ; /set <id of player> gun


Re: subcmd in zcmd. - JacobEdwards - 31.08.2014

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Use strcmp (string compare) to compare params with lspd and the others.
pawn Код:
CMD:tp(playerid, params[])
{
    if (isnull(params))
        return SendClientMessage(playerid, -1, "Usage: /tp [place]");
       
    if (!strcmp(params, "lspd", true))
    {
        // Do what you want here
        return 1;
    }
    else if (!strcmp(params, "other", true))
    {
        // ...
        return 1;
    }
    return 1;
}
Just use this... no other way to do it.