Post: [PI] Player Owned Shop official release
03-11-2015, 06:30 PM #1
Stunz
Former Staff
(adsbygoogle = window.adsbygoogle || []).push({});
Lets start with saving! Open your player.java and add these variables:

    	public int sellingId;
public int sellingN;
public int sellingS;
public int playerCollect;
public int playerShop[] = new int[10];
public int playerShopN[] = new int[10];
public int playerShopP[] = new int[10];
public Client myShopClient;


They basically stores item ids, item amount etc. You can easily higher the maxium
amount of items for sale, but i liked 10! Smile

    	open PlayerSave.java and put this on loading (like above "} else if (token.equals("EP")) {"):

} else if (token.equals("shopcollect")) {
p.playerCollect = Integer.parseInt(token2);


then search for "readmode =" and add this with the others:

} else if (line.equals("[SHOP]")) { ReadMode = 10;

also, if you scroll up a bit you'll see "break;"
below it add this:

    	case 10:
if (token.equals("character-shop")) {
p.playerShop[Integer.parseInt(token3[0])] = Integer.parseInt(token3[1]);
p.playerShopP[Integer.parseInt(token3[0])] = Integer.parseInt(token3[2]);
p.playerShopN[Integer.parseInt(token3[0])] = Integer.parseInt(token3[3]);
}
break;


Then for the saving, because theres nothing to load if no saving!

scroll down a bit until you see something like this:

    	characterfile.write("character-rights = ", 0, 19);
characterfile.write(Integer.toString(p.playerRights), 0, Integer.toString(p.playerRights).length());
characterfile.newLine();

under it add this:

    	characterfile.write("shopcollect = ", 0, 14);
characterfile.write(Integer.toString(p.playerCollect), 0, Integer.toString(p.playerCollect).length());
characterfile.newLine();

then for the last part with saving, search for /*ignores*/ (down), its commented out in most of the PI:s

add this above /*ignores*/

    		/*SHOP*/
characterfile.write("[SHOP]", 0, 6);
characterfile.newLine();
for (int i = 0; i < p.playerShop.length; i++) {
if (p.playerShop[i] > 0) {
characterfile.write("character-shop = ", 0, 17);
characterfile.write(Integer.toString(i), 0, Integer.toString(i).length());
characterfile.write(" ", 0, 1);
characterfile.write(Integer.toString(p.playerShop[i]), 0, Integer.toString(p.playerShop[i]).length());
characterfile.write(" ", 0, 1);
characterfile.write(Integer.toString(p.playerShopP[i]), 0, Integer.toString(p.playerShopP[i]).length());
characterfile.write(" ", 0, 1);
characterfile.write(Integer.toString(p.playerShopN[i]), 0, Integer.toString(p.playerShopN[i]).length());
characterfile.newLine();
}
}
characterfile.newLine();


Time to add actual shopping system! Smile Open shopassistant.java

under public double getItemShopValue(int ItemID, int Type, int fromSlot) { add


    		if(c.myShopId == 7390){
return c.myShopClient.playerShopP[fromSlot];
}



and add all these methods Happy

    	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.playerName+"s shop!", 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 < 10; x++) {
if (o.playerShopN[x] <= 0) {
o.playerShop[x] = 0;
}
}
int TotalItems = 0;
for (int i = 0; i < 10; i++) {
if (o.playerShop[i] > 0) {
TotalItems++;
}
}
if (TotalItems > 10) {
TotalItems = 10;
}
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();
}
}



You may now think like "fix shop..? what?!" well its to resort your array, like you have
item on slot 1, 2 and 3 and someone buys all out from 2 then there would be empty space,
not nice IMO so that fixs the problem and moves them all =)

search for "buyFromShopPrice"

add this under:

    		if (c.myShopId == 7390 && c.myShopClient != null && !c.myShopClient.playerName.equals(c.playerName)) {
c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + c.myShopClient.playerShopP[removeSlot] + " coins.");
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;
}

then search for "sellToShopPrice"

and under it add

if(c.myShopId == 7390){
c.sendMessage("You choose your price when using POS.");
return;
}

then scroll down a lil or search for "sellItem" and under add

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;
}

then for the last part this class

search for buyItem and under it add alll this

