Difficulty: 2/10
Base: Palidinos Normal 508 base...
Description:
This is to add shops with the correct interface to your 508 server. This was coded 100% to serenity and all credits on on this tutorial go to him!
Why is it only 99%, Why not 100%?
It's 99% because of one reason, and that is because the "Buy X" button will not work, unless coded by someone else and released.. Also i dont know if it's me that has this problem, but when you access the shop it does not change to the inventory with the items in..
But yeh that's about it really.
Step 1.
Ok first we are going to need to find "PacketManager.java".
This can be found at "palidino76\rs2\io"...
Once you have opened the file, search for:
And add these other cases if you dont have them..
Remember if you do NOT have any of this then add it, because this basically makes all packets be sent to the server knowing you are clicking the correct buttons on each interface..
Save and close "PacketManager.java"
Step 2.
Now we are going to need to find "ActionButtons.java"
This is located at "palidino76\rs2\io\packets"...
Ok open that file and search for:
Replace it with this:
Of course you dont have to replace it, but you can if you dont know how to call the packets once the buttons have been pressed.
Step 3.
Now we have done all that, we are going to need to make a ShopHandler.java.
This is to be placed at:
This is the main part of the whole tutorial because here we can add shops which will be called from Shops.java.
Step 4.
Now we have to create a file called Shops.java.
This is to be put into:
Now here we can create new shops, basically adding the items to the shop.
For example, i have made a custom shop with Rares in it.
This is the place to insert the item id:
And this is the place to insert the amount of the same item to be inserted into the shop:
How do i open shops on my server?
All you have to do to open a shop on your server is add the above code to where you desire...
So if you were doing it in NpcOption1.java then you can simply do:
How do i make it automatically show Player Stock?
To make it so when you click on the NPC and it automatically goes to the Player Stock instead of Main stock, simply do the following..
In ShopHandler.java with the cases, add this..
I've explained what the code does using comments..
Then add these in Engine.java
If you get any errors you could also try importing this into Engine.java
Pictures of the Shops..
Credits: Serenity 100% for code.
No credits to me but i did write this tutorial, hope you can figure it out!
BTW IM ALWAYSSTUCK1 ON R-SERVER!! meh...
+
i asked serenity if i could post it here. And he approved, so yeh enjoy...
ps. You will get import errors, just fix them if you know what your doing..
Base: Palidinos Normal 508 base...
Description:
This is to add shops with the correct interface to your 508 server. This was coded 100% to serenity and all credits on on this tutorial go to him!
Why is it only 99%, Why not 100%?
It's 99% because of one reason, and that is because the "Buy X" button will not work, unless coded by someone else and released.. Also i dont know if it's me that has this problem, but when you access the shop it does not change to the inventory with the items in..
But yeh that's about it really.
Step 1.
Ok first we are going to need to find "PacketManager.java".
This can be found at "palidino76\rs2\io"...
Once you have opened the file, search for:
Code:
case 232:
case 90:
And add these other cases if you dont have them..
Code:
case 233:
case 113:
case 21:
case 214:
case 169:
case 232:
case 90:
/*
* When you click an interface button this packet is sent.
*/
actionButtons.handlePacket(p, packetId, packetSize);
Remember if you do NOT have any of this then add it, because this basically makes all packets be sent to the server knowing you are clicking the correct buttons on each interface..
Save and close "PacketManager.java"
Step 2.
Now we are going to need to find "ActionButtons.java"
This is located at "palidino76\rs2\io\packets"...
Ok open that file and search for:
Code:
public void handlePacket
Replace it with this:
Code:
public void handlePacket(Player p, int packetId, int packetSize) {
if (p == null || p.stream == null) {
return;
}
int interfaceId = p.stream.readUnsignedWord();
int buttonId = p.stream.readUnsignedWord();
int buttonId2 = 0;
if (packetId == 233 || packetId == 21 || packetId == 169 || packetId == 232 || packetId == 214 || packetId == 90) {
buttonId2 = p.stream.readUnsignedWord();
}
if (buttonId2 == 65535) {
buttonId2 = 0;
}
switch (interfaceId) {
case 620:
case 621:
Engine.shopHandler.handleoption(p,interfaceId,buttonId,buttonId2,packetId);
break;
Of course you dont have to replace it, but you can if you dont know how to call the packets once the buttons have been pressed.
Step 3.
Now we have done all that, we are going to need to make a ShopHandler.java.
This is to be placed at:
Code:
palidino76.rs2.Content
Code:
package palidino76.rs2.Content;
import palidino76.rs2.players.Player;
import palidino76.rs2.players.items.PlayerItems;
import palidino76.rs2.Engine;
/**
* Created by IntelliJ IDEA.
* User: Serenty
* Date: 3-march-2009
* Project: Boneyard
* Time: 19:51:15
*/
public class ShopHandler {
Player p;
PlayerItems pi = new PlayerItems();
public int maxItems = 40;
public int[] items = new int[maxItems];
public int[] itemsN = new int[maxItems];
public int[] maxItemAmount = new int[maxItems];
public boolean generalStore = false;
public long lastRestock = System.currentTimeMillis();
int shopid = 0;
public boolean mainstock = true;
/***************************************************************************************************************/
/* DO NOT TOUCH THIS! */
/***************************************************************************************************************/
public ShopHandler() {
for (int i = 0; i < 40; i++) {
items[i] = -1;
}
this.items = items;
this.itemsN = itemsN;
maxItemAmount = itemsN;
}
public void process(Player p) {
if (System.currentTimeMillis() - lastRestock >= 60000) {
clearSlots(p);
for (int i = 0; i < items.length; i++) {
if (itemsN[i] < maxItemAmount[i]) itemsN[i]++;
}
lastRestock = System.currentTimeMillis();
}
}
public void sell(Player p, int item, int amnt){
PlayerItems pi = new PlayerItems();
boolean shopShouldBuy = generalStore || isItemOnShop(item);
if (!shopShouldBuy) {
p.frames.sendMessage(p, "You cannot sell this item to this shop.");
return;
}
if (item == 995) {
p.frames.sendMessage(p, "You can't sell coins to a shop");
return;
}
int free = findFreeSlot();
if (!isItemOnShop(item) && generalStore) {
if (free == -1) {
p.frames.sendMessage(p, "This shop is full.");
return;
}
items[free] = item;
itemsN[free] = 0;
}
int slot = findItemSlot(item);
if(amnt<=pi.invItemCount(p,item))
{
if (itemStacks(item)) {
items[slot] = item;
itemsN[slot] += amnt;
pi.deleteItem(p, item, pi.getItemSlot(p, item), amnt);
pi.addItem(p, 995, amnt*itemValue(item));
} else {
items[slot] = item;
for (int notused = amnt; notused > 0; notused--) {
pi.deleteItem(p, item, pi.getItemSlot(p, item), 1);
pi.addItem(p, 995, itemValue(item));
itemsN[slot]++;
}
}
}
else
{
amnt = pi.invItemCount(p,item);
if (itemStacks(item)) {
items[slot] = item;
itemsN[slot] += amnt;
pi.deleteItem(p, item, pi.getItemSlot(p, item), amnt);
pi.addItem(p, 995, amnt*itemValue(item));
} else {
items[slot] = item;
for (int notused = amnt; notused > 0; notused--) {
pi.deleteItem(p, item, pi.getItemSlot(p, item), 1);
pi.addItem(p, 995, itemValue(item));
itemsN[slot]++;
}
}
}
sendShopItems(p);
sendPlayerInventory(p);
}
public void buy(Player p, int item, int amnt) {
clearSlots(p);
int slot = findItemSlot(item);
if (slot == -1) {
return;
}
if (itemsN[slot] < amnt) amnt = itemsN[slot];
if (amnt == 0) {
items[slot] = -1;
p.frames.sendMessage(p, "That item's stock has run out.");
return;
}
if (itemStacks(item)) { // item stackable, easier...
if (pi.freeSlotCount(p) < 1) {
p.frames.sendMessage(p, "Not enough space on inventory");
return;
}
if (pi.invItemCount(p, 995) < (amnt * itemValue(item))) {
p.frames.sendMessage(p, "Not enough coins to buy that many.");
return;
}
pi.deleteItem(p, 995, pi.getItemSlot(p, 995), amnt * itemValue(item));
pi.addItem(p, item, amnt);
itemsN[slot] -= amnt;
} else { // item not stackable
for (int i = amnt; i > 0; i--) {
int price = itemValue(item);
clearSlots(p);
if (pi.invItemCount(p, 995) < price) {
p.frames.sendMessage(p, "Not enough coins to buy that many.");
break;
}
if (pi.findInvSlot(p) == -1) {
p.frames.sendMessage(p, "Not enough space on inventory");
break;
}
if (itemsN[slot] < 1) {
clearSlots(p);
p.frames.sendMessage(p, "The shop has run out of stock from this item!");
break;
}
if (itemsN[slot] == 1) {
pi.deleteItem(p, 995, pi.getItemSlot(p, 995), price);
pi.addItem(p, item, 1);
items[slot] = -1;
break;
}
itemsN[slot]--;
pi.deleteItem(p, 995, pi.getItemSlot(p, 995), price);
pi.addItem(p, item, 1);
clearSlots(p);
}
}
sendShopItems(p);
sendPlayerInventory(p);
clearSlots(p);
}
public void buystock(Player p, int item, int amnt) {
if (itemStacks(item)) { // item stackable, easier...
if (pi.freeSlotCount(p) < 1) {
p.frames.sendMessage(p, "Not enough space on inventory");
return;
}
if (pi.invItemCount(p, 995) < (amnt * itemValue(item))) {
p.frames.sendMessage(p, "Not enough coins to buy that many.");
return;
}
pi.deleteItem(p, 995, pi.getItemSlot(p, 995), amnt * itemValue(item));
pi.addItem(p, item, amnt);
} else {
// item not stackable
for (int i = amnt; i > 0; i--) {
int price = itemValue(item);
if (pi.invItemCount(p, 995) < price) {
p.frames.sendMessage(p, "Not enough coins to buy that many.");
break;
}
if (pi.findInvSlot(p) == -1) {
p.frames.sendMessage(p, "Not enough space on inventory");
break;
}
pi.deleteItem(p, 995, pi.getItemSlot(p, 995), price);
pi.addItem(p, item, 1);
}
}
//sendShopItems(p);
sendPlayerInventory(p);
}
public int findItemSlot(int item) {
for (int i = 0; i < items.length; i++)
if (item == items[i]) return i;
return -1;
}
public int findFreeSlot() {
for (int i = 0; i < items.length; i++)
if (items[i] == -1) return i;
return -1;
}
public void clearSlots(Player p) {
for (int i = 0; i < items.length; i++)
if (items[i] < 1) {
items[i] = -1;
} else {
}
}
public void sendShopItems(Player p) {
p.frames.setItems(p, -1, 64271, 31, items, itemsN);
}
public boolean isItemOnShop(int item) {
return findItemSlot(item) != -1;
}
public void sendPlayerInventory(Player p) {
p.frames.setItems(p, -1, 64209, 93, p.items, p.itemsN);
}
public int itemValue(int item) {
return Engine.items.itemLists[item].shopValue;
}
public boolean itemStacks(int item) {
return Engine.items.itemLists[item].itemStackable;
}
public void handleoption(Player p, int interfaceId, int buttonId, int buttonId2, int packetId) {
switch (interfaceId) {
case 620:
if (buttonId == 25) {
p.frames.setInterfaceConfig(p, 620, 23, false);
p.frames.setInterfaceConfig(p, 620, 24, true);
p.frames.setInterfaceConfig(p, 620, 29, false);
p.frames.setInterfaceConfig(p, 620, 25, true);
p.frames.setInterfaceConfig(p, 620, 27, true);
p.frames.setInterfaceConfig(p, 620, 26, false);
p.frames.setAccessMask(p, 1278, 23, 620, 0, 40);
mainstock = true;
}
if (buttonId == 26) {
p.frames.setInterfaceConfig(p, 620, 23, true);
p.frames.setInterfaceConfig(p, 620, 24, false);
p.frames.setInterfaceConfig(p, 620, 29, true);
p.frames.setInterfaceConfig(p, 620, 25, false);
p.frames.setInterfaceConfig(p, 620, 27, false);
p.frames.setInterfaceConfig(p, 620, 26, true);
p.frames.setAccessMask(p, 1278, 24, 620, 0, 40);
mainstock = false;
}
PlayerItems pi = new PlayerItems();
if (buttonId == 23) {
int itemid = returnItemId(shopid, buttonId2);
switch (packetId) {
case 233:
/* Value. */
p.frames.sendMessage(p, "this item costs " + Engine.items.getItemValue(itemid) + " coins.");
break;
case 21:
/* Buy 1. */
buystock(p, itemid, 1);
break;
case 169:
/* Buy 5. */
buystock(p, itemid, 5);
break;
case 214:
/* Buy 10. */
buystock(p, itemid, 10);
break;
case 173:
/* Buy 50. */
buystock(p, itemid, 50);
break;
case 232:
/*Examine. */
p.frames.sendMessage(p, Engine.items.getItemDescription(itemid));
break;
}
}
if (buttonId == 24) {
int itemid = items[buttonId2];
switch (packetId) {
case 233:
/* Value. */
p.frames.sendMessage(p, "this item costs " + Engine.items.getItemValue(itemid) + " coins.");
break;
case 21:
/* Buy 1. */
buy(p, itemid, 1);
break;
case 169:
/* Buy 5. */
buy(p, itemid, 5);
break;
case 214:
/* Buy 10. */
buy(p, itemid, 10);
break;
case 173:
/* Buy 50. */
buy(p, itemid, 50);
break;
case 90:
/*Examine. */
p.frames.sendMessage(p, Engine.items.getItemDescription(itemid));
break;
}
}
break;
case 621:
if (buttonId == 0) {
int itemid = p.items[buttonId2];
switch (packetId) {
case 233:
/*Value.*/
p.frames.sendMessage(p, "this item is wourth " + Engine.items.getItemValue(itemid) + " coins.");
break;
case 21:
/*
* Buy 1.
*/
sell(p, itemid, 1);
break;
case 169:
/*
* Buy 5.
*/
sell(p, itemid, 5);
break;
case 214:
/*
* Buy 10.
*/
sell(p, itemid, 10);
break;
case 173:
/*
* Buy 50.
*/
sell(p, itemid, 50);
break;
case 90:
/*
* Examine.
*/
p.frames.sendMessage(p, Engine.items.getItemDescription(itemid));
break;
}
}
break;
}
}
public void shopopen(Player p, int shopId) {
p.frames.removeShownInterface(p);
p.frames.showInterface(p, 620); //Shop
p.frames.setInventory(p, 621);
p.frames.setTab(p, 80, 621);//Inv
shopid = shopId;
Object[] setshopparams = new Object[]{shopId, 93};
int shi = 621 << 16;
int ship = (620 << 16) + 24;
Object[] invparams = new Object[]{"", "", "", "", "Sell X", "Sell 10", "Sell 5", "Sell 1", "Value", -1, 0, 7, 4, 93, shi};
Object[] shopparams = new Object[]{"", "", "", "", "Buy X", "Buy 10", "Buy 5", "Buy 1", "Value", -1, 0, 4, 10, 31, ship};
p.frames.runScript(p, 25, setshopparams, "vg");//Loads main stock items
p.frames.runScript(p, 150, invparams, "IviiiIsssssssss");
p.frames.runScript(p, 150, shopparams, "IviiiIsssssssss");
p.frames.setAccessMask(p, 1278, 0, 621, 0, 28);
if (mainstock) {
p.frames.setInterfaceConfig(p, 620, 23, false);
p.frames.setInterfaceConfig(p, 620, 24, true);
p.frames.setInterfaceConfig(p, 620, 29, false);
p.frames.setInterfaceConfig(p, 620, 25, true);
p.frames.setInterfaceConfig(p, 620, 27, true);
p.frames.setInterfaceConfig(p, 620, 26, false);
p.frames.setAccessMask(p, 1278, 23, 620, 0, 40);
} else {
p.frames.setInterfaceConfig(p, 620, 23, true);
p.frames.setInterfaceConfig(p, 620, 24, false);
p.frames.setInterfaceConfig(p, 620, 29, true);
p.frames.setInterfaceConfig(p, 620, 25, false);
p.frames.setInterfaceConfig(p, 620, 27, false);
p.frames.setInterfaceConfig(p, 620, 26, true);
p.frames.setAccessMask(p, 1278, 24, 620, 0, 40);
}
}
/***************************************************************************************************************/
/* ONLY EDIT THIS! */
/***************************************************************************************************************/
public int returnItemId(int shopid, int buttonId2) {
switch (shopid) {
case 868:
switch (buttonId2) {
case 0:return 1931;
case 1:return 1935;
case 2:return 1735;
case 3:return 1925;
case 4:return 1923;
case 5:return 1887;
case 6:return 590;
case 7:return 1755;
case 8:return 2347;
case 9:return 550;
case 10:return 9003;
}
break;
case 2:
switch (buttonId2) {
case 0:return 1931;
case 1:return 1935;
case 2:return 1735;
case 3:return 1925;
case 4:return 1923;
case 5:return 1887;
case 6:return 590;
case 7:return 1755;
case 8:return 2347;
case 9:return 550;
case 10:return 9003;
}
break;
}
return -1;
}
public void openshop(Player p, int shopid) {
switch (shopid) {
case 1:
shopopen(p, 868);
generalStore = true;
items = Engine.shops.Generalshoplumb;
itemsN = Engine.shops.GeneralshoplumbN;
p.frames.setItems(p, -1, 64209, 93, p.items, p.itemsN);//Shop Inventory
p.frames.setItems(p, -1, 64271, 31, items, itemsN);//Main Stock
break;
case 2:
shopopen(p, 868);
generalStore = true;
items = Engine.shops.Generalshopfalador;
itemsN = Engine.shops.GeneralshopfaladorN;
p.frames.setItems(p, -1, 64209, 93, p.items, p.itemsN);//Shop Inventory
p.frames.setItems(p, -1, 64271, 31, items, itemsN);//Main Stock
break;
case 3:
shopopen(p, 868); // shop id 868 general store.
generalStore = true;
items = Engine.shops.Generalshopvarrock;
itemsN = Engine.shops.GeneralshopvarrockN;
p.frames.setItems(p, -1, 64209, 93, p.items, p.itemsN);//Shop Inventory
p.frames.setItems(p, -1, 64271, 31, items, itemsN);//Main Stock //set to 32 to be in playerstock
break;
}
}
}
This is the main part of the whole tutorial because here we can add shops which will be called from Shops.java.
Step 4.
Now we have to create a file called Shops.java.
This is to be put into:
Code:
palidino76.rs2.Content
Code:
package palidino76.rs2.Content;
/**
* Created by IntelliJ IDEA.
* User: Sere
* Date: 6-mrt-2009
* Time: 10:33:19
*/
public class Shops {
public int maxItems = 40;
/*init shops */
public int[] Generalshoplumb = new int[maxItems];
public int[] GeneralshoplumbN = new int[maxItems];
public int[] Generalshopvarrock = new int[maxItems];
public int[] GeneralshopvarrockN = new int[maxItems];
public int[] Generalshopfalador = new int[maxItems];
public int[] GeneralshopfaladorN = new int[maxItems];
/*init shops */
public Shops() {
System.out.println("[ loaded shops ]");
/**
* this sets the shops empty
*/
for (int i = 0; i < 40; i++) {
Generalshoplumb[i] =-1;
Generalshopvarrock[i] =-1;
Generalshopfalador[i] =-1;
}
}
}
Now here we can create new shops, basically adding the items to the shop.
For example, i have made a custom shop with Rares in it.
Code:
public int[] RaresShop = {1038, 1040, 1042, 1044, 1046, 1048, 1050, 2651, 8928, 8959, 8960, 8961, 8962, 8963, 8964, 8965, 13**** 1053, 1055, 1057}; // the items
public int[] RaresShopN = {50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}; // the amout
This is the place to insert the item id:
Code:
public int[] RaresShop
And this is the place to insert the amount of the same item to be inserted into the shop:
Code:
public int[] RaresShopN
How do i open shops on my server?
Code:
Engine.shopHandler.openshop(p, 4);
All you have to do to open a shop on your server is add the above code to where you desire...
So if you were doing it in NpcOption1.java then you can simply do:
Code:
case 520: // Npc id
Engine.shopHandler.openshop(p, 4);
break;
How do i make it automatically show Player Stock?
To make it so when you click on the NPC and it automatically goes to the Player Stock instead of Main stock, simply do the following..
In ShopHandler.java with the cases, add this..
Code:
case 4: // Shop Case
p.frames.setShop(p, 700); // 700 is the Shop ID
items = Engine.shops.RaresShop; // Declaring this from Shops.java
itemsN = Engine.shops.RaresShopN; // Declaring this from Shops.java
p.frames.setItems(p, -1, 64209, 93, p.items, p.itemsN);
p.frames.setItems(p, -1, 64271, 31, items, itemsN);
break;
I've explained what the code does using comments..
Then add these in Engine.java
Code:
public static ShopHandler shopHandler = new ShopHandler();
public static Shops shops = new Shops();
If you get any errors you could also try importing this into Engine.java
Code:
import palidino76.rs2.content.*; // Please make sure Content is upper or lower case in your files...
Pictures of the Shops..
Credits: Serenity 100% for code.
No credits to me but i did write this tutorial, hope you can figure it out!
BTW IM ALWAYSSTUCK1 ON R-SERVER!! meh...
+
i asked serenity if i could post it here. And he approved, so yeh enjoy...
ps. You will get import errors, just fix them if you know what your doing..