Thread: Better additem ( simple shit)

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Better additem ( simple shit) 
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    24
    Posts
    2,104
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Code:
    	
    	public boolean addItem(int item, int amount, boolean dropitem) {
    		synchronized(c) {
    			if (amount < 1) {
    				amount = 1;
    			}
    			if(item <= 0) {
    				return false;
    			}
    			if ((((freeSlots() >= 1) || playerHasItem(item, 1)) && Item.itemStackable[item]) || ((freeSlots() > 0) && !Item.itemStackable[item])) {
    				for (int i = 0; i < c.playerItems.length; i++) {
    					if ((c.playerItems[i] == (item + 1)) && Item.itemStackable[item]
    							&& (c.playerItems[i] > 0)) {
    						c.playerItems[i] = (item + 1);
    						if (((c.playerItemsN[i] + amount) < Config.MAXITEM_AMOUNT)
    								&& ((c.playerItemsN[i] + amount) > -1)) {
    							c.playerItemsN[i] += amount;
    						} else {
    							c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
    						}
    						updateInventory = true;
    						updateInventory();
    						i = 30;
    						return true;
    					}
    				}
    				for (int i = 0; i < c.playerItems.length; i++) {
    					if (c.playerItems[i] <= 0) {
    						c.playerItems[i] = item + 1;
    						if ((amount < Config.MAXITEM_AMOUNT) && (amount > -1)) {
    							c.playerItemsN[i] = 1;
    							if (amount > 1) {
    								c.getItems().addItem(item, amount - 1);
    								return true;
    							}
    						} else {
    							c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
    						}
    						updateInventory = true;	
    						updateInventory();						
    						i = 30;
    						return true;
    					}
    				}
    				return false;
    			} else {
    				updateInventory = true;
    				updateInventory();
    				if (dropitem) {
    				 Server.itemHandler.createGroundItem(c, item, c.absX, c.absY, amount,c.playerId);
    				} else {
    				c.sendMessage("Not enough space in your inventory.");
    				}
    				return false;
    			}
    		}
    	}

    Without using boolean:
    Code:
    	
    	public boolean addItem(int item, int amount) {
    		synchronized(c) {
    			if (amount < 1) {
    				amount = 1;
    			}
    			if(item <= 0) {
    				return false;
    			}
    			if ((((freeSlots() >= 1) || playerHasItem(item, 1)) && Item.itemStackable[item]) || ((freeSlots() > 0) && !Item.itemStackable[item])) {
    				for (int i = 0; i < c.playerItems.length; i++) {
    					if ((c.playerItems[i] == (item + 1)) && Item.itemStackable[item]
    							&& (c.playerItems[i] > 0)) {
    						c.playerItems[i] = (item + 1);
    						if (((c.playerItemsN[i] + amount) < Config.MAXITEM_AMOUNT)
    								&& ((c.playerItemsN[i] + amount) > -1)) {
    							c.playerItemsN[i] += amount;
    						} else {
    							c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
    						}
    						updateInventory = true;
    						updateInventory();
    						i = 30;
    						return true;
    					}
    				}
    				for (int i = 0; i < c.playerItems.length; i++) {
    					if (c.playerItems[i] <= 0) {
    						c.playerItems[i] = item + 1;
    						if ((amount < Config.MAXITEM_AMOUNT) && (amount > -1)) {
    							c.playerItemsN[i] = 1;
    							if (amount > 1) {
    								c.getItems().addItem(item, amount - 1);
    								return true;
    							}
    						} else {
    							c.playerItemsN[i] = Config.MAXITEM_AMOUNT;
    						}
    						updateInventory = true;	
    						updateInventory();						
    						i = 30;
    						return true;
    					}
    				}
    				return false;
    			} else {
    				updateInventory = true;
    				updateInventory();
    				 Server.itemHandler.createGroundItem(c, item, c.absX, c.absY, amount,c.playerId);
    				//c.sendMessage("Not enough space in your inventory.");
    				return false;
    			}
    		}
    	}

    this is simple as fuck, do not replace ur current additem with this one unless u dont care about urself and dont mind about fixing thousands of errors, just add it close to ur current one.

    What this will do? if you do not have enough inventory spaces it will drop the item u added, but thats optional.

    How to use it?
    additem(item, amount, true/false) if you set it true it will drop the item if u do not have inventory spaces, sometimes u might want it to say you do not have enough inventory spaces instead of dropping the item so i made it optional.

    Please tell me how to improve this, and if i made any mistake, didnt test but should work.
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jun 2009
    Posts
    2,918
    Thanks given
    169
    Thanks received
    806
    Rep Power
    0
    if ((((freeSlots() >= 1)
    lol

    w/e gj i guess easy as @@@@ though
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    24
    Posts
    2,104
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Quote Originally Posted by iQuality View Post
    lol

    w/e gj i guess easy as @@@@ though
    lol didnt even notice, that part wasnt done by me i'm kinda noob server side im learning as much as i can , thnx i guess.
    Reply With Quote  
     

  5. #4  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    28
    Posts
    4,758
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Err.. kinda blew my snippet out of the water with dropping fire cape on the ground
    Reply With Quote  
     

  6. #5  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    24
    Posts
    2,104
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Quote Originally Posted by animeking1120 View Post
    Err.. kinda blew my snippet out of the water with dropping fire cape on the ground
    hehe sry lol
    Reply With Quote  
     

  7. #6  
    Banned

    Join Date
    Jun 2009
    Posts
    2,918
    Thanks given
    169
    Thanks received
    806
    Rep Power
    0
    Also don't see the point of this being a boolean?
    Reply With Quote  
     

  8. #7  
    Extreme Donator


    Join Date
    Oct 2006
    Posts
    1,370
    Thanks given
    64
    Thanks received
    197
    Rep Power
    426
    Quote Originally Posted by iQuality View Post
    Also don't see the point of this being a boolean?
    if can add item -> ok
    else
    do something else

    however that was meant to be used for the dropping thing, which OP has put in the code.

    it used to be if (c.getItems().addItem(x, x,)) {
    } else {
    Server.itemHandler.createGroundItem(itemId, x, y, otherParameters, c.playerId);
    }
    [Only registered and activated users can see links. ]


    Reply With Quote  
     

  9. #8  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    24
    Posts
    2,104
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Quote Originally Posted by iQuality View Post
    Also don't see the point of this being a boolean?
    it may not be, but idk if everyone wants to drop the item so i just made it optional like i said its easy as fuck to make it work without the boolean
    Reply With Quote  
     

  10. #9  
    Banned

    Join Date
    Jun 2009
    Posts
    2,918
    Thanks given
    169
    Thanks received
    806
    Rep Power
    0
    Quote Originally Posted by phl0w View Post
    if can add item -> ok
    else
    do something else

    however that was meant to be used for the dropping thing, which OP has put in the code.

    it used to be if (c.getItems().addItem(x, x,)) {
    } else {
    Server.itemHandler.createGroundItem(itemId, x, y, otherParameters, c.playerId);
    }
    Yeah but it's not getting used for it so it should not be a boolean really.
    Reply With Quote  
     

  11. #10  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    24
    Posts
    2,104
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    i updated a version without using boolean if u guys want feel free to check
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. Replies: 20
    Last Post: 12-26-2011, 09:46 PM
  2. additem
    By kojomba in forum Help
    Replies: 8
    Last Post: 09-13-2009, 06:53 PM
  3. What is the method# for addItem?
    By hoopslowe in forum Help
    Replies: 1
    Last Post: 05-29-2009, 08:56 AM
  4. need addItem void
    By luvgirl12345 in forum Help
    Replies: 5
    Last Post: 03-06-2009, 08:24 PM
  5. Better addItem thing
    By Diablo1123 in forum Configuration
    Replies: 11
    Last Post: 05-09-2008, 04:59 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
  •