if(c.myShopId == 7390 && c.myShopClient != null && !c.myShopClient.properLogout && !c.playerName.equals(c.myShopClient.playerName)){
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 enought 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 Upside Down Happy:collect)");
}
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);
}
}else{
c.sendMessage("Not enought space.");
break;
}
}
resetShop(c.myShopClient);
c.getItems().resetItems(3823);
return false;
}else if(c.myShopId == 7390){
return false;
}

now open BankX2(at packets) and add following under "int Xamount = c.getInStream().readDWord();"

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 < 10; x++){
if(c.playerShop[x] == 0){
slot = x;
break;
}
}
if(slot == -1){
c.sendMessage("You can only be selling 10 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 ::myshop and collect coins ::collect");
}
c.getShops().openPlayerShop(c);
c.sellingId = 0;
c.sellingN = 0;
c.sellingS = 0;
return;
}

also import server.Config;

Time to open commands.java and add these commands:

    		if(playerCommand.equalsIgnoreCase("collect")){
if(c.playerCollect > 0){
c.sendMessage("You succesfully collected "+c.playerCollect+" coins.");
c.getItems().addItem(995, c.playerCollect);
c.playerCollect = 0;
}else{
c.sendMessage("You dont have anything to collect");
}
}
if(playerCommand.equalsIgnoreCase("myshop")){
if(c.absX > 2527 && c.absX < 2634 && c.absY > 3066 && c.absY < 3115){
c.getShops().openPlayerShop(c);
}else
c.sendMessage("You can only view your shops in home.");
}


then for right click shopping, open combatAssistant, yes you readed right! combatAssistant
Oh, you're asking why? because "View shop" button is actually attack button replaced with
view shop so no client changes are needed! Smile No worries, it wont attack anyone nor cause
any bugs! Smile

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

    		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;
}


One more thing before we are done! Smile Open client.java and search for "getPA().showOption(3, 0, "Attack", 1);"

Under it add:

    		} 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);


and you're done!
(adsbygoogle = window.adsbygoogle || []).push({});

The following 2 users say thank you to Stunz for this useful post:

01cedricv2, KillManz G
03-14-2015, 09:06 AM #2
Pwnaggge
I’m too L33T
This is where most of the dupes are located xD
03-14-2015, 10:52 PM #3
Stunz
Former Staff
Originally posted by Pwnaggge View Post
This is where most of the dupes are located xD
Lol yeah, quite a few dupes in this.
03-19-2015, 02:47 PM #4
KillManz G
Little One
Originally posted by Stunz View Post
Lets start with saving! Open your player.java and add these variables:

    	public int sellingId;
public int sellingN;
public int sellingS;
public int playerCollect;
public int playerShop[] = new int[10];
public int playerShopN[] = new int[10];
public int playerShopP[] = new int[10];
public Client myShopClient;


They basically stores item ids, item amount etc. You can easily higher the maxium
amount of items for sale, but i liked 10! Smile

    	open PlayerSave.java and put this on loading (like above "} else if (token.equals("EP")) {"):

} else if (token.equals("shopcollect")) {
p.playerCollect = Integer.parseInt(token2);


then search for "readmode =" and add this with the others:

} else if (line.equals("[SHOP]")) { ReadMode = 10;

also, if you scroll up a bit you'll see "break;"
below it add this:

    	case 10:
if (token.equals("character-shop")) {
p.playerShop[Integer.parseInt(token3[0])] = Integer.parseInt(token3[1]);
p.playerShopP[Integer.parseInt(token3[0])] = Integer.parseInt(token3[2]);
p.playerShopN[Integer.parseInt(token3[0])] = Integer.parseInt(token3[3]);
}
break;


Then for the saving, because theres nothing to load if no saving!

scroll down a bit until you see something like this:

    	characterfile.write("character-rights = ", 0, 19);
characterfile.write(Integer.toString(p.playerRights), 0, Integer.toString(p.playerRights).length());
characterfile.newLine();

under it add this:

    	characterfile.write("shopcollect = ", 0, 14);
characterfile.write(Integer.toString(p.playerCollect), 0, Integer.toString(p.playerCollect).length());
characterfile.newLine();

then for the last part with saving, search for /*ignores*/ (down), its commented out in most of the PI:s

add this above /*ignores*/

    		/*SHOP*/
characterfile.write("[SHOP]", 0, 6);
characterfile.newLine();
for (int i = 0; i < p.playerShop.length; i++) {
if (p.playerShop[i] > 0) {
characterfile.write("character-shop = ", 0, 17);
characterfile.write(Integer.toString(i), 0, Integer.toString(i).length());
characterfile.write(" ", 0, 1);
characterfile.write(Integer.toString(p.playerShop[i]), 0, Integer.toString(p.playerShop[i]).length());
characterfile.write(" ", 0, 1);
characterfile.write(Integer.toString(p.playerShopP[i]), 0, Integer.toString(p.playerShopP[i]).length());
characterfile.write(" ", 0, 1);
characterfile.write(Integer.toString(p.playerShopN[i]), 0, Integer.toString(p.playerShopN[i]).length());
characterfile.newLine();
}
}
characterfile.newLine();


Time to add actual shopping system! Smile Open shopassistant.java

under public double getItemShopValue(int ItemID, int Type, int fromSlot) { add


    		if(c.myShopId == 7390){
return c.myShopClient.playerShopP[fromSlot];
}



and add all these methods Happy

    	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.playerName+"s shop!", 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 < 10; x++) {
if (o.playerShopN[x] <= 0) {
o.playerShop[x] = 0;
}
}
int TotalItems = 0;
for (int i = 0; i < 10; i++) {
if (o.playerShop[i] > 0) {
TotalItems++;
}
}
if (TotalItems > 10) {
TotalItems = 10;
}
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();
}
}



