Introduction:
After having alot of trouble myself finding out how create a new shop I decided to make a clear tutorial myself. I am making this tutorial because i couldn't find any good tutorial on these forums myself.
Note that this tutorial will only work on a PI (Project Insanity) server.
Ok lets get started!
If you want to make a shop yourself you would have to do 6 things:
--1-- Find a non-combat NPC (with 0 combat and health etc).
--2-- Spawn the NPC to the location of your choice.
--3-- Create the shop itself.
--4-- Adding items to the shop
--5-- Make the NPC open the shop if you click on him.
--6-- Changing the prices.
--7-- Compile & Testing!
--EXTRA-- How to make it a points-shop.
--1-- FINDING A NON-COMBAT NPC
Open your source. Most of the time you can find a NPC-list in here: Source -> Data -> cfg. If you cant find return to your source and press CTRL+F, search for "npc". When you are in here look for a file called npc.cfg. Open it in your notepad
You will now see a large list of all monsters and NPC's in your source. If there are two 0's behind it means this NPC has a combat level of 0 and has 0 hitpoints.
Example:
npc = 209 Nulodion 0 0
npc = 210 Grail_Maiden 0 0
npc = 211 Sir_Percival 0 0
npc = 212 King_Percival 0 0
npc =
213 Merlin 0 0
npc = 214 Peasant 0 0
npc = 215 Peasant 0 0
npc = 216 High_Priest 0 0
npc = 217 Crone 0 0
npc = 218 Galahad 0 0
npc = 219 Fisherman 0 0
npc = 220 The_Fisher_King 0 0
If you found yourself a suitable NPC for your shop you have to remember the
NPC-ID standing before the NPC's name. If you arent good in remembering things write it down somewhere! As an example for this tutorial I will use the NPC 213, Merlin.
--2-- SPAWNING THE NPC TO THE LOCATION OF YOUR CHOICE
Open your source. Most of the time you can find the "spawn-config.cfg" in here: Source -> Data -> cfg. If you cant find it, return to your source and press CTRL+F, search for "spawn"
Open the file spawn-config.cfg. You will see once again a large list of all the monsters and NPC's that are spawned as soon as you log in.
starting from left to right: first you will see the ID of the NPC that has to be spawned, follow by the x-coords and the y-coords of where the NPC has to be spawned on the map. Example:
NPC ID - x-coords - y-coords-height-walk-maxhit-attack-defence-description.
spawn = 36 3083 3495 0 0 0 0 0 0 Wyson_the_Gardener
spawn = 213 3083 3496 0 0 0 0 0 0 Merlin
After that you will see five 0's and a name which mean the following
In this case they are all 0, because his height is normal, he cant walk, his max hit is 0, his attack is 0 and his defence is 0.
Enter your own spawn here like this:
spawn =
NPC-ID 3083 3496 0 0 0 0 0 0
Description
NPC-ID= your NPC ID
If you use the x and y-coords I use in my example above, the NPC will spawn in the middle of Edgeville.
Thats it for the spawning!
--3-- CREATING THE SHOP ITSELF
Open your source. Most of the time you can find the "shops.cfg" file in here: Source -> Data -> cfg. If you cant find it, return to your source and press CTRL+F, search for "shops" or "shop".
You will see a list of all the shops you have in your source.
Example:
To create your own shop, look for a
SHOP-ID that has not been used yet, I will use the
SHOP-ID 6 as an example for this tutorial.
In my shop above you will see from left to right: SHOP-ID, Name of the Shop, two 2's. The two 2's stand for if you can sell and buy to this shop.
Make one yourself now. Again, make sure you use an ID that has not been used yet!
--4-- ADDING ITEMS TO THE SHOP
Adding items to a shop is very simpel, the only thing you need to know is the ID of the item you want to add to the shop.
To look up the ID of an item go to Source -> Data -> Item. If you cant find it, return to your source and press CTRL+F, search for "item" or "items".
If you found yourself the ID of the item you want to add to your shop, paste it behind your shop in the shops.cfg file, following by the ammount the shop has of this item, like this:
shop = 6 Armor_Store 2 2
1127 50
In this case I have added the ID of a
rune platebody with the quanty of
50
If you want to add more items to the shop, simply paste the next item ID behind the ammount of the previous item, like this:
shop = 6 Armor_Store 2 2 1127 50
1079 50
1079 = rune platelegs.
--5-- MAKE THE NPC OPEN THE SHOP IF YOU CLICK ON HIM
Open your source. Most of the time you can find the "ActionHandler.java" file in here: Source -> src -> server -> model -> players. If you cant find it, return to your source and press CTRL+F, search for "action".
Open the actionhandler.java and press CTRL+F, search for "c.getShops().openShop" (just copy and paste from here).
Keep looking until you find a piece of code thats looks like this:
case 6750:
c.getShops().openShop(77);
break;
case 2830:
c.getShops().openShop(73);
c.sendMessage("You currently have " + c.pkPoints + " points.");
break;
case 5030:
c.getShops().openShop(74);
c.sendMessage("You currently have " + c.pkPoints + " points.");
break;
case 1294:
c.getShops().openShop(72);
break;
To add your own shop action typ the following:
case
NPC ID:
c.getShops().openShop(
SHOP ID);
break;
Enter the ID of your NPC and the ID of your shop on the right places.
In my case this would be:
case 213:
c.getShops().openShop(6);
break;
--6-- CHANGING THE PRICES
Open your source. Most of the time you can find the "prices.txt" in here: Source -> Data -> cfg. If you cant find it, return to your source and press CTRL+F, search for "prices.txt"
When you have opened the file you will see a very long list with all the item ID's and the prices behind them. Saying this we are almost done already!
Search the ID of the item you want to change price of and edit the number behind it to the price you want it to be!
--7-- COMPILE AND TEST
Make sure you save and close all windows you have opened and turn off your server. Look for the compiler in your source file and start compilen. If you find any errors post it on this thread and I or someone else will help you as soon as possible! Close the compiler correctly and test your shop in game!
EXTRA - HOW TO MAKE IT A POINTS SHOP
(NOT FINISHED YET)
Open your source. Most of the time you can find the "shopassistant.java" in here: Source -> src -> server-> model -> shops. If you cant find it, return to your source and press CTRL+F, search for "shopassistant.java".
When you open your file, you will see all the assistant a shop needs, such as letting you know how much an item is worth. That is what we are going to change first. A normal shop will tell you "This item current costs 20000 coins.", or something like that. We want it to become something like this: "This item current costs 10 (slayer/pking) points."
Press CTRL + F and search for:
public void buyFromShopPrice
You should see codes that look like this:
if (c.myShopId == 1) {
c.sendMessage(c.getItems().getItemName(removeId)+" : currently costs " + getSpecialItemValue(removeId) + " slayer points.");
return;
}
if (c.myShopId == 2) {
c.sendMessage(c.getItems().getItemName(removeId)+" : currently costs " + getSpecialItemValue(removeId) + " PK points.");
return;
}
We are going to make the exact same "if statement".
I want the shop I used as an example in this tutorial to become a Slayer Points shop.
First im going to explain what this piece of code meens:
if (c.myShopId == 213) {
c.sendMessage(c.getItems().getItemName(removeId)+":
currently costs " +
getSpecialItemValue(removeId) + "
Slayer Points.");
return;
}
This is the "if" statement that checks if you are using the right shop to continue reading the piece of code between the brackets( { and } ).
Enter your SHOP-ID here, in my case, this is 213.
The codes between the open ( { ) and close ( } ) brackets will be executed if the "if statement" is correct.
A variable thats sends the message between the two " to the players chatbox.
Gets the name of item you are checking the price from.
Gets the price of the item in points, which we willbe making soon.
Plain text that is send to the players chatbox
Now thats done, create your own "if statement"!
The next part we will be doing is making the shop an actual points shop. Still in the same file, look for "handleOtherShop(itemID)" with CTRL + F.
You should see a piece of code that looks like this:
if (c.myShopId == 1)
{
handleOtherShop(itemID);
return false;
}
if (c.myShopId == 2)
{
handleOtherShop(itemID);
return false;
}
This is also a piece of code that checks if the SHOP-ID is correct, simply copy and paste the statement below it and change the number to your SHOP-ID, in my case, this is 213. Make sure you paste the statement below or after the closing bracket of the statement above it!
The next part is giving each singel item in the shop its own price. Still in the same file, look for "public int getSpecialItemValue" with CTRL + F.
You will see a list of cases and returns. The numbers after the cases are the item id's, and the numbers after the returns are the prices of the items in points.
If I would like to have my item 1079 (Rune Platelegs) have a price of 10 points, it would look like this:
Always place a " : " after the case number and a " ; " after the price.
It is also possible to place multiple cases before a return, like this:
case 1127:
case 1079:
return 10;
This will safe you time and space. All the cases above the return now have the same price, which is 10, in my case.
Safe and close shopassistant.java and use the compiler while your server is offline. Now log in and check your shop in game!