subcmd in zcmd.
#1

Hello !

I am a low in zcmd.

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

thx all ++
Reply
#2

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;
}
Reply
#3

But i use sscanf ^^'
Reply
#4

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.
Reply
#5

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?
Reply
#6

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

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

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;
}
Reply
#9

With others params?

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)