SSGamers - 12 Anos online por você.

#SSGamers - A Comunidade que mais crescer no brasil!

Participe do fórum, é rápido e fácil

SSGamers - 12 Anos online por você.

#SSGamers - A Comunidade que mais crescer no brasil!

SSGamers - 12 Anos online por você.

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Chegou o novo tema 6.5.5 - SSGamers - Servidores online de qualidade - Aproveite e entre para nossa comunidade, inscreva-se já! - Ouça nossa web radio - Veja nossas novidades - Participe dos nossos setores de jogos online - Parcerias aberta fale já com um administrador.

    [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009)

    Weslley_Script
    Weslley_Script
    SS - Fundador
    SS - Fundador


    Steam Steam : WeslleySSGames
    Zello : WeslleySSGames
    Mensagens : 11378
    Moedas : 1031975
    Data de inscrição : 06/10/2011
    Idade : 28
    Localização : Brasil

    [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) Empty [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009)

    Mensagem por Weslley_Script Dom 26 Mar 2023 - 10:29

    Description

    This is just a little include that uses OnPlayerCommandText() to process players' commands. Each command has a separate function like in dcmd, but zcmd calls them directly via CallLocalFunction(). Such method is much faster than when you successively compare the text player entered to each command you have in your script (especially if he send a nonexistent cmd, you pass though all then) and its superiority over the old way is proportional to the number of commands. I did a speed test when I've just statrted thinking about this approach, you can find its results here.


    Usage

    All you need to add a command is just make a public function using special pre-defined macro, like this:
    pawn Code:

    Código:
    COMMAND:mycommand(playerid, params[]) // or CMD:mycommand(playerid, params[])
    {
      // Do something
      return 1;
    }


    or (old style):
    pawn Code:

    Código:
    command(mycommand, playerid, params[]) // or cmd(mycommand, playerid, params[])
    {
      // Do something
      return 1;
    }

    Here params[] is the parameters string, playerid is an ID of the player who send this command.
    That's all! Very easy, isn't it?


    Important: Since v0.3 OnPlayerCommandText cannot be used anymore (also ZCMD_NO_CALLBACK option has been removed), but there are two new callbacks instead:
    pawn Code:

    Código:
    OnPlayerCommandReceived(playerid, cmdtext[])

    This one is called when someone sends a command. If you return 0 here, the command won't be performed.
    pawn Code:

    Código:
    OnPlayerCommandPerformed(playerid, cmdtext[], success)


    And this one gets called after command execution, here if you do "return 0" the player will see standard "Unknown command" message. The "success" parameter is equal to value returned by command function returns (if it doesn't exist success will be 0).

    Note that it's not necessary to add these callbacks to your script if you don't use them.


    How to make two different commands doing the same thing

    For example, you have /something cmd:
    pawn Code:

    Código:
    COMMAND:something(playerid, params[])
    {
      // some stuff here
      return 1;
    }

    and you want to create another one such as /another that does what /something does. The simpliest way of doing that is:
    pawn Code:

    Código:
    COMMAND:another(playerid, params[])
    {
      return cmd_something(playerid, params);
    }



    Note #1: If you want to use zcmd in a filterscript, put this define before including:
    pawn Code:

    Código:
    #define FILTERSCRIPT


    Note #2: If you want to check whether parameters string is empty you should not do it like:
    pawn Code:

    Código:
    if (!strlen(params))
    {
      // no parameters
    }


    or :
    pawn Code:

    Código:
    if (!params[0])


    because its length is never null (read more here), simply use isnull() included into zcmd:
    pawn Code:


    Código:
    if (isnull(params))



    Actually, if you use sscanf you don't need to do this as it has built-in isnull checking.

    Here is an example of how you can make /givemoney command using zcmd with sscanf:
    pawn Code:

    Código:
    COMMAND:givemoney(playerid, params[])
    {
        if (IsPlayerAdmin(playerid))
        {
            new
              toplayerid, // the player we want to give money to
              amount;
            // extracting player's ID and amount from params
            if (!sscanf(params, "ii", toplayerid, amount))
            {
              if (toplayerid != INVALID_PLAYER_ID)
              {
                new
                  message[40];
                GivePlayerMoney(toplayerid, amount);
                format(message, sizeof(message), "You got $%d from admin!", amount);
                SendClientMessage(toplayerid, 0x00FF00FF, message);
              }
              else SendClientMessage(playerid, 0xFF0000FF, "That player is not connected");
            }
            else SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Only admins can use this command!");
        return 1;
    }


    Download


    Special thanks to:


    Creditos: Zeex
    - ******



    [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) D07Xwqb
    [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) Yjab9HN

      Data/hora atual: Seg 6 maio 2024 - 8:17