Thread: [PI] DC when selling items to shops.

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [PI] DC when selling items to shops. 
    Registered Member
    Join Date
    Jun 2012
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    So basically when I sell an item to a shop (any shop) I will dc from the server and get the following error in the game console. I've looked at the relevant lines but I'm new to Java and still trying to understand what certain things mean so any help would be greatly appreciated.

    Code:
    [23/05/14 09:37]: java.lang.ArrayIndexOutOfBoundsException: 101
    [23/05/14 09:37]:       at server.model.shops.ShopAssistant.addShopItem(ShopAssistant.java:623)
    [23/05/14 09:37]:       at server.model.shops.ShopAssistant.sellItem(ShopAssistant.java:600)
    [23/05/14 09:37]:       at server.model.players.packets.Bank5.processPacket(Bank5.java:23)
    [23/05/14 09:37]:       at server.model.players.PacketHandler.processPacket(PacketHandler.java:139)
    [23/05/14 09:37]:       at server.model.players.Client.processQueuedPackets(Client.java:2031)
    [23/05/14 09:37]:       at server.model.players.PlayerHandler.process(PlayerHandler.java:149)
    [23/05/14 09:37]:       at server.Server.main(Server.java:186)
    [23/05/14 09:37]: Game saved for player jamie
    [23/05/14 09:37]: jamie logged out.
    [23/05/14 09:37]: [REGISTERED]: jamie
    at server.model.shops.ShopAssistant.addShopItem(ShopA ssistant.java:623)
    Code:
    if ((Server.shopHandler.ShopItems[c.myShopId][i] - 1) == itemID) {
    at server.model.shops.ShopAssistant.sellItem(ShopAssi stant.java:600)
    Code:
    addShopItem(itemID, 1);
    at server.model.players.packets.Bank5.processPacket(B ank5.java:23)
    Code:
    c.getShops().sellItem(removeId, removeSlot, 1);
    at server.model.players.PacketHandler.processPacket(P acketHandler.java:139)
    Code:
    p.processPacket(c, packetType, packetSize);
    at server.model.players.Client.processQueuedPackets(C lient.java:2031)
    Code:
    PacketHandler.processPacket(this, packetType, packetSize);
    at server.model.players.PlayerHandler.process(PlayerH andler.java:149)
    Code:
    while(players[i].processQueuedPackets());
    at server.Server.main(Server.java:186)
    Code:
    playerHandler.process();
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    May 2014
    Age
    29
    Posts
    78
    Thanks given
    0
    Thanks received
    6
    Rep Power
    0
    Is the shopId by any chance 101? If so there's your problem and you should extend how many shops you can sell items to. Not sure where that is defined. If not, post your whole code for line 623;


    Code:
    if ((Server.shopHandler.ShopItems[c.myShopId][i] - 1) == itemID) {
    //code
    }
    This code checks if the shop sells the item already. Maybe you forgot to return; ?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jun 2012
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Geni View Post
    Is the shopId by any chance 101? If so there's your problem and you should extend how many shops you can sell items to. Not sure where that is defined. If not, post your whole code for line 623;


    Code:
    if ((Server.shopHandler.ShopItems[c.myShopId][i] - 1) == itemID) {
    //code
    }
    This code checks if the shop sells the item already. Maybe you forgot to return; ?
    It happens when I sell an item to any shop, selling an item to my melee armour store (shop 20) will still make me dc.


    My addShopItem method.
    Code:
    public boolean addShopItem(int itemID, int amount) {
    		boolean Added = false;
    		if (amount <= 0) {
    			return false;
    		}
    		if (Item.itemIsNote[itemID] == true) {
    			itemID = c.getItems().getUnnotedItem(itemID);
    		}
    		for (int i = 0; i < Server.shopHandler.ShopItems.length; i++) {
    			if ((Server.shopHandler.ShopItems[c.myShopId][i] - 1) == itemID) {
    				Server.shopHandler.ShopItemsN[c.myShopId][i] += amount;
    				Added = true;
    			}
    		}
    		if (Added == false) {
    			for (int i = 0; i < Server.shopHandler.ShopItems.length; i++) {
    				if (Server.shopHandler.ShopItems[c.myShopId][i] == 0) {
    					Server.shopHandler.ShopItems[c.myShopId][i] = (itemID + 1);
    					Server.shopHandler.ShopItemsN[c.myShopId][i] = amount;
    					Server.shopHandler.ShopItemsDelay[c.myShopId][i] = 0;
    					break;
    				}
    			}
    		}
    		return true;
    	}
    Reply With Quote  
     

  4. #4  
    Banned
    Join Date
    May 2014
    Age
    29
    Posts
    78
    Thanks given
    0
    Thanks received
    6
    Rep Power
    0
    Code:
    public boolean addShopItem(int itemID, int amount) {
    		boolean Added = false;
    		if (amount <= 0) {
    			return false;
    		}
    		if (Item.itemIsNote[itemID] == true) {
    			itemID = c.getItems().getUnnotedItem(itemID);
    		}
    		for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
    			if ((ShopHandler.ShopItems[c.myShopId][i] - 1) == itemID) {
    				ShopHandler.ShopItemsN[c.myShopId][i] += amount;
    				Added = true;
    			}
    		}
    		if (Added == false) {
    			for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
    				if (ShopHandler.ShopItems[c.myShopId][i] == 0) {
    					ShopHandler.ShopItems[c.myShopId][i] = (itemID + 1);
    					ShopHandler.ShopItemsN[c.myShopId][i] = amount;
    					ShopHandler.ShopItemsDelay[c.myShopId][i] = 0;
    					break;
    				}
    			}
    		}
    		return true;
    	}
    This shouldn't solve anything, just accessing the methods statically instead.
    Replace yours with this and then compile, and pastebin your whole shop class and I'll try to fix it
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jun 2012
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Errors
    Code:
    src\server\model\shops\ShopAssistant.java:594: error: package ShopHandler does n
    ot exist
                    for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
                                                   ^
    src\server\model\shops\ShopAssistant.java:595: error: cannot find symbol
                            if ((ShopHandler.ShopItems[c.myShopId][i] - 1) == itemID
    ) {
                                 ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:596: error: cannot find symbol
                                    ShopHandler.ShopItemsN[c.myShopId][i] += amount;
    
                                    ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:601: error: package ShopHandler does n
    ot exist
                            for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
    
                                                           ^
    src\server\model\shops\ShopAssistant.java:602: error: cannot find symbol
                                    if (ShopHandler.ShopItems[c.myShopId][i] == 0) {
    
                                        ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:603: error: cannot find symbol
                                            ShopHandler.ShopItems[c.myShopId][i] = (
    itemID + 1);
                                            ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:604: error: cannot find symbol
                                            ShopHandler.ShopItemsN[c.myShopId][i] =
    amount;
                                            ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:605: error: cannot find symbol
                                            ShopHandler.ShopItemsDelay[c.myShopId][i
    ] = 0;
                                            ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    8 errors
    Press any key to continue . . .
    ShopAssistan.java
    package server.model.shops; import server.Config; import server.Server; imp - Pastebin.com
    Reply With Quote  
     

  6. #6  
    Banned
    Join Date
    May 2014
    Age
    29
    Posts
    78
    Thanks given
    0
    Thanks received
    6
    Rep Power
    0
    [Java] package server.model.shops; import server.Config; impo - Pastebin.com

    I fixed some faulty code for you, there's alot of non-reachable code left. You should look over it better, if this does not fix your bug I don't know what to do.
    Post errors while compiling and I'll fix it for you
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Jun 2012
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Code:
    Compiling...
    src\server\model\shops\ShopAssistant.java:543: error: cannot find symbol
                            if (ShopHandler.ShopSModifier[c.myShopId] > 1) {
                                ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:545: error: cannot find symbol
                                    for (int i = 0; i <= ShopHandler.ShopItemsStanda
    rd[c.myShopId]; i++) {
                                                         ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:546: error: cannot find symbol
                                            if (itemID == (ShopHandler.ShopItems[c.m
    yShopId][i] - 1)) {
                                                           ^
      symbol:   variable ShopHandler
      location: class ShopAssistant
    src\server\model\shops\ShopAssistant.java:572: error: cannot find symbol
                                    TotPrice2 = (int) Math.floor(getBuyItemShopValue
    (itemID, 1,
                                                                 ^
      symbol:   method getBuyItemShopValue(int,int,int)
      location: class ShopAssistant
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    4 errors
    Press any key to continue . . .
    These are the errors I ran into this time. I appreciate your help with this btw.

    EDIT:
    Realised I wasn't importing ShopHandler so I've done so and the following has come up.
    Code:
    Compiling...
    src\server\model\shops\ShopAssistant.java:573: error: cannot find symbol
                                    TotPrice2 = (int) Math.floor(getBuyItemShopValue
    (itemID, 1,
                                                                 ^
      symbol:   method getBuyItemShopValue(int,int,int)
      location: class ShopAssistant
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    Press any key to continue . . .
    Reply With Quote  
     

  8. #8  
    Banned
    Join Date
    May 2014
    Age
    29
    Posts
    78
    Thanks given
    0
    Thanks received
    6
    Rep Power
    0
    Code:
    public double getBuyItemShopValue(int ItemID, int Type, int fromSlot) {
    		double ShopValue = 1;
    		double TotPrice = 0;
    		for (int i = 0; i < Config.ITEM_LIMIT; i++) {
    			if (Server.itemHandler.ItemList[i] != null) {
    				if (Server.itemHandler.ItemList[i].itemId == ItemID) {
    					ShopValue = Server.itemHandler.ItemList[i].ShopValue;
    				}
    			}
    		}
    		TotPrice = ShopValue;
    		return TotPrice*sellToShopModifier(c.myShopId);
    	}
    The int type is useless. You might aswell remove it.
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Jun 2012
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Geni View Post
    Code:
    public double getBuyItemShopValue(int ItemID, int Type, int fromSlot) {
    		double ShopValue = 1;
    		double TotPrice = 0;
    		for (int i = 0; i < Config.ITEM_LIMIT; i++) {
    			if (Server.itemHandler.ItemList[i] != null) {
    				if (Server.itemHandler.ItemList[i].itemId == ItemID) {
    					ShopValue = Server.itemHandler.ItemList[i].ShopValue;
    				}
    			}
    		}
    		TotPrice = ShopValue;
    		return TotPrice*sellToShopModifier(c.myShopId);
    	}
    The int type is useless. You might aswell remove it.
    Tried it, fixed other errors that came up and I still have the same problem. :/
    Reply With Quote  
     

  10. #10  
    Banned
    Join Date
    May 2014
    Age
    29
    Posts
    78
    Thanks given
    0
    Thanks received
    6
    Rep Power
    0
    Teamviewer? Send me information in PM
    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. [PI] Selling Items to Shop?
    By Billionaire in forum Help
    Replies: 5
    Last Post: 04-22-2013, 03:01 AM
  2. [PI] Shops DC When selling items
    By furls in forum Help
    Replies: 0
    Last Post: 12-24-2011, 11:22 PM
  3. PI Allow people to sell items to shops
    By RayWilliamJohnson in forum Help
    Replies: 2
    Last Post: 10-22-2011, 08:42 PM
  4. [PI] Selling items to shops
    By Linus in forum Snippets
    Replies: 14
    Last Post: 11-17-2010, 02:10 AM
  5. [PI] SoulSplit sell items to shop fix
    By DDS-PKZ in forum Help
    Replies: 16
    Last Post: 09-05-2010, 07:01 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
  •