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();
}
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:
} 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);
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();
}
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:
} 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!
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.
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.