Jump to content

Whipz Famous Events (BankEvent, LoadoutEvent, BankCache, GEEvent (Buy only) and more)


Recommended Posts

Posted (edited)

Hey guys; I have updated some of the things in here, there is now Bank Cache as well as GrandExchange but only for buying.

I have also added a showoffscript, just so you can see how it works;

Video: 

 

https://streamable.com/f5b3m1

Main Script: This is how you get the script to show up in script selection or it will not show up.

Spoiler
package scripts.core;

import org.tribot.script.Script;
import org.tribot.script.ScriptManifest;
import org.tribot.script.interfaces.Painting;
import scripts.core.paint.PaintInfo;
import scripts.core.paint.Painter;
import scripts.dax_api.api_lib.WebWalkerServerApi;
import scripts.dax_api.api_lib.models.DaxCredentials;
import scripts.dax_api.api_lib.models.DaxCredentialsProvider;

import java.awt.*;
import java.io.IOException;

@ScriptManifest(category = "Tools", authors = {"Whipz"}, name = "ShowOfScript")
public class ShowOffScript extends Script implements PaintInfo, Painting {

    final Painter corePaint = new Painter(this, Painter.PaintLocations.BOTTOM_LEFT_CHATBOX,
            new Color[] { new Color(255, 251, 255) }, "Trebuchet MS", new Color[] { new Color(93, 156, 236, 255) },
            new Color[] { new Color(39, 95, 175) }, 1, false, 5, 3, 0);

