SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 05/02/2012, 08:05 PM   #1
iGetty
High-roller
 
iGetty's Avatar
 
Join Date: Sep 2010
Location: Falkirk, Scotland
Posts: 1,753
Reputation: 224
Default /sell [item] [amount] [price]

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.
iGetty is offline   Reply With Quote
Old 05/02/2012, 09:19 PM   #2
Mosslah
Big Clucker
 
Join Date: Dec 2011
Posts: 74
Reputation: 10
Default Re: /sell [item] [amount] [price]

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 Code:
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.
Mosslah is offline   Reply With Quote
Old 05/02/2012, 09:23 PM   #3
2KY
Gangsta
 
2KY's Avatar
 
Join Date: Jan 2012
Location: United States
Posts: 949
Reputation: 166
Default Re: /sell [item] [amount] [price]

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

pawn Code:
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;
}
__________________
Check out my wiki page
2KY is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How Do I Do This? On Screen Amount Of Kills And amount Of Deaths HayZatic Help Archive 1 01/07/2011 02:26 PM
how to add +1 item when ... hardstop Help Archive 2 27/04/2010 08:18 PM
Help inventory sell item Giotis11 Help Archive 1 11/01/2010 12:33 PM
dcmd with parameter: /sell [playerid][item] lolmaster Help Archive 4 14/12/2009 03:30 AM
how do i get this item? Drift_04 Help Archive 2 02/03/2009 12:30 AM


All times are GMT. The time now is 03:41 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.