/sell [item] [amount] [price]
#1

How can I make a command like that above?

/sell [item] [amount] [price]

It would help SO much. I use ZCMD and SSCANF. Thank you SO much everybody.
Reply
#2

You can use sscanf to create a command like this, it's pretty simple.

You would have alter it though on how you're doing your items, for example: If you're getting them from an inventory which is numbered then you might sell via the number, but if not then you'd use a string and just type in the name of whatever you are selling.

pawn Код:
if(sscanf(params, "sii", Item, Amount, Price)) SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sell [Item] [Amount] [Price]"); // Items via string
Obviously you'd have to define the 'Item', 'Amount' and 'Price' before the sscanf line, but that's it. Then you'd just implement the code for your items inside of it.
Reply
#3

You'll need strdel, and (advanced) sscanf knowledge. Here's an example of mine - Try to make something out of it:

pawn Код:
CMD:give(playerid, params[])
{
    new
        user,
        string[128],
        weaponname[32],
        amount,
        Float:Pos[3]
    ;
   
    if(isnull(params))
    {
        SendClientMessage(playerid, COLOR_WHITE, "[AVAILABLE ITEM NAMES]");
       
        //Items
       
        if(GetPlayerCash(playerid) > 0) { SendClientMessage(playerid, COLOR_LIME, "* Money"); }
        if(GetPlayerWeapon(playerid) != 0) { SendClientMessage(playerid, COLOR_LIME, "* Weapon"); }
        if(UserInfo[playerid][Sunglasses] == 1 && UserInfo[playerid][SunglassesType] != 0) { SendClientMessage(playerid, COLOR_LIME, "* Sunglasses"); }

        //Food
       
        if(UserInfo[playerid][Pizza] > 0) { SendClientMessage(playerid, COLOR_LIME, "* Pizza Slice"); }
        if(UserInfo[playerid][Soda] > 0) { SendClientMessage(playerid, COLOR_LIME, "* Soda"); }
        if(UserInfo[playerid][Doughnuts] > 0) { SendClientMessage(playerid, COLOR_LIME, "* Doughnut"); }
       
        //Ammo
       
        if(UserInfo[playerid][ExplosiveAmmo] > 0) { SendClientMessage(playerid, COLOR_LIME, "* ExplosiveAmmo"); }
        if(UserInfo[playerid][TazerDarts] > 0) { SendClientMessage(playerid, COLOR_LIME, "* TazerDart"); }
       
        SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give [Item Name] [Player ID] [Amount]");
        return 1;
    }
   
    if(strcmp(params, "money", true, 5) == 0) {
        strdel(params, 0, 5);
       
        if(sscanf(params, "ui", user, amount))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Money [Player ID] [Amount]");

        new
            name[24],
            uname[24]
        ;

        GetPlayerNameEx(playerid, name, 24);
        GetPlayerNameEx(user, uname, 24);
       
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);

        if(IsPlayerInRangeOfPoint(user, 5, Pos[0], Pos[1], Pos[2]))
        {
            if(GetPlayerCash(playerid) >= amount)
            {
                if(user == playerid)
                    return SendClientMessage(playerid, COLOR_ERROR, "< You cannot give yourself money!");
                   
                format(string, sizeof(string), "* %s hands %s some money.", name, uname);
                ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);

                format(string, sizeof(string), "* You have given %s $%d.", uname, amount);
                SendClientMessage(playerid, COLOR_SUCCESSFUL, string);
               
                format(string, sizeof(string), "* %s has given you $%d.", name, amount);
                SendClientMessage(user, COLOR_SUCCESSFUL, string);

                GivePlayerCash(playerid, -amount);
                GivePlayerCash(user, amount);
            }
            else return SendClientMessage(playerid, COLOR_ERROR, "< You do not have enough money!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You're not close enough to that player!");
    }
   
    else if(strcmp(params, "weapon", true, 6) == 0) {
        strdel(params, 0, 6);
       
        new
            name[24],
            uname[24],
            gunname[42]
        ;
       
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
       
        if(sscanf(params, "us[32]", user, weaponname))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Weapon [Player ID] [Weapon Name]");
       
        if(GetWeaponModelIDFromName(weaponname) == GetPlayerWeapon(playerid))
        {
       
            /*if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");*/

       
            if(IsPlayerInRangeOfPoint(user, 5, Pos[0], Pos[1], Pos[2]))
            {
                new Ammo;
                if(expAmmo[playerid] == -1)
                {
                        Ammo = GetPlayerAmmo(playerid);
                }
                else
                {
                        Ammo = UserInfo[playerid][w_TempAmmo];
                }
           
                GivePlayerWeapon(user, GetWeaponModelIDFromName(weaponname), Ammo);

                GivePlayerWeapon(playerid, GetWeaponModelIDFromName(weaponname), -Ammo);
                GetWeaponName(GetWeaponModelIDFromName(weaponname), gunname, 42);
               
                GetPlayerNameEx(playerid, name, 24);
                GetPlayerNameEx(user, uname, 24);
               
                format(string, sizeof(string), "* %s hands %s a %s.", name, uname, gunname);
                ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
               
                if(UserInfo[playerid][w_TempAmmo] != 0)
                {
                    UserInfo[playerid][w_TempAmmo] = 0;
                    expAmmo[playerid] = -1;
                }
            }
            else return SendClientMessage(playerid, COLOR_ERROR, "< You're not close enough to that player!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You can't give someone a weapon you don't have!");

    }
   
    else if(strcmp(params, "sunglasses", true, 10) == 0) {
        strdel(params, 0, 10);

        new
            name[24],
            uname[24]
        ;

        if(sscanf(params, "u", user))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Sunglasses [Player ID]");
           
        if(UserInfo[playerid][Sunglasses] == 1)
        {
            if(UserInfo[playerid][SunglassesType] != 0)
            {
           
                if(user == playerid)
                    return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");
           
                GetPlayerNameEx(playerid, name, 24);
                GetPlayerNameEx(user, uname, 24);
           
                UserInfo[user][Sunglasses] = 1;
                UserInfo[user][SunglassesType] = UserInfo[playerid][SunglassesType];
               
                UserInfo[playerid][Sunglasses] = 0;
                UserInfo[playerid][SunglassesType] = 0;
               
                format(string, sizeof(string), "* %s hands %s a pair of Sunglasses.", name, uname);
                ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
               
                SendClientMessage(user, COLOR_WHITE, "* Use /equip sunglasses to put them on!");
               
            }
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You do not have any sunglasses to give!");
    }
   
    else if(strcmp(params, "pizza", true, 5) == 0) {
        strdel(params, 0, 5);

        new
            name[24],
            uname[24]
        ;

        if(sscanf(params, "u", user))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Pizza [Player ID]");

        if(UserInfo[playerid][Pizza] > 0)
        {
            if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");
                   
            GetPlayerNameEx(playerid, name, 24);
            GetPlayerNameEx(user, uname, 24);

            UserInfo[user][Pizza]++;
            UserInfo[playerid][Pizza]--;

            format(string, sizeof(string), "* %s hands %s a Slice of Pizza.", name, uname);
            ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);

            SendClientMessage(user, COLOR_WHITE, "* Use /eat pizza slice to eat it!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You do not have any Pizza to give!");
    }
   
    else if(strcmp(params, "soda", true, 4) == 0) {
        strdel(params, 0, 4);

        new
            name[24],
            uname[24]
        ;

        if(sscanf(params, "u", user))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Soda [Player ID]");

        if(UserInfo[playerid][Soda] > 0)
        {
            if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");

            GetPlayerNameEx(playerid, name, 24);
            GetPlayerNameEx(user, uname, 24);

            UserInfo[user][Soda]++;
            UserInfo[playerid][Soda]--;

            format(string, sizeof(string), "* %s hands %s a Can of Soda.", name, uname);
            ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);

            SendClientMessage(user, COLOR_WHITE, "* Use /drink soda to drink it!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You do not have any Soda to give!");
    }
   
    else if(strcmp(params, "doughnut", true, 9) == 0) {
        strdel(params, 0, 9);

        new
            name[24],
            uname[24]
        ;

        if(sscanf(params, "u", user))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Doughnut [Player ID]");

        if(UserInfo[playerid][Doughnuts] > 0)
        {
            if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");

            GetPlayerNameEx(playerid, name, 24);
            GetPlayerNameEx(user, uname, 24);

            UserInfo[user][Doughnuts]++;
            UserInfo[playerid][Doughnuts]--;

            format(string, sizeof(string), "* %s hands %s a Doughnut.", name, uname);
            ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);

            SendClientMessage(user, COLOR_WHITE, "* Use /eat doughnut to eat it!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You do not have any Doughnuts to give!");
    }
   
    else if(strcmp(params, "explosiveammo", true, 13) == 0) {
        strdel(params, 0, 13);
       
        new
            name[24],
            uname[24]
        ;
       
        if(sscanf(params, "ui", user, amount))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give ExplosiveAmmo [Player ID] [Amount]");
           
        if(UserInfo[playerid][ExplosiveAmmo] > 0)
        {
            if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");
               
            if(UserInfo[playerid][ExplosiveAmmo] >= amount)
            {

                GetPlayerNameEx(playerid, name, 24);
                GetPlayerNameEx(user, uname, 24);

                UserInfo[playerid][ExplosiveAmmo] -= amount;
                UserInfo[user][ExplosiveAmmo] += amount;
           
                if(amount == 1) {
                    format(string, sizeof(string), "* %s hands %s a single round marked with a red letter \"E\".", name, uname);
                    ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
                    return 1;
                }
                else
                {
                    format(string, sizeof(string), "* %s hands %s a hand full of rounds marked with a red letter \"E\".", name, uname);
                    ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
                    return 1;
                }
           
            }
            else return SendClientMessage(playerid, COLOR_ERROR, "> You do not have that many bullets!");
        }
    }
   
    else if(strcmp(params, "tazerdart", true, 9) == 0) {
        strdel(params, 0, 9);
       
        new
            name[24],
            uname[24]
        ;
       
        if(sscanf(params, "ui", user, amount))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give TazerDart [Player ID] [Amount]");
           
        if(UserInfo[playerid][TazerDarts] > 0)
        {
            if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");
               
            if(UserInfo[playerid][TazerDarts] >= amount)
            {

                GetPlayerNameEx(playerid, name, 24);
                GetPlayerNameEx(user, uname, 24);

                UserInfo[playerid][TazerDarts] -= amount;
                UserInfo[user][TazerDarts] += amount;
           
                if(amount == 1) {
                    format(string, sizeof(string), "* %s hands %s a single bullet with a dart sticking out the end of it, marked with a blue \"T\".", name, uname);
                    ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
                    return 1;
                }
                else
                {
                    format(string, sizeof(string), "* %s hands %s a hand full of rounds marked with a blue letter \"T\".", name, uname);
                    ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
                    return 1;
                }
           
            }
            else return SendClientMessage(playerid, COLOR_ERROR, "> You do not have that many bullets!");
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)