danielmedvec Posted November 10, 2019 Share Posted November 10, 2019 7 hours ago, BravoTaco said: Hopefully this works, haven't tested. Let me know if it doesn't Hide contents //Use this when the item to receive, is not already in the inventory. public boolean itemReceived(String itemName, int amountToReceive) { Item temp; return (temp = mp.getInventory().getItem(itemName)) != null && temp.getAmount() == amountToReceive; } //Use this when the item to receive, is already in the inventory. public boolean itemReceivedWithSameItemInInventory(String itemName, int startAmount, int amountToReceive) { Item temp; return (temp = mp.getInventory().getItem(itemName)) != null && temp.getAmount() - startAmount == amountToReceive; } //Use this when the item you are trading will have no left-over amounts. public boolean itemTraded(String itemName) { return mp.getInventory().getItem(itemName) == null; } //Use this when the item you are trading will have left-over amounts. public boolean itemTradedWithLeftOverItemAmount(String itemName, int startAmount, int amountToTrade) { Item temp; return (temp = mp.getInventory().getItem(itemName)) == null || temp.getAmount() + amountToTrade == startAmount; } Could you please show an example on how to use this? Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted November 10, 2019 Author Share Posted November 10, 2019 (edited) 10 hours ago, danielmedvec said: Could you please show an example on how to use this? Sure can Trading Items: Spoiler //Something like this if you have more of an item in the inventory than you are attempting to trade //IE You have 200 Iron arrows in the inventory but only want to trade 100 of them. if (trader.trade("Player")) { if (trader.offerItem("Iron arrow", 100)) { if (trader.acceptTrade(true)) { // Item Name, The Amount that you started with in the inventory, And the amount you wanted to trade if (trader.itemTradedWithLeftOverItemAmount("Iron arrow", 200, 100)) { log("Item Successfully Traded!"); } else { log("Trade Unsuccessful!"); } } } } //This will be for if you will not have the item left-over in the inventory //IE You have 200 Iron arrows in the inventory and are trading all of them. if (trader.trade("Player")) { if (trader.offerItem("Iron arrow", 100)) { if (trader.acceptTrade(true)) { // Item Name if (trader.itemTraded("Iron arrow")) { log("Item Successfully Traded!"); } else { log("Trade Unsuccessful!"); } } } } Receiving Items: Spoiler //This will be for receiving an item when you already had the same item in the inventory //IE You have 100 Iron arrows in the inventory and are expecting to receive 200 more if (trader.trade("Player")) { if (trader.acceptTrade(true)) { // Item Name, The Amount that you started with in the inventory, And the amount you are expecting to receive if (trader.itemReceivedWithSameItemInInventory("Iron arrow", 100, 200)) { log("Item Successfully Received!"); } else { log("Trade Unsuccessful!"); } } } //This will be for receiving an item when you don't already have the item in the inventory //IE You are expecting to receive 100 iron arrows if (trader.trade("Player")) { if (trader.acceptTrade(true)) { // Item Name And the amount you are expecting to receive if (trader.itemReceived("Iron arrow", 100)) { log("Item Successfully Received!"); } else { log("Trade Unsuccessful!"); } } } Edited November 10, 2019 by BravoTaco 1 Quote Link to comment Share on other sites More sharing options...
danielmedvec Posted November 11, 2019 Share Posted November 11, 2019 30 minutes ago, BravoTaco said: Sure can Trading Items: Hide contents //Something like this if you have more of an item in the inventory than you are attempting to trade //IE You have 200 Iron arrows in the inventory but only want to trade 100 of them. if (trader.trade("Player")) { if (trader.offerItem("Iron arrow", 100)) { if (trader.acceptTrade(true)) { // Item Name, The Amount that you started with in the inventory, And the amount you wanted to trade if (trader.itemTradedWithLeftOverItemAmount("Iron arrow", 200, 100)) { log("Item Successfully Traded!"); } else { log("Trade Unsuccessful!"); } } } } //This will be for if you will not have the item left-over in the inventory //IE You have 200 Iron arrows in the inventory and are trading all of them. if (trader.trade("Player")) { if (trader.offerItem("Iron arrow", 100)) { if (trader.acceptTrade(true)) { // Item Name if (trader.itemTraded("Iron arrow")) { log("Item Successfully Traded!"); } else { log("Trade Unsuccessful!"); } } } } Receiving Items: Hide contents //This will be for receiving an item when you already had the same item in the inventory //IE You have 100 Iron arrows in the inventory and are expecting to receive 200 more if (trader.trade("Player")) { if (trader.acceptTrade(true)) { // Item Name, The Amount that you started with in the inventory, And the amount you are expecting to receive if (trader.itemReceivedWithSameItemInInventory("Iron arrow", 100, 200)) { log("Item Successfully Received!"); } else { log("Trade Unsuccessful!"); } } } //This will be for receiving an item when you don't already have the item in the inventory //IE You are expecting to receive 100 iron arrows if (trader.trade("Player")) { if (trader.acceptTrade(true)) { // Item Name And the amount you are expecting to receive if (trader.itemReceived("Iron arrow", 100)) { log("Item Successfully Received!"); } else { log("Trade Unsuccessful!"); } } } Thank you so much, i appreciate it! Quote Link to comment Share on other sites More sharing options...
danielmedvec Posted November 11, 2019 Share Posted November 11, 2019 How do you completely decline the trade? Say in case there was someone who have declined like 3 times, and i just want to cancel this trade. How do i make the process stop? Because i tried decline trade, but it still kept trading. Best regards Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted November 11, 2019 Author Share Posted November 11, 2019 32 minutes ago, danielmedvec said: How do you completely decline the trade? Say in case there was someone who have declined like 3 times, and i just want to cancel this trade. How do i make the process stop? Because i tried decline trade, but it still kept trading. Best regards Do you mean like not trade that person again? If so this will have to be done in your own script logic. An example would be to add that player to a blacklist after he has declined the trade or keep track of how many times that player has declined the trade and if it exceeds a certain threshold add them to the blacklist to not be traded again. Example Code Without Threshold (Untested): Spoiler private Trader trader; private ArrayList<String> blackListedNames = new ArrayList<>(); @Override public void onStart() throws InterruptedException { trader = new Trader(this); } @Override public int onLoop() throws InterruptedException { String playerName = "PlayerName"; if (!blackListedNames.contains(playerName) && trader.trade(playerName)) { if (trader.offerItem("Iron arrow", 100)) { if (trader.acceptTrade(true)) { if (trader.itemTradedWithLeftOverItemAmount("Iron arrow", 200, 100)) { log("Item Successfully Traded!"); } else { log("Trade Unsuccessful!"); blackListedNames.add(playerName); } } } } else { //Set the player name to a different player name. } return random(800, 3000); } Example Code With Threshold (Untested): Spoiler private Trader trader; private HashMap<String, Integer> playerTradeHistory = new HashMap<>(); private int threshold = 3; @Override public void onStart() throws InterruptedException { trader = new Trader(this); } @Override public int onLoop() throws InterruptedException { String playerName = "PlayerName"; if (playerTradeHistory.containsKey(playerName) && playerTradeHistory.get(playerName) < threshold && trader.trade(playerName) || !playerTradeHistory.containsKey(playerName) && trader.trade(playerName)) { if (trader.offerItem("Iron arrow", 100)) { if (trader.acceptTrade(true)) { if (trader.itemTradedWithLeftOverItemAmount("Iron arrow", 200, 100)) { log("Item Successfully Traded!"); //This will remove the player if they had declined some trades but finally accepted one of them. if(playerTradeHistory.containsKey(playerName)) playerTradeHistory.remove(playerName); } else { log("Trade Unsuccessful!"); if (playerTradeHistory.containsKey(playerName)) { int oldValue = playerTradeHistory.get(playerName); playerTradeHistory.replace(playerName, oldValue, oldValue + 1); } else { playerTradeHistory.put(playerName, 1); } } } } } else { //Set the player name to a different player name. } return random(800, 3000); } Quote Link to comment Share on other sites More sharing options...
BananaTown Posted March 3, 2022 Share Posted March 3, 2022 tried to use this and whenever the methods were called it would spam NPEs and cause my client to crash. I know this is old, just wanted to let other people who may want to use this know. Quote Link to comment Share on other sites More sharing options...
Wacky Jacky Posted June 17, 2023 Share Posted June 17, 2023 Can confirm it works, only if on the second trading screen, the player who gets offered the trade accepts before the bot/script running player presses accept, it will fail and indeed give a NPE. this is because it detects the text on top, when the normal player accepts, the bot gets to see “other player has accepted” and tries to click that instead of the accept trade button. lovely snippet thanks. Quote Link to comment Share on other sites More sharing options...
dubai Posted August 25 Share Posted August 25 Nice, I might incorporate this into my botfarm scripts Quote Link to comment Share on other sites More sharing options...