Thread: ::sellitem

Results 1 to 3 of 3
  1. #1 ::sellitem 
    Registered Member
    Join Date
    Sep 2011
    Posts
    327
    Thanks given
    130
    Thanks received
    17
    Rep Power
    6
    Ok so my SellItem command,
    syntax: :ellitem ID AMOUNT
    Problem: If the item is not stacked it only removes one,
    for example, 10 furys UNNOTED - :ellitem 6585 10 - gives cash amount for 10, but removes one fury,
    If they furys were noted, it would remove all 10.
    Not sure if I am missing something very obvious here, or if I am just having an enormous brain fart.
    Code:
    			
              if (playerCommand.startsWith("sellitem")) {
                    Item item = new Item();
                    try {
                            String[] args = playerCommand.split(" ");
                            if (args.length == 3) {
                                    int newItemID = Integer.parseInt(args[1]);
                                    int newItemAmount = Integer.parseInt(args[2]);
                                    int req = item.getPrice(newItemID) * newItemAmount;
                                    boolean exists = (item.getPrice(newItemID) != -1);
                                    if(!exists) {
                                     c.sendMessage("The item you are trying to sell cannot be sold with this command.");
                                     return;
                                    }
                                    if (req < 0) {
                                            c.sendMessage("The amount you trying to sell is too low, please try selling more.");
                                            return;
                                    }
                                    if (c.getItems().playerHasItem(995,2000000000)) {
                                            c.sendMessage("You cannot sell items when you have 2b in your inventory.");
                                            return;
                                    }
                                    if (c.getItems().playerHasItem(newItemID, newItemAmount)) {
                                            c.getItems().deleteItem(newItemID, newItemAmount);
                                            c.getItems().addItem(995, (int) (req / 1.12));
                                            c.sendMessage("You have successfully sold "+newItemAmount+"x "+server.model.items.Item.getItemName(newItemID)+" for "+(int) (req / 1.12)+".");   
                                    } else {
                                            c.sendMessage("Check again to make sure this item is in your inventory.");
                                    }
                            } else {
                                    c.sendMessage("Use as ::sell 995 200 for example 200 gp");
                            }
                    } catch(Exception e) {
                            e.printStackTrace();
                    }
            }
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Dec 2011
    Posts
    967
    Thanks given
    234
    Thanks received
    208
    Rep Power
    0
    I'm pretty sure most modified PIs have a method deleteItem2 which is just a modified version of deleteItem, use that instead.

    Also, this is pretty useless

    Code:
                                    if (c.getItems().playerHasItem(995,2000000000)) {
                                            c.sendMessage("You cannot sell items when you have 2b in your inventory.");
                                            return;
                                    }
    You could do something like

    Code:
                                    if (c.getItems().playerHasItem(995, req+c.getItems().getItemAmount(995) > 2147000000 )) {
                                            c.sendMessage("You cannot sell items when you have 2b in your inventory.");
                                            return;
                                    }
    Also, instead of creating a new instance of Item everytime someone uses the command, just use a static reference to getPrice, since it should be a static method (the set price should be the same for everything in the program, no?)
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Sep 2011
    Posts
    327
    Thanks given
    130
    Thanks received
    17
    Rep Power
    6
    Quote Originally Posted by Jet- View Post
    I'm pretty sure most modified PIs have a method deleteItem2 which is just a modified version of deleteItem, use that instead.

    Also, this is pretty useless

    Code:
                                    if (c.getItems().playerHasItem(995,2000000000)) {
                                            c.sendMessage("You cannot sell items when you have 2b in your inventory.");
                                            return;
                                    }
    You could do something like

    Code:
                                    if (c.getItems().playerHasItem(995, req+c.getItems().getItemAmount(995) > 2147000000 )) {
                                            c.sendMessage("You cannot sell items when you have 2b in your inventory.");
                                            return;
                                    }
    Also, instead of creating a new instance of Item everytime someone uses the command, just use a static reference to getPrice, since it should be a static method (the set price should be the same for everything in the program, no?)
    Totally forgot about deleteitem2....
    Thank you!
    Also, yes I made this pretty sloppy thanks for the tips

    and I'm not to sure what your asking here
    (the set price should be the same for everything in the program, no?)
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. ::buyitem ::sellitem command
    By nathanrr44 in forum Help
    Replies: 11
    Last Post: 04-02-2012, 07:01 AM
  2. 637/639 Dementhium - SellItem
    By rspsmaster in forum Snippets
    Replies: 3
    Last Post: 02-11-2012, 01:26 AM
  3. Dementhium Sellitem
    By rspsmaster in forum Help
    Replies: 4
    Last Post: 01-05-2012, 09:24 PM
  4. [Pi] ::sellitem
    By furls in forum Help
    Replies: 4
    Last Post: 11-26-2011, 11:02 AM
  5. [508] Better ::sellitem for Z508
    By The Lizard King in forum Tutorials
    Replies: 12
    Last Post: 06-20-2009, 05:57 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •