Purpose: create a shop option to buy X Difficulty: 3 maybe? Assumed Knowledge: search, c+p, some java common sense Server Base: old cheeze, should work on all Classes Modified: Server side: client.java Client side: class9.java
Procedure
Client Side
Step 1: All we do is tell the client to say buy X
in class9.java search for
Step 1: First we make the shop accept buying X
in client.java search for
Code:
case 208: //Enter Amount Part 2
You should see a bunch of if/else ifs so we are just going to add another else if.
For example one you should see is
Code:
else if (XinterfaceID == 6669 && duelStatus >= 1) { //remove from duel window
fromDuel(XremoveID, XremoveSlot, EnteredAmount);
}
now add this else if
Code:
else if (XinterfaceID == 3900) { //Shop
if (EnteredAmount <= 10000)
buyItem(XremoveID, XremoveSlot, EnteredAmount);
else
sendMessage("You cannot buy more than 10k items at a time.");
}
I made it so you cannot buy more than 10k at a time, you can change that.
Step 2: Now we need to fix that it loops to buy each item one at a time, even if you buy 5k arrows
I thought it was reasonable not to loop if the purchase is over 100 of an item.
Search for
Code:
public boolean buyItem(int itemID, int fromSlot, int amount) {
and in that method there's a loop that looks like
Code:
for (int i = amount; i > 0; i--) {
above that add
Code:
if (amount > 100) {
TotPrice2 = (int)Math.floor(GetItemShopValue(itemID, 0, fromSlot))*amount;
Slot = GetItemSlot(995);
if (Slot == -1 && TotPrice2 != 0) {
sendMessage("You don't have enough coins.");
}
if(TotPrice2 <= 1) {
TotPrice2 = (int)Math.floor(GetItemShopValue(itemID, 0, fromSlot));
}
if (TotPrice2 <= 0) {
if (freeSlots() > 0) {
addItem(itemID, amount);
server.shopHandler.ShopItemsN[MyShopID][fromSlot] -= 1;
server.shopHandler.ShopItemsDelay[MyShopID][fromSlot] = 0;
if ((fromSlot + 1) > server.shopHandler.ShopItemsStandard[MyShopID]) {
server.shopHandler.ShopItems[MyShopID][fromSlot] = 0;
}
} else {
sendMessage("Not enough space in your inventory.");
}
} else if (playerItemsN[Slot] >= TotPrice2) {
if (freeSlots() > 0) {
deleteItem(995, GetItemSlot(995), TotPrice2);
addItem(itemID, amount);
server.shopHandler.ShopItemsN[MyShopID][fromSlot] -= amount;
server.shopHandler.ShopItemsDelay[MyShopID][fromSlot] = 0;
if ((fromSlot + 1) > server.shopHandler.ShopItemsStandard[MyShopID]) {
server.shopHandler.ShopItems[MyShopID][fromSlot] = 0;
}
} else {
sendMessage("Not enough space in your inventory.");
}
} else {
sendMessage("You don't have enough coins.");
}
}else{
then add another
Code:
}
at the end of the for loop
There you should be done.
Credits: Me, tj007razor
Video: [Only registered and activated users can see links. ]
$5 please? I accept paypal at [Only registered and activated users can see links. ]
else if (XinterfaceID == 3900) { //Shop
if (EnteredAmount <= 10000)
buyItem(XremoveID, XremoveSlot, EnteredAmount);
else
sM("You cannot buy more than 10k items at a time.");
}