    @Override
    public void run() {
        WebWalkerServerApi.getInstance().setDaxCredentialsProvider(new DaxCredentialsProvider() {
            @Override
            public DaxCredentials getDaxCredentials() {
                return new DaxCredentials("sub_DPjXXzL5DeSiPf", "PUBLIC-KEY");
            }
        });
        while(true) {
            try {
                new ShowOffScriptEvent(this).execute();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public String[] getPaintInfo() {
        return new String[] {"Nothing to see here"};
    }

    @Override
    public void onPaint(Graphics g) {
        corePaint.paint(g);
    }

    /*@Override
	public void passArguments(HashMap<String, String> arg) {
		/*HashMap<String, String> parsedArgs = get(arg);
		if (parsedArgs.containsKey("BankEvent")) {
			General.println("BankEvent is: " + parsedArgs.get("BankEvent"));
		}
		if (parsedArgs.containsKey("LoadoutEvent")) {
			General.println("LoadoutEvent is: " + parsedArgs.get("LoadoutEvent"));
		}
}
    public static HashMap<String, String> get(HashMap<String, String> userInput) {
        if (userInput.containsKey("custom_input")) {
            return getFromString(userInput.get("custom_input"));
        }
        return new HashMap<>();
    }
    public static HashMap<String, String> getFromString(String argumentsString) {
        HashMap<String, String> arguments = new HashMap<>();
        if (argumentsString == null) {
            return arguments;
        }
        String[] argList = argumentsString.split(";(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); // Split everything by ;
        for (String currentArgument : argList) {
            if (!currentArgument.contains(":")) {
                break;
            }
            String[] argumentSplit = currentArgument.split(":");
            arguments.put(argumentSplit[0].replaceAll("^\"|\"$", ""), argumentSplit[1].replaceAll("^\"|\"$", ""));
        }
        return arguments;
    }*/

}

 

BotEvent: This is what every event will need to extend this allows for isCompleted() isFailed() and setInterruptionCondition() which allows you to stop an event for x reason and a few extra things from dax's api that i use for questing and other things which is easier to call from my botevent.

Spoiler

package scripts.core.botevent;

import org.tribot.api.DynamicClicking;
import org.tribot.api.General;
import org.tribot.api.input.Keyboard;
import org.tribot.api2007.Interfaces;
import org.tribot.api2007.Login;
import org.tribot.api2007.Login.STATE;
import org.tribot.api2007.Player;
import org.tribot.api2007.types.*;
import org.tribot.script.Script;
import scripts.core.utilities.Methods;
import scripts.core.utilities.Walker;
import scripts.dax_api.shared.helpers.InterfaceHelper;
import scripts.dax_api.walker_engine.WaitFor;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public abstract class BotEvent {

	private boolean complete = false;
	private boolean failed = true;

	protected Supplier<Boolean> interruptCondition;

	private final ArrayList<Supplier<Boolean>> conditionList = new ArrayList<>();

	protected Script script;

	public BotEvent(Script script) {
		super();
		this.script = script;
	}

	public BotEvent setInterruptCondition(Supplier<Boolean> interuptCondition) {
		this.interruptCondition = interuptCondition;
		return this;
	}

	public BotEvent reset() {
		this.complete = false;
		this.failed = true;
		return this;
	}

	public abstract void step() throws InterruptedException, IOException;

	public void setComplete() {
		this.complete = true;
		this.failed = false;
	}

	public boolean isComplete() {
		return complete;
	}

	public boolean isFailed() {
		return failed;
	}

	public void execute() throws InterruptedException, IOException {
		executed();
	}

	public boolean executed() throws InterruptedException, IOException {
		while (!isComplete() && script.isActive() && !script.isPaused()) {
			if (Login.getLoginState().equals(STATE.INGAME)) {
				for (Supplier<Boolean> condition : conditionList) {
					if (!condition.get()) {
						setComplete();
						return true;
					}
				}
				if (interruptCondition != null && interruptCondition.get()) {
					setComplete();
				} else if (!script.isPaused()) {
					step();
				}
			}
		}
		return isComplete() && !isFailed();
	}

	protected RSInterface getClickHereToContinue() {
		List<RSInterface> list = getConversationDetails();
		if (list == null) {
			return null;
		}
		Optional<RSInterface> optional = list.stream()
				.filter(rsInterface -> rsInterface.getText().equals("Click here to continue")).findAny();
		return optional.orElse(null);
	}

	private void waitForNextOption() {
		List<String> interfaces = getAllInterfaces().stream().map(RSInterface::getText).collect(Collectors.toList());
		WaitFor.condition(2500, () -> {
			if (!interfaces
					.equals(getAllInterfaces().stream().map(RSInterface::getText).collect(Collectors.toList()))) {
				return WaitFor.Return.SUCCESS;
			}
			return WaitFor.Return.IGNORE;
		});
	}

	public void waitForConversationWindow() {
		RSPlayer player = Player.getRSPlayer();
		RSCharacter rsCharacter = null;
		if (player != null) {
			rsCharacter = player.getInteractingCharacter();
		}
		WaitFor.condition(rsCharacter != null ? WaitFor.getMovementRandomSleep(rsCharacter) : 5000, () -> {
			if (isConversationWindowUp()) {
				return WaitFor.Return.SUCCESS;
			}
			return WaitFor.Return.IGNORE;
		});
	}

	protected void clickHereToContinue() {
		General.println("Clicking continue.");
		Keyboard.typeKeys(' ');
		waitForNextOption();
	}

	private List<RSInterface> getConversationDetails() {
		for (int window : ALL_WINDOWS) {
			List<RSInterface> details = InterfaceHelper.getAllInterfaces(window).stream().filter(rsInterfaceChild -> {
				if (rsInterfaceChild.getTextureID() != -1) {
					return false;
				}
				String text = rsInterfaceChild.getText();
				return text != null && text.length() > 0;
			}).collect(Collectors.toList());
			if (details.size() > 0) {
				General.println("Conversation Options: ["
						+ details.stream().map(RSInterface::getText).collect(Collectors.joining(", ")) + "]");
				return details;
			}
		}
		return null;
	}

	private List<RSInterface> getAllOptions(String... options) {
		final List<String> optionList = Arrays.stream(options).map(String::toLowerCase).collect(Collectors.toList());
		List<RSInterface> list = getConversationDetails();
		return list != null
				? list.stream().filter(rsInterface -> optionList.contains(rsInterface.getText().trim().toLowerCase()))
						.collect(Collectors.toList())
				: null;
	}

	public void handleChatV2(String... options) {
		General.println("Handling... " + Arrays.asList(options));
		List<String> blackList = new ArrayList<>();
		int limit = 0;
		while (limit++ < 50) {
			if (WaitFor.condition(General.random(650, 800), () -> isConversationWindowUp() ? WaitFor.Return.SUCCESS
					: WaitFor.Return.IGNORE) != WaitFor.Return.SUCCESS) {
				General.println("Conversation window not up.");
				break;
			}

			if (getClickHereToContinue() != null) {
				clickHereToContinue();
				limit = 0;
				continue;
			}

			List<RSInterface> selectableOptions = getAllOptions(options);
			if (selectableOptions == null || selectableOptions.size() == 0) {
				WaitFor.milliseconds(150);
				continue;
			}

			for (RSInterface selected : selectableOptions) {
				if (blackList.contains(selected.getText())) {
					continue;
				}
				General.sleep(General.randomSD(350, 2250, 775, 350));
				General.println("Replying with option: " + selected.getText());
				blackList.add(selected.getText());
				Keyboard.typeString(selected.getIndex() + "");
				waitForNextOption();
				limit = 0;
				break;
			}
			General.sleep(10, 20);
		}
		if (limit > 50) {
			General.println("Reached conversation limit.");
		}
	}

	private final static int ITEM_ACTION_INTERFACE_WINDOW = 193;
	private final static int NPC_TALKING_INTERFACE_WINDOW = 231;
	private final static int PLAYER_TALKING_INTERFACE_WINDOW = 217;
	private static final int SELECT_AN_OPTION_INTERFACE_WINDOW = 219;
	private final static int SINGLE_OPTION_DIALOGUE_WINDOW = 229;

	private final static int[] ALL_WINDOWS = new int[] { ITEM_ACTION_INTERFACE_WINDOW, NPC_TALKING_INTERFACE_WINDOW,
			PLAYER_TALKING_INTERFACE_WINDOW, SELECT_AN_OPTION_INTERFACE_WINDOW, SINGLE_OPTION_DIALOGUE_WINDOW };

	public boolean talkToV2(String name, RSArea area) {
		if (area != null && !area.contains(Player.getRSPlayer().getPosition())) {
			General.println("Walking to NPC: " + name);
			Walker.walkToArea(area);
		} else {
			RSNPC npc = Methods.getNPC(name);
			if (npc != null) {
				if (npc.isOnScreen()) {
					if (DynamicClicking.clickRSNPC(npc, "Talk-to")) {
						waitForConversationWindow();
					}
				} else {
					General.println("Rotating Camera to npc: " + npc);
					npc.adjustCameraTo();
				}
			}
		}
		return isConversationWindowUp();
	}

	public boolean isConversationWindowUp() {
		return Arrays.stream(ALL_WINDOWS).anyMatch(Interfaces::isInterfaceValid);
	}

	private List<RSInterface> getAllInterfaces() {
		ArrayList<RSInterface> interfaces = new ArrayList<>();
		for (int window : ALL_WINDOWS) {
			interfaces.addAll(InterfaceHelper.getAllInterfaces(window));
		}
		return interfaces;
	}

}

 

 

Main Event: This is where you add all your events, this is basically the main part of your script. You would add banking grand exchange loadout etc plus whatever else you are wanting to do.

Spoiler

package scripts.core;

import org.tribot.script.Script;
import org.tribot.script.sdk.tasks.BankTask;
import scripts.core.banking.BankEventV2;
import scripts.core.botevent.BotEvent;
import scripts.core.equipment.LoadoutEvent;
import scripts.core.grandexchange.GEEvent;

import java.io.IOException;

public class ShowOffScriptEvent extends BotEvent {

    BankEventV2 bankEvent;
    LoadoutEvent loadoutEvent;
    BankEventV2 bankLoadout;
    GEEvent geEvent;
    BankTask bankTask;

    public ShowOffScriptEvent(Script script) {
        super(script);
        bankLoadout = new BankEventV2(script).addReq("Staff of earth",1);
        loadoutEvent = new LoadoutEvent(script, bankLoadout);
        bankEvent = new BankEventV2(script).addReq("Potato", 10);
        geEvent = new GEEvent(script, bankEvent).addReq("Potato", 10, 300).addReq("Vial", 10, 100).addReq("Bronze axe", 2, 1000);

    }

    @Override
    public void step() throws InterruptedException, IOException {
        if(loadoutEvent.isPendingOperation()) {
            loadoutEvent.execute();
            loadoutEvent.reset();
        } else if(bankEvent.isPendingOperation()) {
		bankEvent.execute();
		bankEvent.reset();
	}
    }
}

 

BankEvent: This handles all your banking needs. It has a fair few features, such as withdrawing based on conditions, noted items etc

Spoiler

package scripts.core.banking;

import org.tribot.api.General;
import org.tribot.api.Timing;
import org.tribot.api2007.Objects;
import org.tribot.api2007.*;
import org.tribot.api2007.types.RSItem;
import org.tribot.api2007.types.RSItemDefinition;
import org.tribot.api2007.types.RSNPC;
import org.tribot.api2007.types.RSObject;
import org.tribot.script.Script;
import scripts.core.botevent.BotEvent;
import scripts.core.inventory.InventoryEvent;
import scripts.core.requistion.RequisitionItem;
import scripts.dax_api.api_lib.DaxWalker;

import java.io.IOException;
import java.util.*;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.tribot.api2007.Inventory.getAll;

public class BankEventV2 extends BotEvent {

    public  HashMap<String, BankCache> bankCacheHashMap = new HashMap<>();

    public LinkedHashMap<String, RequisitionItem> withdrawList = new LinkedHashMap<>();

    public BankEventV2(Script script) {
        super(script);
    }

    String finalItem;

    @Override
    public void step() throws InterruptedException, IOException {
        if(GrandExchange.getWindowState() != null) {
            GrandExchange.close();
            Timing.waitCondition( () -> GrandExchange.getWindowState() == null, 4000);
        } else
        if (!Banking.isBankScreenOpen()) {
            RSObject[] bank = Objects.find(20, "Bank booth");
            RSNPC[] banker = NPCs.find("Banker");
            RSObject[] chest = Objects.find(20, "Bank chest", "Open chest");
            if (bank.length < 1 && banker.length < 1 && chest.length < 1) {
                General.println("BankEvent: Walking to closest bank");
                DaxWalker.walkToBank();
                Timing.waitCondition( () -> Banking.isInBank() || !Player.getRSPlayer().isMoving(), 20000);
            } else if (Banking.openBank()) {
                General.println("BankEvent opening bank");
                Timing.waitCondition(Banking::isBankLoaded, 2000);
                updateCache();
            }
            return;
        }

        if (!Banking.isBankLoaded()) {
            return;
        }

        if (!InventoryEvent.containsOnly(arryOfItemsToWithdraw())) {
            General.println("Banking unreqired items");
            Banking.depositAllExcept(arryOfItemsToWithdraw());
            Timing.waitCondition( () -> InventoryEvent.containsOnly(arryOfItemsToWithdraw()), 6000);
        }
        for (Map.Entry<String, RequisitionItem> withdrawList : withdrawList.entrySet()) {
            RequisitionItem reqItem = withdrawList.getValue();
            String itemName = reqItem.getName();
            int amount = reqItem.getQty();
            Supplier<Boolean> itemCondition = reqItem.getCondition();
            boolean noted = reqItem.getNoted();
            finalItem = "";

            if (itemName.contains("~")) {
                if (finalItem.equals("")) {
                    List<String> expandedItem = expandItemName(itemName);
                    for (String item : expandedItem) {
                        if (contains(item)) {
                            finalItem = item;
                            break;
                        }
                    }
                }
            } else {
                finalItem = itemName;
            }
            if(finalItem.equals("")) {
                continue;
            }
            /*if (!itemCondition.get()) {
                General.println("BankEvent: Banking unrequired items part2");
                General.println("Checking item: " + itemName + " amount: " + amount + " noted: " + noted); //You're not checking finalItem we're checking the itemName
                Banking.deposit(Integer.MAX_VALUE, finalItem);
                continue;
            }*/
            RSItem finalRsItem = InventoryEvent.getInventoryItem(finalItem);
            RSItemDefinition finalItemDefinition = null;
            if(finalRsItem != null) {
                finalItemDefinition = finalRsItem.getDefinition();
            }
            General.println("Checking item: " + finalItem + " amount: " + amount + " noted: " + noted);
            if(!itemCondition.get()) {
                if(InventoryEvent.contains(finalItem)) {
                    Banking.deposit(Integer.MAX_VALUE, finalItem);
                    Timing.waitCondition( () -> !InventoryEvent.contains(finalItem), 3000);
                }
                continue;
            }

            if (InventoryEvent.contains(finalRsItem) && finalItemDefinition != null && !finalItemDefinition.isNoted() && noted) {
                General.println("Depositing item: "+finalItem+" we need noted");
                Banking.deposit(InventoryEvent.getCount(itemName), itemName);
                Timing.waitCondition(() -> !InventoryEvent.contains(finalRsItem), 2000);
            } else if (!bankCacheHashMap.containsKey(finalItem) || !contains(finalItem)) {
                General.println("Stopping we dont have item '"+finalItem+"' in bank");
                updateCache();
                setComplete();
            } else if (!InventoryEvent.contains(finalItem)) {
                if(!itemCondition.get()) {
                    General.println("Skipping do to not needing item");
                    continue;
                }
                boolean setStatus = setWithdrawNoted(noted);
                if (!setStatus) {
                    continue;
                } else if (noted) {
                    General.println("Withdrawing noted: " + finalItem);
                }
                if (Banking.withdraw(amount, finalItem)) {
                    Timing.waitCondition(() -> InventoryEvent.contains(finalItem), 2000);
                }
            } else if (InventoryEvent.contains(finalItem) && finalRsItem != null) {
                boolean isStackable = finalItemDefinition != null && finalItemDefinition.isStackable();
                int itemCount = isStackable ? finalRsItem.getStack() : InventoryEvent.getCount(finalItem);
                boolean shouldWithdraw = itemCount < amount;
                boolean setWithdrawStatus = setWithdrawNoted(noted);
                BooleanSupplier bankWaitCondition = isStackable ? () -> InventoryEvent.getStackedCount(finalItem) == amount : () -> InventoryEvent.getCount(finalItem) == amount;

                if (shouldWithdraw && Banking.withdraw(amount - itemCount, finalItem)) {
                    Timing.waitCondition(bankWaitCondition, 2000);
                }
            }
        }
        General.println("Trying to update cache");
        updateCache();
        Banking.close();
        setComplete();
    }

    public void setWithdrawList(String itemName, int amount, boolean noted, Supplier<Boolean> condition) {
        if (withdrawList.containsKey(itemName)) {
            if (withdrawList.get(itemName).getQty() != amount) {
                withdrawList.replace(itemName, new RequisitionItem(itemName, amount, noted, condition));
            }
        } else {
            withdrawList.put(itemName, new RequisitionItem(itemName, amount, noted, condition));
        }
    }

    public BankEventV2 addReq(String itemName, int amount) {
        setWithdrawList(itemName, amount, false, () -> true);
        return this;
    }

    public BankEventV2 addReq(String itemName, int amount, Supplier<Boolean> condition) {
        setWithdrawList(itemName, amount, false, condition);
        return this;
    }

    public BankEventV2 addReq(String itemName, int amount, boolean noted) {
        setWithdrawList(itemName, amount, noted, () -> true);
        return this;
    }

    public BankEventV2 addReq(String itemName, int amount, boolean noted, Supplier<Boolean> condition) {
        setWithdrawList(itemName, amount, noted, condition);
        return this;
    }

    public static boolean setWithdrawNoted(boolean enable) {
        return enable ? setNoted() : setUnNoted();
    }

    public static boolean setNoted() {
        if (Game.getSetting(115) != 1) {
            Interfaces.get(12, 23).click("Note");
        }
        return Game.getSetting(115) == 1;
    }

    public static boolean setUnNoted() {
        if (Game.getSetting(115) == 1) {
            Interfaces.get(12, 21).click("Item");
        }
        return Game.getSetting(115) != 1;
    }

    public String[] arryOfItemsToWithdraw() {
        General.println(withdrawList.keySet());
        return withdrawList.keySet().toArray(new String[0]);
    }

    public boolean isPendingOperation() {
        for (Map.Entry<String, RequisitionItem> withdrawList : withdrawList.entrySet()) {
            String itemName = withdrawList.getKey();
            finalItem = "";
            Supplier<Boolean> cond = withdrawList.getValue().getCondition();
            boolean noted = withdrawList.getValue().getNoted();
            if (cond.get()) {
                if (itemName.contains("~")) {
                    List<String> expandedItem = expandItemName(itemName);
                    if (expandedItem.size() > 0) {
                        for (String item : expandedItem) {
                            if (InventoryEvent.contains(item)) {
                                finalItem = item;
                                break;
                            }
                        }
                    }
                } else {
                    finalItem = itemName;
                }
                if(finalItem.equals("")) {
                    continue;
                }
                RSItem item = InventoryEvent.getInventoryItem(finalItem);
                if (noted) {
                    if (item != null) {
                        if (!item.getDefinition().isNoted()) {
                            General.println("We need noted: " + finalItem);
                            return true;
                        }
                    } else {
                        return true;
                    }
                } else if (!InventoryEvent.contains(finalItem)) {
                    General.println("BankEvent is Pending Operation: We dont have: " + finalItem);
                    return true;
                }
            }
        }
        return false;
    }

    public RSItem getBankItem(String... itemNames) {
        RSItem[] items = Banking.find(itemNames);
        for (RSItem item : items) {
            if (item != null) {
                return item;
            }
        }
        return null;
    }

    public int getCount(String... itemNames) {
        int amount = 0;
        if (getBankItem(itemNames) != null) {
            amount = getBankItem(itemNames).getStack();
        }
        return amount;
    }

    public boolean contains(String itemName) {
        return Banking.find(itemName).length >=1;
    }

    public void bankEquipment() {
        if (!Banking.isBankScreenOpen()) {
            if (!Banking.isInBank()) {
                DaxWalker.walkToBank();
            } else if (Banking.openBank()) {
                Timing.waitCondition(Banking::isBankScreenOpen, 2000);
            }
        } else {
            if (Banking.depositEquipment()) {
                Timing.waitCondition(() -> Equipment.getItems().length == 0, 2000);
            }
        }
    }

    public static List<String> expandItemName(String name) {
        ArrayList<String> names = new ArrayList<>();
        Pattern pattern = Pattern.compile("^(.*?)([0-9]+)~([0-9]+)(.*?)$");
        Matcher matcher = pattern.matcher(name);
        if (matcher.find()) {
            String prepend = matcher.group(1), append = matcher.group(4);
            int start = Integer.parseInt(matcher.group(2)), finish = Integer.parseInt(matcher.group(3)),
                    dir = start > finish ? -1 : 1;
            for (int i = start; i * dir <= finish * dir; i += dir) {
                names.add(prepend + i + append);
            }
        } else {
            pattern = Pattern.compile("^(.*?)\\{(.*?)}(.*?)$");
            matcher = pattern.matcher(name);
            if (matcher.find()) {
                String prepend = matcher.group(1), append = matcher.group(3);
                String[] tings = matcher.group(2).split(";");
                for (String t : tings) {
                    names.add((prepend + t + append).trim());
                }
            } else {
                names.add(name);
            }
        }
        return names;
    }

    public void openBank() {
        if (!Banking.isBankScreenOpen()) {
            RSObject[] bank = Objects.find(20, "Bank booth");
            RSNPC[] banker = NPCs.find("Banker");
            RSObject[] chest = Objects.find(20, "Bank chest", "Open chest");
            if (bank.length < 1 && banker.length < 1 && chest.length < 1) {
                General.println("BankEvent: Walking to closest bank");
                DaxWalker.walkToBank();
                Timing.waitCondition(() -> Banking.isInBank() || !Player.getRSPlayer().isMoving(), 20000);
            } else if (Banking.openBank()) {
                General.println("BankEvent opening bank");
                Timing.waitCondition(Banking::isBankScreenOpen, 2000);
            }
        } else {
            depositAll();
            General.sleep(1000);
            updateCache();
        }
    }

    public void depositAll() {
        if(Banking.isBankScreenOpen()) {
            if(getAll().length > 0) {
                Banking.depositAll();
            }
        }
    }

    public boolean needCache() {
        return bankCacheHashMap.isEmpty();
    }

    public void updateItem(String itemName, int id, int amount) {
        if(bankCacheHashMap.containsKey(itemName)) {
            bankCacheHashMap.replace(itemName, new BankCache(itemName, id, amount));
        } else {
            bankCacheHashMap.put(itemName, new BankCache(itemName, id, amount));
        }
    }

    public void updateCache() {
        if(!Banking.isBankScreenOpen() && Banking.isBankLoaded()) {
            General.println("Bank is not open cannot continue");
            return;
        } else {
            bankCacheHashMap = new HashMap<>();
            RSItem[] bankCache = Banking.getAll();
            for(int i = 0; bankCache.length > i;i++) {
                General.println("Updating cache: "+bankCache[i].getDefinition().getName() +" ID: "+ bankCache[i].getDefinition().getID()+ " qty: "+bankCache[i].getStack());
                updateItem(bankCache[i].getDefinition().getName(), bankCache[i].getDefinition().getID(), bankCache[i].getStack());
            }
            RSItem[] equipment = Equipment.getItems();
            for(int i=0; equipment.length> i;i++) {
                General.println("Updating cache: "+equipment[i].getDefinition().getName() +" ID: "+ equipment[i].getDefinition().getID()+ " qty: "+equipment[i].getStack());
                updateItem(equipment[i].getDefinition().getName(), equipment[i].getDefinition().getID(), equipment[i].getStack());
            }
        }
    }
}

 

BankCache: This is BankCache Item handler

Spoiler

package scripts.core.banking;

import java.util.HashMap;

public class BankCache {

    static HashMap<String, BankCache> bankCacheHashMap = new HashMap<String, BankCache>();

    public String name;
    public  int id;
    public int qty;

    public BankCache(String itemName, int id, int qty) {
        this.name = itemName;
        this.id = id;
        this.qty = qty;
    }

    public String getName() {
        return name;
    }

    public int getId() {
        return id;
    }

    public int getQty() {
        return qty;
    }







}

 

RequisitionItem: This information stored about items in the bankevent;

Spoiler

package scripts.core.requistion;

import java.util.function.Supplier;

public class RequisitionItem {

	public final String name;
	public final int qty;
	public final Supplier<Boolean> cond;
	public final boolean noted;

	public RequisitionItem(String name, int qty, boolean noted, Supplier<Boolean> cond) {
		this.name = name;
		this.qty = qty;
		this.noted = noted;
		this.cond = cond;
	}

	public String getName() {
		return name;
	}

	public int getQty() {
		return qty;
	}

	public boolean getNoted() {
		return noted;
	}

	public Supplier<Boolean> getCondition() {
		return cond;
	}

}

 

LoadoutEvent: This handles banking and equipping items.

Spoiler

package scripts.core.equipment;

import org.tribot.api.Clicking;
import org.tribot.api.General;
import org.tribot.api.Timing;
import org.tribot.api.input.Mouse;
import org.tribot.api2007.Banking;
import org.tribot.api2007.Equipment;
import org.tribot.api2007.Game;
import org.tribot.api2007.Magic;
import org.tribot.api2007.types.RSItem;
import org.tribot.script.Script;
import scripts.core.banking.BankEventV2;
import scripts.core.botevent.BotEvent;
import scripts.core.inventory.InventoryEvent;
import scripts.core.requistion.RequisitionItem;
import scripts.core.utilities.Methods;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Supplier;


public class LoadoutEvent extends BotEvent {
    BankEventV2 bankEventV2;
    String finalItem = null;

    public LoadoutEvent(Script script, BankEventV2 bankEvent) {
        super(script);
        this.bankEventV2 = bankEvent;
    }

    public static RSItem getEquipmentItem(String... name) {
        RSItem[] items = Equipment.find(name);
        if (items != null) {
            for (RSItem item : items) {
                if (item != null) {
                    return item;
                }
            }
        }
        return null;
    }

    public static RSItem getEquipmentPartName(String partName) {
        RSItem[] items = Equipment.find(i -> i.getDefinition().getName().contains(partName));
        for (RSItem item : items) {
            if (item != null) {
                return item;
            }
        }
        return null;
    }

    public static RSItem getEquipmentID(int id) {
        RSItem[] items = Equipment.find(i -> i.getDefinition().getID() == id);
        for (RSItem item : items) {
            if (item != null) {
                return item;
            }
        }
        return null;
    }

    public static boolean isWearing(String... string) {
        return Equipment.isEquipped(string);
    }

    public static boolean isWearing(String string) {
        if (string.contains("~")) {
            List<String> expandedItem = BankEventV2.expandItemName(string);
            if (expandedItem.size() > 0) {
                for (String item : expandedItem) {
                    if (Equipment.isEquipped(item)) {
                        return true;
                    }
                }
            }
        } else {
            return Equipment.isEquipped(string);
        }
        return false;
    }

    public static boolean isWearingPartName(String partName) {
        RSItem[] items = Equipment.find(i -> i.getDefinition().getName().contains(partName));
        for (RSItem item : items) {
            if (item != null) {
                return item != null;
            }
        }
        return false;
    }

    public boolean isPendingOperation() {
        for (Map.Entry<String, RequisitionItem> withdrawList : bankEventV2.withdrawList.entrySet()) {
            String itemName = withdrawList.getKey();
            finalItem = "";
            Supplier<Boolean> cond = withdrawList.getValue().getCondition();
            boolean noted = withdrawList.getValue().getNoted();
            if (cond.get()) {
                if (itemName.contains("~")) {
                    List<String> expandedItem = BankEventV2.expandItemName(itemName);
                    if (expandedItem.size() > 0) {
                        for (String item : expandedItem) {
                            if (Equipment.isEquipped(item)) {
                                finalItem = itemName;
                                return false;
                            }
                        }
                    }
                } else {
                    finalItem = itemName;
                }
                RSItem item = LoadoutEvent.getEquipmentItem(finalItem);
                if (finalItem == "") {
                    General.println("Skipping final Item is: empty");
                } else {
                    return !LoadoutEvent.isWearing(finalItem);
                }
            }
        }
        return false;
    }

    @Override
    public void step() throws InterruptedException, IOException {
        if (!isPendingOperation()) {
            General.println("LoadoutEvent is complete");
            setComplete();
        } else {
            for (Entry<String, RequisitionItem> withdrawList : bankEventV2.withdrawList.entrySet()) {
                String itemName = withdrawList.getKey();
                Supplier<Boolean> cond = withdrawList.getValue().getCondition();
                finalItem = "";
                if (cond.get()) {
                    if (itemName.contains("~")) {
                        List<String> expandedItem = BankEventV2.expandItemName(itemName);
                        if (expandedItem.size() > 0) {
                            for (String item : expandedItem) {
                                if (InventoryEvent.contains(item)) {
                                    finalItem = item;
                                    break;
                                }
                            }
                        }
                    } else {
                        finalItem = itemName;
                    }
                    if(isWearing(finalItem)) {
                    	continue;
					}else
                    if (Magic.isSpellSelected()) {
                        Mouse.click(1);
                    } else if (InventoryEvent.contains(finalItem)) {
                        General.println("LoadoutEvent: Inventory contains: " + finalItem);
                        if (Banking.isBankScreenOpen()) {
                            Banking.close();
                            Timing.waitCondition(() -> !Banking.isBankScreenOpen(), 5000);
                        } else {
                            RSItem item = Methods.getInventoryItem(finalItem);
                            if (InventoryEvent.contains("Vial")) {
                                General.println("Dropping vial");
                                RSItem vial = Methods.getInventoryItem("Vial");
                                if (Game.getItemSelectionState() == 0) {
                                    if (vial.click("Drop")) {
                                        Timing.waitCondition(() -> !InventoryEvent.contains("Vial"), 2000);
                                    }
                                } else {
                                    General.println("Deselecting vial LoadoutEvent");
                                    Clicking.click(vial);
                                    Timing.waitCondition(() -> Game.getItemSelectionState() == 0, 1000);
                                }
                            } else if (Game.getItemSelectionState() == 0) {
                                General.println("ItemSelection State: 0");
                                if (item != null) {
                                    General.println("Loadout: Equiping item.. " + item.getDefinition().getName());
                                    if (item.click("Wear", "Wield", "Weild", "Equip")) {
                                        Timing.waitCondition(() -> Equipment.isEquipped(item.getDefinition().getName()),
                                                500);
                                    }
                                }
                            } else {
                                General.println("Trying to deselect item LoadoutEvent");
                                Clicking.click(item);
                                Timing.waitCondition(() -> Game.getItemSelectionState() == 0, 1000);
                            }
                        }
                    } else if (bankEventV2.isPendingOperation()) {
                        bankEventV2.execute();
                        bankEventV2.reset();
                    }
                }
            }
        }
    }

}

 

GEEvent: This handles buying items you require and will by the right amount depending on how much of the item you have in your bank. Once purchased and is in your inventory the BankCache will also be updated.

Spoiler

package scripts.core.grandexchange;

import org.tribot.api.General;
import org.tribot.api.Timing;
import org.tribot.api2007.*;
import org.tribot.api2007.types.*;
import org.tribot.script.Script;
import scripts.core.banking.BankCache;
import scripts.core.banking.BankEventV2;
import scripts.core.botevent.BotEvent;
import scripts.core.inventory.InventoryEvent;
import scripts.core.utilities.Methods;
import scripts.core.utilities.Walker;
import scripts.dax_api.walker.utils.AccurateMouse;

import java.io.IOException;
import java.util.Objects;
import java.util.*;

public class GEEvent extends BotEvent {

    public HashMap<String, GrandExchangeItem> grandExchangeItemHashMap = new HashMap<>();
    public HashMap<String, GrandExchangeItem> grandExchangeSellHashMap = new HashMap<>();
    public int itemChild;
    BankEventV2 bankEvent;
    RSArea grandExchangeArea = new RSArea(
            new RSTile[]{
                    new RSTile(3157, 3494, 0),
                    new RSTile(3157, 3487, 0),
                    new RSTile(3162, 3483, 0),
                    new RSTile(3169, 3483, 0),
                    new RSTile(3173, 3487, 0),
                    new RSTile(3173, 3494, 0),
                    new RSTile(3168, 3498, 0),
                    new RSTile(3161, 3498, 0)
            }
    );
    ExchangeBoxes boxes;

    public GEEvent(Script script, BankEventV2 bankEvent) {
        super(script);
        this.bankEvent = bankEvent;
        bankEventV2= new BankEventV2(script).addReq("Coins", Integer.MAX_VALUE);

    }

    public GEEvent addReq(String itemName, int id, int qty, int price) {
        setGrandExchangeItemIDList(itemName, id, qty, price);
        return this;
    }

    public GEEvent addReq(String itemName, int qty, int price) {
        setGrandExchangeItemList(itemName, qty, price);
        return this;
    }

    public GEEvent sellReq(String itemName, int price) {
        setGrandExchangeSellList(itemName, price);
        General.println("Selling item: "+itemName +" pride: "+price);
        return this;
    }

    public void setGrandExchangeSellList(String itemName, int price) {
        grandExchangeSellHashMap.put(itemName, new GrandExchangeItem(itemName, price));
    }

    public boolean isPendingOperation() {
        for (Map.Entry<String, GrandExchangeItem> grandExchangeList : grandExchangeItemHashMap.entrySet()) {
            String itemName = grandExchangeList.getKey();
            if (!bankEvent.bankCacheHashMap.containsKey(itemName)) {
                General.println("Grand Exchange: We dont have: "+itemName);
                return true;
            }
        }
        return false;
    }

    public void setGrandExchangeItemIDList(String itemName, int id, int qty, int price) {
        grandExchangeItemHashMap.put(itemName, new GrandExchangeItem(itemName, id, qty, price));
    }

    public void setGrandExchangeItemList(String itemName, int qty, int price) {
        grandExchangeItemHashMap.put(itemName, new GrandExchangeItem(itemName, qty, price));
    }

    @Override
    public void step() throws InterruptedException, IOException {
        if (!isPendingOperation()) {
            if (!canOpenExchange()) {
                closeGrandExchange();
            } else if (!Banking.isBankScreenOpen()) {
                bankEventV2.openBank();
            } else {
                bankEventV2.depositAll();
                bankEventV2.updateCache();
                setComplete();
            }
        } else if (!grandExchangeArea.contains(me())) {
            Walker.walkToArea(grandExchangeArea);
            Timing.waitCondition( () -> grandExchangeArea.contains(me()), 10000);
        } else {
            if (needCoins()) {
                getCoins();
            } else if (Banking.isBankScreenOpen()) {
                Banking.close();
                Timing.waitCondition(() -> !Banking.isBankScreenOpen(), 4000);
            } else if (canOpenExchange()) {
                openGrandExchange();
            } else {
                General.println("grandExchangeSellHashMap: "+!grandExchangeSellHashMap.isEmpty());

                if(!grandExchangeSellHashMap.isEmpty()) {
                   for(Map.Entry<String, GrandExchangeItem> sellItemsMap : grandExchangeSellHashMap.entrySet()) {
                       String itemName = sellItemsMap.getKey();
                       int price = sellItemsMap.getValue().getPrice();
                       while (InventoryEvent.contains(itemName)) {
                           RSItem item = Methods.getInventoryItem(itemName);
                           if (GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.SELECTION_WINDOW)) {
                               if (item.click("Offer")) {
                                   Timing.waitCondition(() -> GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.NEW_OFFER_WINDOW), 5000);
                               }
                           } else if (GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.NEW_OFFER_WINDOW)) {
                               if (!isItemPriceCorrect(price)) {
                                   setItemPrice(price);
                               } else {
                                   clickContinue();
                                   Timing.waitCondition(() -> (Arrays.stream(GrandExchange.getOffers()).anyMatch(i -> i.getStatus() == RSGEOffer.STATUS.COMPLETED) && GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.SELECTION_WINDOW)), 10000);
                               }
                           }
                       }
                   }
                }
                for (Map.Entry<String, GrandExchangeItem> grandExchangeItems : grandExchangeItemHashMap.entrySet()) {
                    String itemName = grandExchangeItems.getKey();
                    General.println("Trying to buy: " + itemName);
                    int qty;
                    if (bankEventV2.bankCacheHashMap.get(itemName) != null) {
                        qty = grandExchangeItems.getValue().getQty() - bankEventV2.bankCacheHashMap.get(itemName).getQty();
                        if (qty <= 0) {
                            continue;
                        }
                    } else {
                        qty = grandExchangeItems.getValue().getQty();
                    }
                    if(canOpenExchange()) {
                        break;
                    }
                    int price = grandExchangeItems.getValue().getPrice();
                    RSGEOffer[] rsgeOffer2 = GrandExchange.getOffers();
                    if (Arrays.stream(rsgeOffer2).anyMatch(i -> i.getStatus() == RSGEOffer.STATUS.COMPLETED) && GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.SELECTION_WINDOW)) {
                        General.println("Collecting items");
                        collectItemsInventory();
                        General.sleep(1000);
                        updateCache();
                    } else {

                        if (GrandExchange.getWindowState() != null) {
                            if (GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.SELECTION_WINDOW)) {
                                if (alreadyHaveOffer(itemName)) {
                                    continue;
                                } else if (!alreadyHaveOffer(itemName)) {
                                    openFirstEmptyBox();
                                }
                            } else if (GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.NEW_OFFER_WINDOW)) {
                                while (!alreadyHaveOffer(itemName)) {
                                    if (needToChooseItem()) {
                                        if (isItemThere(itemName)) {
                                            clickItemChild();
                                            Timing.waitCondition(() -> !needToChooseItem(), 3000);
                                        } else if (!isItemThere(itemName)) {
                                            RSInterface buyTextBar = Interfaces.get(162, 42);
                                            Timing.waitCondition(() -> Interfaces.isInterfaceSubstantiated(buyTextBar), 3000);
                                            new TypingEvent(script, itemName, false).execute();
                                            Timing.waitCondition(() -> isItemThere(itemName), 4000);
                                        }
                                    } else if (isItemCorrect(itemName)) {
                                        if (!isItemPriceCorrect(price)) {
                                            setItemPrice(price);
                                        } else if (!isItemQtyCorrect(qty)) {
                                            setItemQty(qty);
                                        } else {
                                            clickContinue();
                                            Timing.waitCondition(() -> GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.SELECTION_WINDOW), 3000);
                                        }
                                    }
                                }
                            }
                            General.sleep(1000);
                        }
                    }
                }
            }
        }
    }

    public void collectItemsInventory() {
        RSInterface collectInterface = Interfaces.get(465, 6, 0);
        if (Interfaces.isInterfaceSubstantiated(collectInterface)) {
            if (collectInterface.click("Collect to inventory")) {
                General.sleep(1000);
            }
        }
    }

    public void updateItem(String itemName, int id, int amount) {
        int oldCache;
        if (bankEvent.bankCacheHashMap.containsKey(itemName)) {
            oldCache = bankEvent.bankCacheHashMap.get(itemName).getQty();
            bankEvent.bankCacheHashMap.replace(itemName, new BankCache(itemName, id, amount + oldCache));
        } else {
            bankEvent.bankCacheHashMap.put(itemName, new BankCache(itemName, id, amount));
        }
    }

    public void updateCache() {
        RSItem[] inventoryItems = Inventory.getAll();
        Arrays.stream(inventoryItems)
                .map(RSItem::getDefinition)
                .filter(Objects::nonNull)
                .forEach(rsItemDefinition -> {
                    final String name = rsItemDefinition.getName();
                    final int id = rsItemDefinition.getUnnotedItemID();

                    final int qty;

                    // find the qty by matching the current RSItem to the RSItem[] inventoryItems by ID
                    qty = Arrays.stream(inventoryItems)
                            .filter(rsItem -> rsItem.getDefinition().getUnnotedItemID() == rsItemDefinition.getID()) // find the current RSItem in stream using ID
                            .mapToInt(RSItem::getStack) // map the stack
                            .findFirst() // find it
                            .orElse(0); // return the stack or zero if not found

                    General.println("Updating cache: " + name + " ID: " + id + " qty: " + qty);

                    updateItem(name, id, qty);
                });
    }

    public void clickContinue() {
        RSInterface continueButton = Interfaces.get(465, 27, 0);
        if (Interfaces.isInterfaceSubstantiated(continueButton)) {
            continueButton.click();
            Timing.waitCondition(() -> GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.SELECTION_WINDOW), 3000);
        }
    }

    public boolean needToChooseItem() {
        RSInterface rsInterface = Interfaces.get(465, 24, 25);
        if (Interfaces.isInterfaceSubstantiated(rsInterface)) {
            return rsInterface.getText().equals("Choose an item...");
        }
        return false;
    }

    public boolean isItemCorrect(String itemName) {
        RSInterface itemNameInterface = Interfaces.get(465, 24, 25);
        if (Interfaces.isInterfaceSubstantiated(itemNameInterface)) {
            return itemNameInterface.getText().equals(itemName);
        }
        return false;
    }

    public boolean isItemPriceCorrect(int price) {
        RSInterface itemPriceText = Interfaces.get(465, 24, 39);
        if (Interfaces.isInterfaceSubstantiated(itemPriceText)) {
            String itemPrice = itemPriceText.getText().replace(" coins", "").replace(",", "");
            return Integer.parseInt(itemPrice) == price;
        }
        return false;
    }

    public void setItemPrice(int price) throws IOException, InterruptedException {
        RSInterface enterPriceButton = Interfaces.get(465, 24, 12);
        RSInterface enterPrice = Interfaces.get(162, 41);
        if (Interfaces.isInterfaceSubstantiated(enterPrice)) {
            String itemPrice = Integer.toString(price);
            new TypingEvent(script, itemPrice, true).execute();
            Timing.waitCondition(() -> isItemPriceCorrect(price), 4000);
        } else if (Interfaces.isInterfaceSubstantiated(enterPriceButton)) {
            if (enterPriceButton.click()) {
                Timing.waitCondition(() -> Interfaces.isInterfaceSubstantiated(enterPrice), 2000);
            }
        }
    }

    public boolean isItemQtyCorrect(int qty) {
        RSInterface itemQtyText = Interfaces.get(465, 24, 32);
        if (Interfaces.isInterfaceSubstantiated(itemQtyText)) {
            return Integer.parseInt(itemQtyText.getText().replace(",", "")) == qty;
        }
        return false;
    }

    public void setItemQty(int qty) throws IOException, InterruptedException {
        RSInterface itemQtyButton = Interfaces.get(465, 24, 7);
        RSInterface enterQty = Interfaces.get(162, 41);
        if (Interfaces.isInterfaceSubstantiated(enterQty)) {
            String itemQty = Integer.toString(qty).replace(",", "");
            new TypingEvent(script, itemQty, true).execute();
        } else if (Interfaces.isInterfaceSubstantiated(itemQtyButton)) {
            if (itemQtyButton.click()) {
                Timing.waitCondition(() -> Interfaces.isInterfaceSubstantiated(enterQty), 3000);
            }
        }
    }

    public void clickItemChild() {
        RSInterface itemList = ExchangeBoxes.itemList;
        if (Interfaces.isInterfaceSubstantiated(itemList)) {
            RSInterface itemChild = itemList.getChild(getItemChild());
            if (Interfaces.isInterfaceSubstantiated(itemChild)) {
                itemChild.click();
            } else {
                General.println("We need to scroll i guess");
                General.sleep(1000);
            }
        }
    }

    public boolean isItemThere(String itemName) {
        RSInterface itemList = ExchangeBoxes.itemList;
        if (Interfaces.isInterfaceSubstantiated(itemList)) {
            for (int i = 0; i < 26; i++) {
                if (Interfaces.isInterfaceSubstantiated(itemList.getChild(i))) {
                    String itemBoxName = itemList.getChild(i).getComponentName().replace("<col=ff9040>", "").replace("</col>", "");
                    if (itemBoxName.equals(itemName)) {
                        setItemChild(i);
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public int getItemChild() {
        return itemChild;
    }

    public void setItemChild(int i) {
        itemChild = i;
    }

    public void openFirstEmptyBox() {
        General.println("Trying to open first empty box");
        RSInterface emptyBox = getFirstEmptyBox();
        if (emptyBox.getChild(ExchangeBoxes.buyChild).click()) {
            Timing.waitCondition(() -> GrandExchange.getWindowState().equals(GrandExchange.WINDOW_STATE.NEW_OFFER_WINDOW), 5000);
        }
    }

    public boolean alreadyHaveOffer(String itemName) {
        RSInterface[] allBoxes = new RSInterface[]{Interfaces.get(465, 7), Interfaces.get(465, 8), Interfaces.get(465, 9), Interfaces.get(465, 10), Interfaces.get(465, 11), Interfaces.get(465, 12), Interfaces.get(465, 13), Interfaces.get(465, 14)};
        return Arrays.stream(allBoxes).anyMatch(i -> i.getChild(19).getText().equals(itemName));
    }

    public boolean isBoxEmpty(RSInterface box) {
        return Interfaces.isInterfaceSubstantiated(box.getChild(ExchangeBoxes.buyChild));
    }

    public Optional<RSInterface> getEmptyBox() {
        RSInterface[] allBoxes = new RSInterface[]{Interfaces.get(465, 7), Interfaces.get(465, 8), Interfaces.get(465, 9), Interfaces.get(465, 10), Interfaces.get(465, 11), Interfaces.get(465, 12), Interfaces.get(465, 13), Interfaces.get(465, 14)};
        int buyChild = ExchangeBoxes.buyChild;
        return Arrays.stream(allBoxes).filter(Objects::nonNull).filter(i -> Interfaces.isInterfaceSubstantiated(i.getChild(buyChild))).findAny();
    }

    public RSInterface getFirstEmptyBox() {
        RSInterface[] allBoxes = new RSInterface[]{Interfaces.get(465, 7), Interfaces.get(465, 8), Interfaces.get(465, 9), Interfaces.get(465, 10), Interfaces.get(465, 11), Interfaces.get(465, 12), Interfaces.get(465, 13), Interfaces.get(465, 14)};
        int buyChild = ExchangeBoxes.buyChild;
        return Arrays.stream(allBoxes).filter(d -> Interfaces.isInterfaceSubstantiated(d.getChild(buyChild))).findFirst().get();
    }

    public boolean noEmptyBoxes() {
        RSInterface[] allBoxes = new RSInterface[]{Interfaces.get(465, 7), Interfaces.get(465, 8), Interfaces.get(465, 9), Interfaces.get(465, 10), Interfaces.get(465, 11), Interfaces.get(465, 12), Interfaces.get(465, 13), Interfaces.get(465, 14)};
        int buyChild = ExchangeBoxes.buyChild;
        return Arrays.stream(allBoxes).noneMatch(i -> Interfaces.isInterfaceSubstantiated(i.getChild(buyChild)));
    }


    public boolean needCoins() {
        return bankEventV2.addReq("Coins", Integer.MAX_VALUE).isPendingOperation();
    }
    BankEventV2 bankEventV2;

    public void getCoins() throws IOException, InterruptedException {
        if(grandExchangeSellHashMap.isEmpty()) {
            General.println("SellHashMap is empty");
           bankEventV2 = new BankEventV2(script).addReq("Coins", Integer.MAX_VALUE);
           bankEventV2.execute();
           bankEventV2.reset();
        } else {
            for(Map.Entry<String, GrandExchangeItem> grandSellItems :grandExchangeSellHashMap.entrySet()) {
                String itemName = grandSellItems.getValue().getItemName();
                General.println("Adding: "+itemName+" to bankevent");
                bankEventV2.addReq(itemName, Integer.MAX_VALUE, () -> bankEventV2.bankCacheHashMap.containsKey(itemName) || InventoryEvent.contains(itemName));
            }
            if(bankEventV2.isPendingOperation()) {
                bankEventV2.execute();
                bankEventV2 = new BankEventV2(script);
                bankEventV2.reset();
            }
        }
    }

    public boolean canOpenExchange() {
        return GrandExchange.getWindowState() == null;
    }

    public void openGrandExchange() {
        RSObject booth = Methods.getObjectWithAction("Exchange", "Grand Exchange booth", 20);
        if (booth != null) {
            if (!booth.isOnScreen() || !booth.isClickable()) {
                booth.adjustCameraTo();
            } else if (AccurateMouse.click(booth, "Exchange")) {
                Timing.waitCondition(() -> GrandExchange.getWindowState() != null, 5000);
            }
        }
    }

    public void closeGrandExchange() {
        if (!canOpenExchange()) {
            GrandExchange.close();
            Timing.waitCondition(() -> canOpenExchange(), 4000);
        }
    }

    public RSPlayer me() {
        return Player.getRSPlayer();
    }
}

 

ExchangeBoxes: Exchange boxes interfaces id's

Spoiler

package scripts.core.grandexchange;

import org.tribot.api2007.Interfaces;
import org.tribot.api2007.types.RSInterface;

public class ExchangeBoxes {

    public static RSInterface Box1 = Interfaces.get(465, 7);
    public static   RSInterface Box2 = Interfaces.get(465, 8);
    public static RSInterface Box3 = Interfaces.get(465, 9);
    public static RSInterface Box4 = Interfaces.get(465, 10);
    public static RSInterface Box5 = Interfaces.get(465, 11);
    public static RSInterface Box6 = Interfaces.get(465, 12);
    public static RSInterface Box7 = Interfaces.get(465, 13);
    public static RSInterface Box8 = Interfaces.get(465, 14);

    public static int buyChild = 3;
    public int sellChild = 4;

    //Actions Sell: Create <col=ff9040>Sell</col> offer
    //Actions Buy: Create <col=ff9040>Buy</col> offer

    public int itemTextChild = 19;

    public int offerTypeChild = 16;

     static RSInterface[] allBoxes = new RSInterface[]{Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8};

    public static RSInterface searchBar = Interfaces.get(162, 42);

    // <col=000000> What would you like to buy?</col> blah*

    public static RSInterface itemList = Interfaces.get(162, 50);

    //<col=ff9040>Item Name</col>




}

 

GrandExchangeItem: Grand Exchange Item handler

Spoiler

package scripts.core.grandexchange;

public class GrandExchangeItem {

    public final String itemName;
    public int qty;
    public  int id;
    public final int price;

    public GrandExchangeItem(String itemName, int id, int qty, int price) {
        this.itemName = itemName;
        this.id = id;
        this.qty = qty;
        this.price = price;
    }

    public GrandExchangeItem(String itemName, int qty, int price) {
        this.itemName = itemName;
        this.qty = qty;
        this.price = price;
    }

    public GrandExchangeItem(String itemName, int price) {
        this.itemName = itemName;
        this.price = price;
    }

    public String getItemName() {
        return itemName;
    }

    public int getQty() {
        return qty;
    }

    public int getId() {
        return id;
    }

    public int getPrice() {
        return price;
    }
}

 


TypingEvent: simple typing event so you can interrupt typing based on conditions

Spoiler

 


package scripts.core.grandexchange;

import org.tribot.api.General;
import org.tribot.api.input.Keyboard;
import org.tribot.script.Script;
import scripts.core.botevent.BotEvent;

import java.io.IOException;

public class TypingEvent extends BotEvent {

    String string;
    boolean enter;

    public TypingEvent(Script script, String string, boolean enter) {
        super(script);
        this.string = string;
        this.enter = enter;
    }

    /*  else if(Interfaces.isInterfaceSubstantiated(itemList)) {
                for (int i = 0; i> 9;i++) {
                    if(itemList.getChild(i).getComponentName().contains(itemName)) {
                        setComplete();
                    }
                }*/

    @Override
    public void step() throws InterruptedException, IOException {
        if (enter) {
            Keyboard.typeSend(string);
        } else {
            Keyboard.typeString(string);
        }
        General.sleep(1000);
        setComplete();
    }
}

 

Rest of api is in the link below:
https://github.com/Whipz/OpenSource/tree/main/showofscript

 

If you have questions or have feedback on how to improve let me know, however some of the newer stuff hasnt been added yet and might be in a later date or they are strictly for my premium stuff if I ever end up as one.

 

Edit: Updated fixed some bugs, added selling to ge

Edited by whipz_man
Update to handle BankCache, GEEvent etc
  • Like 2
  • Thanks 1
Link to post
Share on other sites
  • whipz_man changed the title to Whipz Famous Events (BankEvent, LoadoutEvent, BankCache, GEEvent (Buy only) and more)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Our picks

    • Support for the gradle launcher is being dropped. Read more about the new launcher here.
        • Like
      • 8 replies
    • What to expect from TRiBot moving forward.
        • Thanks
        • Like
      • 11 replies
    • TRiBot 12 Release Candidate

      The TRiBot team has been hard at work creating the last major version of TRiBot before the TRiBot X release. We've noticed many problems with TRiBot 11 with a lot of users preferring TRiBot 10 over 11. We've heard you, so we took TRiBot 10, added the new features introduced with 11, introduced some other new things, and created TRiBot 12. So without further adieu, here's TRiBot 12.
        • Sad
        • Like
      • 40 replies
    • Gradle is a build tool used to accelerate developer productivity.

      We recently setup a Maven repository (TRiBot Central) to make it easier for scripters to create scripts. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-central/-/packages

      Furthermore, we've released a simple Gradle project to make it easy to run TRiBot and develop scripts for it. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-gradle-launcher

      The goals of TRiBot Central are to:

      Deliver updates to TRiBot faster


      Better organize TRiBot's dependencies (AKA dependancies)


      Make it easier to develop scripts for TRiBot


      Make it easier to use and run TRiBot


      Note: TRiBot won't be able to run scripts from within this project until TRiBot's next release.
        • Like
      • 13 replies
    • Hi everyone,

      I'd like to thank everyone for their patience in this transition period. Since last week, we've worked out the remaining bugs with this integration.

      Some users have still been having issues with connecting their forums account to their Auth0 account. To resolve this, we've imported all forums accounts into Auth0.

      Unfortunately, the accounts which were imported today were using an unsupported password hashing algorithm. Hence, random passwords were set during the import.

      What does this mean for me?

      If you've previously linked your forums account to your Auth0 account, you don't have to do anything. Nothing changes for you.


      If you haven't logged in via our new login yet,

      Try logging in with your forums email address and the last password you used


      If you are unable to login, please use the "Forgot password" tool on the login page:
      Follow the instructions to reset your password
       
        • thonking
        • Like
      • 17 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...