Thread: [PI] Better Player Owned Shops

Page 1 of 9 123 ... LastLast
Results 1 to 10 of 87
  1. #1 [PI] Better Player Owned Shops 
    Registered Member Linksbro's Avatar
    Join Date
    Mar 2008
    Posts
    118
    Thanks given
    13
    Thanks received
    22
    Rep Power
    25
    This version adds a tutorial NPC, slot amount buying, shop name changing, and many, many bug fixes including updating, collecting, and failsafe purchasing protection.

    You need these methods in ShopAssistant.
    Code:
    public void openPlayerShop(Client o) {
    		if (o == null || o.properLogout)
    			return;
    		c.getItems().resetItems(3823);
    		resetShop(o);
    		c.myShopClient = o;
    		c.myShopId = 7390;
    		c.isShopping = true;
    		c.getPA().sendFrame248(3824, 3822);
    		c.getPA().sendFrame126(o.playerShopTitle, 3901);
    	}
    
    	public int[] fixArray(int[] array) {
    		int arrayPos = 0;
    		int[] newArray = new int[array.length];
    		for (int x = 0; x < array.length; x++) {
    			if (array[x] != 0) {
    				newArray[arrayPos] = array[x];
    				arrayPos++;
    			}
    		}
    		return newArray;
    	}
    
    	public void fixShop(Client o) {
    		o.playerShop = fixArray(o.playerShop);
    		o.playerShopN = fixArray(o.playerShopN);
    		o.playerShopP = fixArray(o.playerShopP);
    	}
    
    	public void resetShop(Client o) {
    		synchronized (c) {
    			fixShop(o);
    			for (int x = 0; x < o.playerShop.length; x++) {
    				if (o.playerShopN[x] <= 0) {
    					o.playerShop[x] = 0;
    				}
    			}
    			int TotalItems = 0;
    			for (int i = 0; i <  o.playerShop.length; i++) {
    				if (o.playerShop[i] > 0) {
    					TotalItems++;
    				}
    			}
    			if (TotalItems >  o.playerShop.length) {
    				TotalItems = o.playerShop.length;
    			}
    			c.getOutStream().createFrameVarSizeWord(53);
    			c.getOutStream().writeWord(3900);
    			c.getOutStream().writeWord(TotalItems);
    			int TotalCount = 0;
    			for (int i = 0; i < o.playerShop.length; i++) {
    				if (o.playerShop[i] > 0) {
    					if (o.playerShopN[i] > 254) {
    						c.getOutStream().writeByte(255);
    						c.getOutStream().writeDWord_v2(o.playerShopN[i]);
    					} else {
    						c.getOutStream().writeByte(o.playerShopN[i]);
    					}
    					c.getOutStream().writeWordBigEndianA((o.playerShop[i] + 1));
    					TotalCount++;
    				}
    				if (TotalCount > TotalItems) {
    					break;
    				}
    			}
    			c.getOutStream().endFrameVarSizeWord();
    			c.flushOutStream();
    		}
    	}
    
    	public void openShop(int ShopID) {
    		c.getItems().resetItems(3823);
    		resetShop(ShopID);
    		c.isShopping = true;
    		c.myShopId = ShopID;
    		c.getPA().sendFrame248(3824, 3822);
    		c.getPA().sendFrame126(ShopHandler.ShopName[ShopID], 3901);
    	}
    
    	public void updatePlayerShop() {
    		for (int i = 1; i < Config.MAX_PLAYERS; i++) {
    			if (PlayerHandler.players[i] != null) {
    				if (PlayerHandler.players[i].isShopping == true
    						&& PlayerHandler.players[i].myShopId == c.myShopId
    						&& i != c.playerId) {
    					Client sh = (Client) PlayerHandler.players[i];
    					//sh.getShops().openShop(sh.myShopId);
    					PlayerHandler.players[i].updateShop = true;
    				}
    			}
    		}
    	}
    
    	public void updatePlayerOwnedShop(Client x) {
    		if (x == null)
    			return;
    		for (int i = 1; i < Config.MAX_PLAYERS; i++) {
    			if (PlayerHandler.players[i] != null) {
    				if (PlayerHandler.players[i].myShopClient != null) {
    					if (x.playerName
    							.equals(PlayerHandler.players[i].myShopClient.playerName)) {
    						Client sh = (Client) PlayerHandler.players[i];
    						sh.getShops().openPlayerShop(x);
    					}
    				}
    			}
    		}
    	}
    This is the core of player shop handling. Also, I've modified some of the updating methods so that when another player buys from the same shop you're looking at, it will update your shop. In the previous released version, this was a huge problem.

    In buyFromShopPrice add this at the start of the method.
    Code:
    if (c.myShopId == 7390 && c.myShopClient != null
    				&& !c.myShopClient.playerName.equals(c.playerName)) {
    			int value = c.myShopClient.playerShopP[removeSlot];
    			String add = "";
    			if (value >= 1000 && value < 1000000) {
    				add = " (" + (value / 1000) + "K)";
    			} else if (value >= 1000000) {
    				add = " (" + (value / 1000000) + " million)";
    			}
    			c.sendMessage(c.getItems().getItemName(removeId)
    					+ ": currently costs " + value + " coins." + add);
    			return;
    		} else if (c.myShopId == 7390 && c.myShopClient != null
    				&& c.myShopClient.playerName.equals(c.playerName)) {
    			c.sendMessage(c.getItems().getItemName(removeId)
    					+ ": currently costs " + c.playerShopP[removeSlot]
    					+ " coins.");
    			return;
    		}
    This makes it say the custom price the player has set.
    In sellToShopPrice
    Code:
    if (c.myShopId == 7390) {
    			c.sendMessage("You choose your price when using POS.");
    			return;
    		}
    In sellItem
    Code:
    if (c.myShopId == 7390) {
    			for (int i : Config.ITEM_TRADEABLE) {
    				if (i == itemID) {
    					c.sendMessage("You can't sell this item.");
    					return false;
    				}
    			}
    			if (c.playerName.equals(c.myShopClient.playerName)) {
    				c.sellingId = itemID;
    				c.sellingN = amount;
    				c.sellingS = fromSlot;
    				c.xInterfaceId = 7390;
    				c.outStream.createFrame(27);
    			} else {
    				c.sendMessage("You can only sell items on your own store.");
    			}
    			return true;
    		}
    In buyItem
    Code:
    if (c.myShopId == 7390 && c.myShopClient != null
    				&& !c.myShopClient.properLogout
    				&& !c.playerName.equals(c.myShopClient.playerName)) {
    			if (c.myShopClient.playerShop[fromSlot] != itemID)
    				return false;
    			int bought = 0;
    			int price = c.myShopClient.playerShopP[fromSlot];
    			if (amount > c.myShopClient.playerShopN[fromSlot])
    				amount = c.myShopClient.playerShopN[fromSlot];
    			for (int x = 0; x < amount; x++) {
    				if (c.getItems().playerHasItem(995,
    						c.myShopClient.playerShopP[fromSlot])
    						&& c.getItems().freeSlots() > 0) {
    					c.getItems().deleteItem2(995,
    							c.myShopClient.playerShopP[fromSlot]);
    					c.getItems()
    							.addItem(c.myShopClient.playerShop[fromSlot], 1);
    					c.myShopClient.playerShopN[fromSlot]--;
    					c.myShopClient.playerCollect += c.myShopClient.playerShopP[fromSlot];
    					if (c.myShopClient.playerShopN[fromSlot] == 0) {
    						c.myShopClient.playerShop[fromSlot] = 0;
    						c.myShopClient.playerShopP[fromSlot] = 0;
    					}
    					bought++;
    				} else {
    					c.sendMessage("Not enough space or money.");
    					break;
    				}
    			}
    			if (bought > 0) {
    				resetShop(c.myShopClient);
    				c.getItems().resetItems(3823);
    				;
    				c.sendMessage("You just bought " + bought + " "
    						+ c.getItems().getItemName(itemID) + " for "
    						+ (bought * price));
    				c.myShopClient.sendMessage(c.playerName + " has bought "
    						+ bought + " " + c.getItems().getItemName(itemID)
    						+ " from you!");
    				c.myShopClient.sendMessage("You now have "
    						+ c.myShopClient.playerCollect
    						+ " coins to collect (::collect)");
    				fixShop(c.myShopClient);
    				updatePlayerShop();
    				resetShop(c.myShopClient);
    				updatePlayerOwnedShop(c.myShopClient);
    				// c.myShopClient.complete(5);
    				// c.complete(6);
    			}
    			return false;
    		} else if (c.myShopId == 7390 && c.myShopClient != null
    				&& !c.myShopClient.properLogout
    				&& c.playerName.equals(c.myShopClient.playerName)) {
    			if (amount > c.myShopClient.playerShopN[fromSlot])
    				amount = c.myShopClient.playerShopN[fromSlot];
    			for (int x = 0; x < amount; x++) {
    				if (c.getItems().freeSlots() > 0) {
    					c.getItems()
    							.addItem(c.myShopClient.playerShop[fromSlot], 1);
    					c.myShopClient.playerShopN[fromSlot]--;
    					if (c.myShopClient.playerShopN[fromSlot] == 0) {
    						c.myShopClient.playerShop[fromSlot] = 0;
    						c.myShopClient.playerShopP[fromSlot] = 0;
    						fixShop(c);
    						updatePlayerShop();
    						resetShop(c.myShopClient);
    						updatePlayerOwnedShop(c.myShopClient);
    
    					}
    				} else {
    					c.sendMessage("Not enought space.");
    					break;
    				}
    			}
    			resetShop(c.myShopClient);
    			updatePlayerOwnedShop(c.myShopClient);
    			c.getItems().resetItems(3823);
    			return false;
    		} else if (c.myShopId == 7390) {
    			return false;
    		}
    This is the code for buying items, it also updates other players looking at the same shop to avoid purchasing bad items.

    Those are all the methods for ShopAssistant.

    Next, we move to BankX2
    Under processPacket,
    Code:
    if(c.sellingId > 0 && c.sellingN > 0 && c.xInterfaceId == 7390){
    			for (int i : Config.ITEM_TRADEABLE)  {
    				if(i == c.sellingId) {
    					c.sendMessage("You can't sell this item.");
    					c.sellingId = 0;
    					c.sellingN = 0;
    					c.sellingS = 0;
    					return;
    				}		
    			}
    			if(c.sellingN > c.getItems().getItemAmount(c.sellingId))
    				c.sellingN = c.getItems().getItemAmount(c.sellingId);
    			int slot = -1;
    			for(int x = 0; x < c.playerShop.length; x++){
    				if(c.playerShop[x] == 0){
    					slot = x;
    					break;
    				}
    			}
    			if (c.playerShop.length < c.playerShopAmt)
    			{
    				c.sendMessage("Please re-log for shop size effects to take place.");
    				return;
    			}
    			if(slot == -1){
    				c.sendMessage("You can only be selling "+c.playerShopAmt+" items at once!");
    				c.sellingId = 0;
    				c.sellingN = 0;
    				c.sellingS = 0;
    				return;
    			}
    
    			if(c.getItems().playerHasItem(c.sellingId, c.sellingN, c.sellingS)){
    				c.getItems().deleteItem2(c.sellingId, c.sellingN);
    				c.playerShop[slot] = c.sellingId;
    				c.playerShopN[slot] = c.sellingN;
    				c.playerShopP[slot] = Xamount;
    				c.sendMessage("You put your items on sale.");
    				c.sendMessage("Check your items by using ::shop and collect coins ::collect");
    			}
    			c.getShops().openPlayerShop(c);
    			c.getShops().updatePlayerOwnedShop(c);
    
    			c.sellingId = 0;
    			c.sellingN = 0;
    			c.sellingS = 0;
    			return;
    		}
    Next, in DialogueHandler add these cases (adjust if any overwrite)
    Code:
    case 568:
    			sendNpcChat4("Hello! I will explain how to use player-owned shops.",
    						"To view another person's shop, right click them in a",
    						"safe zone, and hit \"View Shop Playername\". this will",
    						"open their shop, where you may buy items directly.",
    						496,
    						"Banker");
    			c.nextChat = 569;
    		break;
    		case 569:
    			sendNpcChat4("To view, and stock your own shop, type ::shop",
    						"This will open your shop. You can right click and sell",
    						"items from your inventory to the shop. You will then",
    						"be asked to enter a price, per item.",
    						496,
    						"Banker");
    			c.nextChat = 570;
    		break;
    		case 570:
    			sendNpcChat4("To remove an item from your shop, use ::shop and",
    						"Right click an item in the shop and select buy.",
    						"This will place the item in your inventory and",
    						"remove it from your shop.",
    						496,
    						"Banker");
    			c.nextChat = 571;
    		break;
    		case 571:
    			sendNpcChat4("When a player buys an item in your store, you will",
    						"be informed. To collect money, use the ::collect",
    						"command. Your shop and collection money is saved",
    						"so you can logout and login. Have fun!",
    						496,
    						"Banker");
    			c.nextChat = 0;
    		break;
    case 576:
    			sendOption5("Learn how to use my shop",
    						"Buy more shop slots",
    						"Change shop title",
    						"Manage my own shop",
    						"No thanks");
    			c.dialogueAction = 82;
    		break;
    		case 577:
    			if (c.playerShopAmt < 40)
    			{
    				sendNpcChat2("You currently have "+c.playerShopAmt+"/40 slots",
    						"It costs 100m to increase your shop size by 5.",
    						496,
    						"Banker");
    				c.nextChat = 578;
    			}
    			else
    			{
    				sendNpcChat2("You already have 40/40 slots","You don't need anymore.",496,"Banker");
    				c.nextChat = 0;
    			}
    		break;
    		case 578:
    			sendOption2("Buy 5 slots for 100m","No thanks");
    			c.dialogueAction = 83;
    		break;
    		case 579:
    			sendOption2("Buy ability to change shop name 50m","No thanks");
    			c.dialogueAction = 84;
    		break;
    Next, in ClickingButtons
    Under case 9193
    Code:
    if (c.dialogueAction == 82)
    				{
    					c.getShops().openPlayerShop(c);
    				}
    Under case 9192
    Code:
    else if (c.dialogueAction == 82)
    				{
    					c.getDH().sendDialogues(579,1);
    				}
    Under case 9191
    [code]
    if (c.dialogueAction == 82)
    {
    c.getDH().sendDialogues(577,1);
    }
    Under case 9190
    Code:
    if (c.dialogueAction == 82)
    				{
    					c.getDH().sendDialogues(568,1);
    				}
    Under case 9157
    Code:
    if (c.dialogueAction == 83)
    				{
    					if (c.getItems().playerHasItem(995, 100000000))
    					{
    						c.getItems().deleteItem(995, c.getItems().getItemSlot(995), 100000000);
    						c.playerShopAmt += 5;
    						c.sendMessage("You need to logout for changes to take effect.");
    					}
    					else
    						c.sendMessage("We've got to have moneyyyy");
    					c.dialogueAction = -1;
    					c.getPA().removeAllWindows();
    				}
    				if (c.dialogueAction == 84)
    				{
    					if (c.getItems().playerHasItem(995, 50000000))
    					{
    						c.getItems().deleteItem(995, c.getItems().getItemSlot(995), 50000000);
    						c.playerShopName = true;
    						c.sendMessage("Use ::shopname NAME to change name.");
    					}
    					else
    						c.sendMessage("We've got to have moneyyyy");
    					c.dialogueAction = -1;
    					c.getPA().removeAllWindows();
    				}
    Next, PlayerSave
    Code:
    characterfile.write("playerShopAmt = ", 0, 16);
    			characterfile.write(Integer.toString(p.playerShopAmt), 0, Integer.toString(p.playerShopAmt).length());
    			characterfile.newLine();
    			characterfile.write("playerShopName = ", 0, 17);
    			characterfile.write(Boolean.toString(p.playerShopName), 0, Boolean.toString(p.playerShopName).length());
    			characterfile.newLine();
    			characterfile.write("playerShopTitle = ", 0, 18);
    			characterfile.write(p.playerShopTitle, 0, p.playerShopTitle.length());
    			characterfile.newLine();
    Code:
    else if (token.equals("playerShopAmt")) {
    						p.playerShopAmt = Integer.parseInt(token2);
    						p.playerShop = new int[p.playerShopAmt];
    						p.playerShopN = new int[p.playerShopAmt];
    						p.playerShopP = new int[p.playerShopAmt];
    					}	else if (token.equals("playerShopName"))
    					{
    						p.playerShopName = Boolean.parseBoolean(token2);
    					}else if (token.equals("playerShopTitle"))
    					{
    						p.playerShopTitle = token2;
    					}
    Code:
    else if (token.equals("shopcollect")) {
    						p.playerCollect = Long.parseLong(token2);
    					}
    Code:
    characterfile.write("shopcollect = ", 0, 14);
    			characterfile.write(Long.toString(p.playerCollect), 0, Long.toString(p.playerCollect).length());
    			characterfile.newLine();
    Next, Commands
    Code:
    if (cmd.equals("collect")) {
    				if (c.playerCollect > 0 && c.playerCollect < Integer.MAX_VALUE) {
    					if (((long)c.getItems().getItemAmount(995) + c.playerCollect < Integer.MAX_VALUE) && c.getItems().freeSlots() > 0)
    					{
    						c.sendMessage("You succesfully collected "
    								+ c.playerCollect + " coins.");
    						c.getItems().addItem(995, (int)c.playerCollect);
    						c.playerCollect = 0;
    					}
    					else
    					{
    						c.sendMessage("Need more gp space in your inv.");
    						return;
    					}
    					
    				} 
    				else if (c.playerCollect > Integer.MAX_VALUE)
    				{
    					int checks = (int) ((double)c.playerCollect/1000000000);
    					if (c.getItems().freeSlots() == 0)
    					{
    						c.sendMessage("Need more space in inv");
    					}
    					if (checks > c.getItems().freeSlots())
    						checks = c.getItems().freeSlots();
    					c.getItems().addItem(15287, checks);
    					c.playerCollect -= (1000000000*(long)checks);
    					c.sendMessage("Collected "+checks+" checks because collect amt to high.");
    					c.sendMessage("You still have "+c.playerCollect+"gp to collect. Use ::collect");
    					
    				} else {
    					
    					c.playerCollect = 0;
    					c.sendMessage("You dont have anything to collect");
    				}
    				return;
    			}
    			else if (cmd.equals("shop")) {
    				if (c.inWild()) {
    					c.sendMessage("can't do that bro");
    					return;
    				}
    				c.getShops().openPlayerShop(c);
    				// c.complete(4);
    				return;
    			}if (cmd.equals("shopname"))
    		{
    			if (input.length() < 20)
    			{
    				c.playerShopTitle = input;
    				c.sendMessage("Your new shop name is "+input);
    			}
    			else
    			{
    				c.sendMessage("Name needs to be less than 20 characters");
    				return;
    			}
    		}
    NOTE: The "COLLECT" command WILL PAY OUT IN CHECKS (An item that is exchangeable for gp). IF YOU DON'T HAVE CHECKS IN YOUR SERVER, YOU NEED TO REWRITE THIS COMMAND SO THAT WHEN PLAYERCOLLECT GOES OVER THE MAX INT VALUE, IT STOPS AND DOES SOME OTHER SHIT. I CHANGED IT TO A LONG IN THIS TUTORIAL TO AVOID THESE PROBLEMS.

    In Player declare
    Code:
    public boolean playerShopName=false;
    		public String playerShopTitle = "a shop";
    	public int playerShopAmt = 10;
    public int sellingId;
    	public int sellingN;
    	public int sellingS;
    	public long playerCollect;
    	public int playerShop[] = new int[playerShopAmt];
    	public int playerShopN[] = new int[playerShopAmt];
    	public int playerShopP[] = new int[playerShopAmt];
    public Client myShopClient;
    This declares the variables we use.

    In combat under checkreqs() { and under "if(Server.playerHandler.players[c.playerIndex] == null) {
    return false;
    }"
    add this:

    Code:
    		if(!Server.playerHandler.players[c.playerIndex].inWild() && !Server.playerHandler.players[c.playerIndex].inDuelArena()) {
    			c.getShops().openPlayerShop((Client)Server.playerHandler.players[c.playerIndex]);
    			c.getCombat().resetPlayerAttack();
    			return false;
    		}
    In Client. Search for showOption(3, 0,

    Code:
    		} else if (!inWild() && !inDuelArena() && safeTimer <= 0 && !inGWD() && !inPcBoat() && !inPcGame()){ //this makes it so attack option is visible on wild and challenge in duel =)
    		getPA().showOption(3, 0, "View shop", 1);
    getPA().walkableInterface(-1);
    Commands.java under ProcessPacket
    Code:
    String playerCommand = c.getInStream().readString();
    		String[] cmdargs = playerCommand.split(" ",2);
    		String cmd = cmdargs[0].toLowerCase();
    		String input = "";
    		if (cmdargs.length > 1)
    			input = cmdargs[1];
    If I'm missing any methods sorry, just post errors and I'll help fix. Kinda rushed atm.

    Credits:
    90% [Only registered and activated users can see links. ]
    10% Me
    Reply With Quote  
     

  2. #2  
    Get On My Level

    ItsGoml's Avatar
    Join Date
    Dec 2010
    Posts
    643
    Thanks given
    11
    Thanks received
    79
    Rep Power
    391
    Spoiler for teehe:

    Quote Originally Posted by Linksbro View Post
    This version adds a tutorial NPC, slot amount buying, shop name changing, and many, many bug fixes including updating, collecting, and failsafe purchasing protection.

    You need these methods in ShopAssistant.
    Code:
    public void openPlayerShop(Client o) {
    		if (o == null || o.properLogout)
    			return;
    		c.getItems().resetItems(3823);
    		resetShop(o);
    		c.myShopClient = o;
    		c.myShopId = 7390;
    		c.isShopping = true;
    		c.getPA().sendFrame248(3824, 3822);
    		c.getPA().sendFrame126(o.playerShopTitle, 3901);
    	}
    
    	public int[] fixArray(int[] array) {
    		int arrayPos = 0;
    		int[] newArray = new int[array.length];
    		for (int x = 0; x < array.length; x++) {
    			if (array[x] != 0) {
    				newArray[arrayPos] = array[x];
    				arrayPos++;
    			}
    		}
    		return newArray;
    	}
    
    	public void fixShop(Client o) {
    		o.playerShop = fixArray(o.playerShop);
    		o.playerShopN = fixArray(o.playerShopN);
    		o.playerShopP = fixArray(o.playerShopP);
    	}
    
    	public void resetShop(Client o) {
    		synchronized (c) {
    			fixShop(o);
    			for (int x = 0; x < o.playerShop.length; x++) {
    				if (o.playerShopN[x] <= 0) {
    					o.playerShop[x] = 0;
    				}
    			}
    			int TotalItems = 0;
    			for (int i = 0; i <  o.playerShop.length; i++) {
    				if (o.playerShop[i] > 0) {
    					TotalItems++;
    				}
    			}
    			if (TotalItems >  o.playerShop.length) {
    				TotalItems = o.playerShop.length;
    			}
    			c.getOutStream().createFrameVarSizeWord(53);
    			c.getOutStream().writeWord(3900);
    			c.getOutStream().writeWord(TotalItems);
    			int TotalCount = 0;
    			for (int i = 0; i < o.playerShop.length; i++) {
    				if (o.playerShop[i] > 0) {
    					if (o.playerShopN[i] > 254) {
    						c.getOutStream().writeByte(255);
    						c.getOutStream().writeDWord_v2(o.playerShopN[i]);
    					} else {
    						c.getOutStream().writeByte(o.playerShopN[i]);
    					}
    					c.getOutStream().writeWordBigEndianA((o.playerShop[i] + 1));
    					TotalCount++;
    				}
    				if (TotalCount > TotalItems) {
    					break;
    				}
    			}
    			c.getOutStream().endFrameVarSizeWord();
    			c.flushOutStream();
    		}
    	}
    
    	public void openShop(int ShopID) {
    		c.getItems().resetItems(3823);
    		resetShop(ShopID);
    		c.isShopping = true;
    		c.myShopId = ShopID;
    		c.getPA().sendFrame248(3824, 3822);
    		c.getPA().sendFrame126(ShopHandler.ShopName[ShopID], 3901);
    	}
    
    	public void updatePlayerShop() {
    		for (int i = 1; i < Config.MAX_PLAYERS; i++) {
    			if (PlayerHandler.players[i] != null) {
    				if (PlayerHandler.players[i].isShopping == true
    						&& PlayerHandler.players[i].myShopId == c.myShopId
    						&& i != c.playerId) {
    					Client sh = (Client) PlayerHandler.players[i];
    					//sh.getShops().openShop(sh.myShopId);
    					PlayerHandler.players[i].updateShop = true;
    				}
    			}
    		}
    	}
    
    	public void updatePlayerOwnedShop(Client x) {
    		if (x == null)
    			return;
    		for (int i = 1; i < Config.MAX_PLAYERS; i++) {
    			if (PlayerHandler.players[i] != null) {
    				if (PlayerHandler.players[i].myShopClient != null) {
    					if (x.playerName
    							.equals(PlayerHandler.players[i].myShopClient.playerName)) {
    						Client sh = (Client) PlayerHandler.players[i];
    						sh.getShops().openPlayerShop(x);
    					}
    				}
    			}
    		}
    	}
    This is the core of player shop handling. Also, I've modified some of the updating methods so that when another player buys from the same shop you're looking at, it will update your shop. In the previous released version, this was a huge problem.

    In buyFromShopPrice add this at the start of the method.
    Code:
    if (c.myShopId == 7390 && c.myShopClient != null
    				&& !c.myShopClient.playerName.equals(c.playerName)) {
    			int value = c.myShopClient.playerShopP[removeSlot];
    			String add = "";
    			if (value >= 1000 && value < 1000000) {
    				add = " (" + (value / 1000) + "K)";
    			} else if (value >= 1000000) {
    				add = " (" + (value / 1000000) + " million)";
    			}
    			c.sendMessage(c.getItems().getItemName(removeId)
    					+ ": currently costs " + value + " coins." + add);
    			return;
    		} else if (c.myShopId == 7390 && c.myShopClient != null
    				&& c.myShopClient.playerName.equals(c.playerName)) {
    			c.sendMessage(c.getItems().getItemName(removeId)
    					+ ": currently costs " + c.playerShopP[removeSlot]
    					+ " coins.");
    			return;
    		}
    This makes it say the custom price the player has set.
    In sellToShopPrice
    Code:
    if (c.myShopId == 7390) {
    			c.sendMessage("You choose your price when using POS.");
    			return;
    		}
    In sellItem
    Code:
    if (c.myShopId == 7390) {
    			for (int i : Config.ITEM_TRADEABLE) {
    				if (i == itemID) {
    					c.sendMessage("You can't sell this item.");
    					return false;
    				}
    			}
    			if (c.playerName.equals(c.myShopClient.playerName)) {
    				c.sellingId = itemID;
    				c.sellingN = amount;
    				c.sellingS = fromSlot;
    				c.xInterfaceId = 7390;
    				c.outStream.createFrame(27);
    			} else {
    				c.sendMessage("You can only sell items on your own store.");
    			}
    			return true;
    		}
    In buyItem
    Code:
    if (c.myShopId == 7390 && c.myShopClient != null
    				&& !c.myShopClient.properLogout
    				&& !c.playerName.equals(c.myShopClient.playerName)) {
    			if (c.myShopClient.playerShop[fromSlot] != itemID)
    				return false;
    			int bought = 0;
    			int price = c.myShopClient.playerShopP[fromSlot];
    			if (amount > c.myShopClient.playerShopN[fromSlot])
    				amount = c.myShopClient.playerShopN[fromSlot];
    			for (int x = 0; x < amount; x++) {
    				if (c.getItems().playerHasItem(995,
    						c.myShopClient.playerShopP[fromSlot])
    						&& c.getItems().freeSlots() > 0) {
    					c.getItems().deleteItem2(995,
    							c.myShopClient.playerShopP[fromSlot]);
    					c.getItems()
    							.addItem(c.myShopClient.playerShop[fromSlot], 1);
    					c.myShopClient.playerShopN[fromSlot]--;
    					c.myShopClient.playerCollect += c.myShopClient.playerShopP[fromSlot];
    					if (c.myShopClient.playerShopN[fromSlot] == 0) {
    						c.myShopClient.playerShop[fromSlot] = 0;
    						c.myShopClient.playerShopP[fromSlot] = 0;
    					}
    					bought++;
    				} else {
    					c.sendMessage("Not enough space or money.");
    					break;
    				}
    			}
    			if (bought > 0) {
    				resetShop(c.myShopClient);
    				c.getItems().resetItems(3823);
    				;
    				c.sendMessage("You just bought " + bought + " "
    						+ c.getItems().getItemName(itemID) + " for "
    						+ (bought * price));
    				c.myShopClient.sendMessage(c.playerName + " has bought "
    						+ bought + " " + c.getItems().getItemName(itemID)
    						+ " from you!");
    				c.myShopClient.sendMessage("You now have "
    						+ c.myShopClient.playerCollect
    						+ " coins to collect (::collect)");
    				fixShop(c.myShopClient);
    				updatePlayerShop();
    				resetShop(c.myShopClient);
    				updatePlayerOwnedShop(c.myShopClient);
    				// c.myShopClient.complete(5);
    				// c.complete(6);
    			}
    			return false;
    		} else if (c.myShopId == 7390 && c.myShopClient != null
    				&& !c.myShopClient.properLogout
    				&& c.playerName.equals(c.myShopClient.playerName)) {
    			if (amount > c.myShopClient.playerShopN[fromSlot])
    				amount = c.myShopClient.playerShopN[fromSlot];
    			for (int x = 0; x < amount; x++) {
    				if (c.getItems().freeSlots() > 0) {
    					c.getItems()
    							.addItem(c.myShopClient.playerShop[fromSlot], 1);
    					c.myShopClient.playerShopN[fromSlot]--;
    					if (c.myShopClient.playerShopN[fromSlot] == 0) {
    						c.myShopClient.playerShop[fromSlot] = 0;
    						c.myShopClient.playerShopP[fromSlot] = 0;
    						fixShop(c);
    						updatePlayerShop();
    						resetShop(c.myShopClient);
    						updatePlayerOwnedShop(c.myShopClient);
    
    					}
    				} else {
    					c.sendMessage("Not enought space.");
    					break;
    				}
    			}
    			resetShop(c.myShopClient);
    			updatePlayerOwnedShop(c.myShopClient);
    			c.getItems().resetItems(3823);
    			return false;
    		} else if (c.myShopId == 7390) {
    			return false;
    		}
    This is the code for buying items, it also updates other players looking at the same shop to avoid purchasing bad items.

    Those are all the methods for ShopAssistant.

    Next, we move to BuyX2
    Under processPacket,
    Code:
    if(c.sellingId > 0 && c.sellingN > 0 && c.xInterfaceId == 7390){
    			for (int i : Config.ITEM_TRADEABLE)  {
    				if(i == c.sellingId) {
    					c.sendMessage("You can't sell this item.");
    					c.sellingId = 0;
    					c.sellingN = 0;
    					c.sellingS = 0;
    					return;
    				}		
    			}
    			if(c.sellingN > c.getItems().getItemAmount(c.sellingId))
    				c.sellingN = c.getItems().getItemAmount(c.sellingId);
    			int slot = -1;
    			for(int x = 0; x < c.playerShop.length; x++){
    				if(c.playerShop[x] == 0){
    					slot = x;
    					break;
    				}
    			}
    			if (c.playerShop.length < c.playerShopAmt)
    			{
    				c.sendMessage("Please re-log for shop size effects to take place.");
    				return;
    			}
    			if(slot == -1){
    				c.sendMessage("You can only be selling "+c.playerShopAmt+" items at once!");
    				c.sellingId = 0;
    				c.sellingN = 0;
    				c.sellingS = 0;
    				return;
    			}
    
    			if(c.getItems().playerHasItem(c.sellingId, c.sellingN, c.sellingS)){
    				c.getItems().deleteItem2(c.sellingId, c.sellingN);
    				c.playerShop[slot] = c.sellingId;
    				c.playerShopN[slot] = c.sellingN;
    				c.playerShopP[slot] = Xamount;
    				c.sendMessage("You put your items on sale.");
    				c.sendMessage("Check your items by using ::shop and collect coins ::collect");
    			}
    			c.getShops().openPlayerShop(c);
    			c.getShops().updatePlayerOwnedShop(c);
    
    			c.sellingId = 0;
    			c.sellingN = 0;
    			c.sellingS = 0;
    			return;
    		}
    Next, in DialogueHandler add these cases (adjust if any overwrite)
    Code:
    case 568:
    			sendNpcChat4("Hello! I will explain how to use player-owned shops.",
    						"To view another person's shop, right click them in a",
    						"safe zone, and hit \"View Shop Playername\". this will",
    						"open their shop, where you may buy items directly.",
    						496,
    						"Banker");
    			c.nextChat = 569;
    		break;
    		case 569:
    			sendNpcChat4("To view, and stock your own shop, type ::shop",
    						"This will open your shop. You can right click and sell",
    						"items from your inventory to the shop. You will then",
    						"be asked to enter a price, per item.",
    						496,
    						"Banker");
    			c.nextChat = 570;
    		break;
    		case 570:
    			sendNpcChat4("To remove an item from your shop, use ::shop and",
    						"Right click an item in the shop and select buy.",
    						"This will place the item in your inventory and",
    						"remove it from your shop.",
    						496,
    						"Banker");
    			c.nextChat = 571;
    		break;
    		case 571:
    			sendNpcChat4("When a player buys an item in your store, you will",
    						"be informed. To collect money, use the ::collect",
    						"command. Your shop and collection money is saved",
    						"so you can logout and login. Have fun!",
    						496,
    						"Banker");
    			c.nextChat = 0;
    		break;
    case 576:
    			sendOption5("Learn how to use my shop",
    						"Buy more shop slots",
    						"Change shop title",
    						"Manage my own shop",
    						"No thanks");
    			c.dialogueAction = 82;
    		break;
    		case 577:
    			if (c.playerShopAmt < 40)
    			{
    				sendNpcChat2("You currently have "+c.playerShopAmt+"/40 slots",
    						"It costs 100m to increase your shop size by 5.",
    						496,
    						"Banker");
    				c.nextChat = 578;
    			}
    			else
    			{
    				sendNpcChat2("You already have 40/40 slots","You don't need anymore.",496,"Banker");
    				c.nextChat = 0;
    			}
    		break;
    		case 578:
    			sendOption2("Buy 5 slots for 100m","No thanks");
    			c.dialogueAction = 83;
    		break;
    		case 579:
    			sendOption2("Buy ability to change shop name 50m","No thanks");
    			c.dialogueAction = 84;
    		break;
    Next, in ClickingButtons
    Under case 9193
    Code:
    if (c.dialogueAction == 82)
    				{
    					c.getShops().openPlayerShop(c);
    				}
    Under case 9192
    Code:
    else if (c.dialogueAction == 82)
    				{
    					c.getDH().sendDialogues(579,1);
    				}
    Under case 9191
    [code]
    if (c.dialogueAction == 82)
    {
    c.getDH().sendDialogues(577,1);
    }
    Under case 9190
    Code:
    if (c.dialogueAction == 82)
    				{
    					c.getDH().sendDialogues(568,1);
    				}
    Under case 9157
    Code:
    if (c.dialogueAction == 83)
    				{
    					if (c.getItems().playerHasItem(995, 100000000))
    					{
    						c.getItems().deleteItem(995, c.getItems().getItemSlot(995), 100000000);
    						c.playerShopAmt += 5;
    						c.sendMessage("You need to logout for changes to take effect.");
    					}
    					else
    						c.sendMessage("We've got to have moneyyyy");
    					c.dialogueAction = -1;
    					c.getPA().removeAllWindows();
    				}
    				if (c.dialogueAction == 84)
    				{
    					if (c.getItems().playerHasItem(995, 50000000))
    					{
    						c.getItems().deleteItem(995, c.getItems().getItemSlot(995), 50000000);
    						c.playerShopName = true;
    						c.sendMessage("Use ::shopname NAME to change name.");
    					}
    					else
    						c.sendMessage("We've got to have moneyyyy");
    					c.dialogueAction = -1;
    					c.getPA().removeAllWindows();
    				}
    Next, PlayerSave
    Code:
    characterfile.write("playerShopAmt = ", 0, 16);
    			characterfile.write(Integer.toString(p.playerShopAmt), 0, Integer.toString(p.playerShopAmt).length());
    			characterfile.newLine();
    			characterfile.write("playerShopName = ", 0, 17);
    			characterfile.write(Boolean.toString(p.playerShopName), 0, Boolean.toString(p.playerShopName).length());
    			characterfile.newLine();
    			characterfile.write("playerShopTitle = ", 0, 18);
    			characterfile.write(p.playerShopTitle, 0, p.playerShopTitle.length());
    			characterfile.newLine();
    Code:
    else if (token.equals("playerShopAmt")) {
    						p.playerShopAmt = Integer.parseInt(token2);
    						p.playerShop = new int[p.playerShopAmt];
    						p.playerShopN = new int[p.playerShopAmt];
    						p.playerShopP = new int[p.playerShopAmt];
    					}	else if (token.equals("playerShopName"))
    					{
    						p.playerShopName = Boolean.parseBoolean(token2);
    					}else if (token.equals("playerShopTitle"))
    					{
    						p.playerShopTitle = token2;
    					}
    Code:
    else if (token.equals("shopcollect")) {
    						p.playerCollect = Long.parseLong(token2);
    					}
    Code:
    characterfile.write("shopcollect = ", 0, 14);
    			characterfile.write(Long.toString(p.playerCollect), 0, Long.toString(p.playerCollect).length());
    			characterfile.newLine();
    Next, Commands
    Code:
    if (cmd.equals("collect")) {
    				if (c.playerCollect > 0 && c.playerCollect < Integer.MAX_VALUE) {
    					if (((long)c.getItems().getItemAmount(995) + c.playerCollect < Integer.MAX_VALUE) && c.getItems().freeSlots() > 0)
    					{
    						c.sendMessage("You succesfully collected "
    								+ c.playerCollect + " coins.");
    						c.getItems().addItem(995, (int)c.playerCollect);
    						c.playerCollect = 0;
    					}
    					else
    					{
    						c.sendMessage("Need more gp space in your inv.");
    						return;
    					}
    					
    				} 
    				else if (c.playerCollect > Integer.MAX_VALUE)
    				{
    					int checks = (int) ((double)c.playerCollect/1000000000);
    					if (c.getItems().freeSlots() == 0)
    					{
    						c.sendMessage("Need more space in inv");
    					}
    					if (checks > c.getItems().freeSlots())
    						checks = c.getItems().freeSlots();
    					c.getItems().addItem(15287, checks);
    					c.playerCollect -= (1000000000*(long)checks);
    					c.sendMessage("Collected "+checks+" checks because collect amt to high.");
    					c.sendMessage("You still have "+c.playerCollect+"gp to collect. Use ::collect");
    					
    				} else {
    					
    					c.playerCollect = 0;
    					c.sendMessage("You dont have anything to collect");
    				}
    				return;
    			}
    			else if (cmd.equals("shop")) {
    				if (c.inWild()) {
    					c.sendMessage("can't do that bro");
    					return;
    				}
    				c.getShops().openPlayerShop(c);
    				// c.complete(4);
    				return;
    			}if (cmd.equals("shopname"))
    		{
    			if (input.length() < 20)
    			{
    				c.playerShopTitle = input;
    				c.sendMessage("Your new shop name is "+input);
    			}
    			else
    			{
    				c.sendMessage("Name needs to be less than 20 characters");
    				return;
    			}
    		}
    NOTE: The "COLLECT" command WILL PAY OUT IN CHECKS (An item that is exchangeable for gp). IF YOU DON'T HAVE CHECKS IN YOUR SERVER, YOU NEED TO REWRITE THIS COMMAND SO THAT WHEN PLAYERCOLLECT GOES OVER THE MAX INT VALUE, IT STOPS AND DOES SOME OTHER SHIT. I CHANGED IT TO A LONG IN THIS TUTORIAL TO AVOID THESE PROBLEMS.

    In Player declare
    Code:
    public boolean playerShopName=false;
    		public String playerShopTitle = "a shop";
    	public int playerShopAmt = 10;
    	public int sellingN;
    	public int sellingS;
    	public long playerCollect;
    This declares the variables we use.

    In combat under checkreqs() { and under "if(Server.playerHandler.players[c.playerIndex] == null) {
    return false;
    }"
    add this:

    Code:
    		if(!Server.playerHandler.players[c.playerIndex].inWild() && !Server.playerHandler.players[c.playerIndex].inDuelArena()) {
    			c.getShops().openPlayerShop((Client)Server.playerHandler.players[c.playerIndex]);
    			c.getCombat().resetPlayerAttack();
    			return false;
    		}
    In Client. Search for showOption(3, 0,

    Code:
    		} else if (!inWild() && !inDuelArena() && safeTimer <= 0 && !inGWD() && !inPcBoat() && !inPcGame()){ //this makes it so attack option is visible on wild and challenge in duel =)
    		getPA().showOption(3, 0, "View shop", 1);
    getPA().walkableInterface(-1);
    If I'm missing any methods sorry, just post errors and I'll help fix. Kinda rushed atm.

    Credits:
    90% [Only registered and activated users can see links. ]
    10% Me

    If you enjoyed this tutorial, please give thanks to [Only registered and activated users can see links. ]for the base. Thank you!




    first! and thanks for this broski! im gonna test it now!
    Spoiler for My Vouches:

    Quote Originally Posted by Randon View Post
    huge vouch for this guy! 100% legit
    Quote Originally Posted by xGenesis R View Post
    Friendly bump + vouch, reliable.



    Reply With Quote  
     

  3. #3  
    Registered Member Linksbro's Avatar
    Join Date
    Mar 2008
    Posts
    118
    Thanks given
    13
    Thanks received
    22
    Rep Power
    25
    Quote Originally Posted by death_td View Post
    first! and thanks for this broski! im gonna test it now!
    I'll be here to help you fix any errors!
    Reply With Quote  
     

  4. #4  
    Registered Member pkersworld's Avatar
    Join Date
    Mar 2011
    Age
    23
    Posts
    667
    Thanks given
    3
    Thanks received
    21
    Rep Power
    4
    Thx convert for delta plz
    -Removed
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Apr 2011
    Posts
    801
    Thanks given
    66
    Thanks received
    84
    Rep Power
    0
    This is awesome link. I'm gonna test it now.
    Reply With Quote  
     

  6. #6  
    Registered Member
    BamBam's Avatar
    Join Date
    Jan 2007
    Posts
    270
    Thanks given
    24
    Thanks received
    8
    Rep Power
    153
    Nice additions, maybe if people develop further on this idea it would be worth it. I like the tutorial ideal on usage, not to hip on the commands for it. I can whip up an interface for that if people needed. The extra slot idea is also a nice addition. I didn't look over the code, but I am sure its a big improvement to the original base that was released.

    Just a example interface that could be used. Not up par for me, but might give others an idea.


    I also believe the original author to this is[Only registered and activated users can see links. ], so you might want to give him credits instead of that other dipshit.

    Runekeep®
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Registered Member Linksbro's Avatar
    Join Date
    Mar 2008
    Posts
    118
    Thanks given
    13
    Thanks received
    22
    Rep Power
    25
    Quote Originally Posted by BamBam View Post
    Nice additions, maybe if people develop further on this idea it would be worth it. I like the tutorial ideal on usage, not to hip on the commands for it. I can whip up an interface for that if people needed. The extra slot idea is also a nice addition. I didn't look over the code, but I am sure its a big improvement to the original base that was released.

    Just a example interface that could be used. Not up par for me, but might give others an idea.


    I also believe the original author to this is[Only registered and activated users can see links. ], so you might want to give him credits instead of that other dipshit.
    I'm horrible at making interfaces but I would be grateful if someone would want to make an interface for this (if fact I would PAY for the interface) I could rewrite it and release it again. Whoops, let me fix those credits, thank you.
    Reply With Quote  
     

  9. #8  
    Registered Member pkersworld's Avatar
    Join Date
    Mar 2011
    Age
    23
    Posts
    667
    Thanks given
    3
    Thanks received
    21
    Rep Power
    4
    pleaaaaaaaaaseee convert to delta
    -Removed
    Reply With Quote  
     

  10. #9  
    Endeavor

    Mikey`'s Avatar
    Join Date
    Dec 2007
    Posts
    4,421
    Thanks given
    693
    Thanks received
    1,425
    Rep Power
    1202
    Stop using Delta. It's worse than Project Insanity.
    Reply With Quote  
     

  11. #10  
    Registered Member
    Kobra's Avatar
    Join Date
    Dec 2009
    Posts
    652
    Thanks given
    215
    Thanks received
    84
    Rep Power
    88
    Quote Originally Posted by Mikey` View Post
    Stop using Delta. It's worse than Project Insanity.
    If you make it good it works out
    Reply With Quote  
     

Page 1 of 9 123 ... 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. Player owned shops/ & Bugs
    By TrainWrecked in forum Help
    Replies: 22
    Last Post: 08-11-2011, 08:13 AM
  2. [PI] Player owned shops
    By $nitro$ in forum Buying
    Replies: 2
    Last Post: 06-07-2011, 04:40 PM
  3. [PI]Player Owned Shops
    By Glenn in forum Requests
    Replies: 6
    Last Post: 06-05-2011, 01:39 AM
  4. [PI] PLayer Owned Shops [PI]
    By vader rd in forum Help
    Replies: 6
    Last Post: 12-18-2010, 01:05 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •