Need help making command
#5

Quote:
Originally Posted by cacauagiar
Посмотреть сообщение
Is there anything even more simple? that i wont need an include, like a simple /jail [id] [time] [reason]
Yeah, you can do any command in STRCMP. I don't suggest you do, but you can.


pawn Код:
#define white 0xFFFFFFAA // top of script

#pragma tabsize 0 // You can delete this, but I used it to get rid of loose indentation warnings.

// Put this code under "OnPlayerCommandText", use ctrl + f to search for it.
new cmd[128], idx;
cmd = strtok(cmdtext, idx);


if(strcmp(cmd, "/command", true) == 0)
{
    new parameterstring[256], messagestring[128],
    giveplayerid, moneytogive;
    parameterstring = strtok(cmdtext, idx);

    // You could check to see if the player is an admin here.

    if(!strlen(parameterstring))
    {
        SendClientMessage(playerid, white, "Invalid syntax.");
        return 1;
    }
    giveplayerid = strval(parameterstring);
        parameterstring= strtok(cmdtext, idx);
        if(!strlen(parameterstring))
        {
        SendClientMessage(playerid, white, "Invalid syntax.");
        return 1;
        }

         moneytogive = strval(parameterstring);
         if (IsPlayerConnected(giveplayerid))
         {
                GivePlayerMoney(giveplayerid, moneytogive);
                format(messagestring, 128, "You gave that player $%d.", moneytogive);
        SendClientMessage(playerid, white, messagestring);
         }
         else
         {
               SendClientMessage(playerid, white, "Invalid player.");
         }
         return 1;
}


strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply


Messages In This Thread
Need help making command - by cacauagiar - 18.10.2012, 21:11
Re: Need help making command - by St1geR - 18.10.2012, 21:23
Re: Need help making command - by Jake__ - 18.10.2012, 21:25
Re: Need help making command - by cacauagiar - 18.10.2012, 21:39
Re: Need help making command - by Jake__ - 19.10.2012, 00:39
Re: Need help making command - by RanSEE - 19.10.2012, 04:30

Forum Jump:


Users browsing this thread: 2 Guest(s)