You may now think like "fix shop..? what?!" well its to resort your array, like you have
item on slot 1, 2 and 3 and someone buys all out from 2 then there would be empty space,
not nice IMO so that fixs the problem and moves them all =)

search for "buyFromShopPrice"

add this under:

    		if (c.myShopId == 7390 && c.myShopClient != null && !c.myShopClient.playerName.equals(c.playerName)) {
c.sendMessage(c.getItems().getItemName(removeId)+": currently costs " + c.myShopClient.playerShopP[removeSlot] + " coins.");
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;
}

then search for "sellToShopPrice"

and under it add

if(c.myShopId == 7390){
c.sendMessage("You choose your price when using POS.");
return;
}

then scroll down a lil or search for "sellItem" and under add

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;
}

then for the last part this class

search for buyItem and under it add alll this

if(c.myShopId == 7390 && c.myShopClient != null && !c.myShopClient.properLogout && !c.playerName.equals(c.myShopClient.playerName)){
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 enought 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 Upside Down Happy:collect)");
}
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);
}
}else{
c.sendMessage("Not enought space.");
break;
}
}
resetShop(c.myShopClient);
c.getItems().resetItems(3823);
return false;
}else if(c.myShopId == 7390){
return false;
}

now open BankX2(at packets) and add following under "int Xamount = c.getInStream().readDWord();"

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 < 10; x++){
if(c.playerShop[x] == 0){
slot = x;
break;
}
}
if(slot == -1){
c.sendMessage("You can only be selling 10 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 ::myshop and collect coins ::collect");
}
c.getShops().openPlayerShop(c);
c.sellingId = 0;
c.sellingN = 0;
c.sellingS = 0;
return;
}

also import server.Config;

Time to open commands.java and add these commands:

    		if(playerCommand.equalsIgnoreCase("collect")){
if(c.playerCollect > 0){
c.sendMessage("You succesfully collected "+c.playerCollect+" coins.");
c.getItems().addItem(995, c.playerCollect);
c.playerCollect = 0;
}else{
c.sendMessage("You dont have anything to collect");
}
}
if(playerCommand.equalsIgnoreCase("myshop")){
if(c.absX > 2527 && c.absX < 2634 && c.absY > 3066 && c.absY < 3115){
c.getShops().openPlayerShop(c);
}else
c.sendMessage("You can only view your shops in home.");
}


then for right click shopping, open combatAssistant, yes you readed right! combatAssistant
Oh, you're asking why? because "View shop" button is actually attack button replaced with
view shop so no client changes are needed! Smile No worries, it wont attack anyone nor cause
any bugs! Smile

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

    		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;
}


One more thing before we are done! Smile Open client.java and search for "getPA().showOption(3, 0, "Attack", 1);"

Under it add:

    		} 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);


and you're done!


Awesome nice work

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo