Multiple command inside one dcmd cmd?
#10

Here is a demonstration of the method I use for second commands in a command:
pawn Код:
// somewhere on the top of the script:
#define COLOR_RED 0xFF0000AA

dcmd_house(playerid, params[])
{
    new
      cmd2[64], // second command will be stored in this array
      string[128]; // for additional parameters in the second commands (see below)
    if (Account[playerid][pAdminLevel] >= 20) // admin level check
    {
        if (sscanf(params, "s ", cmd2) != 0) // cmd2 will become the first parameter, sscanf is tricked with the extra space to stop processing the string
        {
            // send proper command syntax for player, include only the first parameters (the second commands):
            SendClientMessage(playerid, COLOR_RED, "Usage: /house <add / whatever more params here>");
            return 1; // exit
        }

        if (strcmp("add", cmd2, true, 3) == 0) // check if the first 3 (!) characters of cmd2 are the same as 'add'
        {
            if (sscanf(params, "ss", cmd2, string) != 0) // read the additional parameters after the second command
            {
                // send proper syntax again, now with the needed parameters for the second command the player typed (in this case 'add'):
                SendClientMessage(playerid, COLOR_RED, "Usage: /house <add> <owner>"); // we are expecting only one extra parameter, the 'owner'
                return 1; // exit
            }
            /*
            // you may want to add this extra check for more security ^^
            if (strlen (string) > MAX_PLAYER_NAME) return SendClientMessage(playerid, COLOR_RED, "The given owner name is too long!");
            */

            // command code follows (yours), note that string is now the owner
            new
                Float:x,
                Float:y,
                Float:z,
                Float:angle;
            GetPlayerPos(playerid,x,y,z);
            GetPlayerFacingAngle(playerid,angle);
            AddHouse(owner,x,y,z,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),angle,0/*exitx*/,0/*exity*/,0/*exitz*/,1337/*exitinterior*/,0/*exitangle*/,0/*owned*/,0/*rentable*/,0/*rentcost*/,0/*houseprice*/,0/*locked*/);
            return 1; // successful, exit
        }
        /*
        // additional second commands may come here in this format:
        else if (strcmp("remove", cmd2, true, 6) == 0)
        {
          // check for other params if any
          // check validness of other params
          // code follows
        }
        else if (strcmp("info", cmd2, true, 4) == 0)
        {
          // check for other params if any
          // check validness of other params
          // code follows
        }
        // you may add as many as you want
        */

    }
    /*
    // you may want to send this warning if player if not a level 20 admin:
    else SendClientMessage(playerid, SOME_COLOR, "This is a level 20 admin command!");
    */

    return 1; // end of command
}
This works for me, I use it in multiple commands, hope it helps.
Reply


Messages In This Thread
Multiple command inside one dcmd cmd? - by Norn - 31.08.2009, 02:06
Re: Multiple command inside one dcmd cmd? - by JaTochNietDan - 31.08.2009, 02:08
Re: Multiple command inside one dcmd cmd? - by Norn - 31.08.2009, 02:13
Re: Multiple command inside one dcmd cmd? - by JaTochNietDan - 31.08.2009, 02:15
Re: Multiple command inside one dcmd cmd? - by Norn - 31.08.2009, 02:16
Re: Multiple command inside one dcmd cmd? - by JaTochNietDan - 31.08.2009, 02:19
Re: Multiple command inside one dcmd cmd? - by Norn - 31.08.2009, 02:22
Re: Multiple command inside one dcmd cmd? - by JaTochNietDan - 31.08.2009, 02:37
Re: Multiple command inside one dcmd cmd? - by Norn - 31.08.2009, 02:39
Re: Multiple command inside one dcmd cmd? - by Clavius - 31.08.2009, 16:18

Forum Jump:


Users browsing this thread: 2 Guest(s)