Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sell OSRS Gold
boe123

[SNIPPET] Duel Arena API

Recommended Posts

Posted (edited)

Recently I started working on scripts that involve the usage of the duel arena. After writing an API for it I've decided to release it to anyone who could use it.

The API supports:

  • Challenging a player
  • Setting Last Duel / Preset
  • Wagering amount in coins or platinum tokens
  • Starting the duel
  • Forfeiting
  • Getting Duel Results (Winner, Loser)

I've posted the snippet on my GitHub if you want to download/clone it for yourself :)

THIS API IS DEPENDENT ON Dax's Walker API

Here is an example of it's usage:

if (Duel.isInDuel()) {
  Duel.forfeit();
} else if (Duel.getDuelResult().isOpen()) {
  DuelResult result = Duel.getDuelResult();
  String winner = result.getWinner();
  boolean didWeWin = result.hasPlayerWon();
  result.close();
} else {
  if (Duel.isDuelScreenOpen()) {
    if (Duel.getDuelOptions().isOpen()) {
      DuelOptions options = Duel.getDuelOptions();
      if (options != null) {
        if (options.isPresetLoaded(DuelPreset.SAVED)) {
          if (!options.hasPlayerAccepted()) {
            options.accept();
          }
        } else {
          options.loadPreset(DuelPreset.SAVED);
        }
      }
    } else if (Duel.getDuelStake().isOpen()) {
      DuelStake stake = Duel.getDuelStake();
      if (stake != null) {
        if (stake.getTotalOffer() == 0) {
          stake.offer(DuelCurrency.PLATINUM_TOKENS, "10m");
        } else {
          if (!stake.hasPlayerAccepted()) {
            stake.accept();
          }
        }
      }
    } else if (Duel.getDuelConfirmation().isOpen()) {
      DuelConfirmation confirmation = Duel.getDuelConfirmation();
      if (confirmation != null) {
        if (!confirmation.hasPlayerAccepted()) {
          confirmation.accept();
        }
      }
    }
  } else {
    Duel.challenge("boe123");
  }

If anyone has questions on my api or how it works, don't hesitate to ask questions.

Edited by boe123
dependencies

Share this post


Link to post
Share on other sites
package scripts.assume_staker.staker_api.types.screens;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.tribot.api.General;
import org.tribot.api2007.Game;
import org.tribot.api2007.Interfaces;
import org.tribot.api2007.types.RSInterface;
import org.tribot.api2007.types.RSVarBit;

import scripts.assume_staker.main.Settings;
import scripts.assume_staker.staker_api.methods.DefaultMethods;

public enum InterfaceIconsFirstScreen {

	NO_FORFEIT(482, 50, 0, -1), NO_MOVEMENT(482, 51, 1, -1), NO_WEAPON_SWITCH(482, 52, 2, -1), SHOW_INVENTORIES(482, 53,
			3, -1), NO_RANGED(482, 54, 4, -1), NO_MELEE(482, 55, 5, -1), NO_MAGIC(482, 56, 6, -1), NO_DRINKS(482, 57, 7,
					-1), NO_FOOD(482, 58, 8, -1), NO_PRAYER(482, 59, 9, -1), OBSTACLES(482, 60, 10,
							-1), FUN_WEAPONS(482, 61, 12, -1), NO_SPECIAL_ATTACK(482, 62, 13, -1), HELMET(482, 80, 14,
									643), CAPE(482, 81, 15, 644), NECKLACE(482, 82, 16, 645), WEAPON(482, 83, 17,
											646), BODY(482, 84, 18, 647), SHIELD(482, 85, 19, 648), LEGS(482, 86, 21,
													650), GLOVES(482, 87, 23, 652), BOOTS(482, 88, 24,
															653), RING(482, 89, 26, 655), AMMO(482, 90, 27, 656);

	private static final int SETTING_INDEX = 286;

	private int parent;
	private int child;
	private int bytemod;
	private int varbit;

	InterfaceIconsFirstScreen(int parent, int child, int bytemod, int varbit) {
		this.parent = parent;
		this.child = child;
		this.bytemod = bytemod;
		this.varbit = varbit;
	}

	public int getParent() {
		return parent;
	}

	public int getChild() {
		return child;
	}

	public int getByteMod() {
		return bytemod;
	}

	public int getVarbit() {
		return varbit;
	}

	public boolean isSelected() {
		return getVarbit() == -1 ? ((Game.getSetting(SETTING_INDEX) >> getByteMod()) & 0x1) == 1
				: RSVarBit.get(getVarbit()).getValue() == 1;
	}

	public static InterfaceIconsFirstScreen[] getAllWhipping() {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		for (InterfaceIconsFirstScreen f : values())
			if (!f.equals(NO_MELEE) && !f.equals(OBSTACLES) && !f.equals(FUN_WEAPONS) && !f.equals(WEAPON)
					&& !f.equals(NO_WEAPON_SWITCH))
				list.add(f);
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static InterfaceIconsFirstScreen[] getAllDDSing() {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		for (InterfaceIconsFirstScreen f : values())
			if (!f.equals(NO_MELEE) && !f.equals(OBSTACLES) && !f.equals(FUN_WEAPONS) && !f.equals(WEAPON)
					&& !f.equals(NO_SPECIAL_ATTACK) && !f.equals(NO_WEAPON_SWITCH))
				list.add(f);
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static InterfaceIconsFirstScreen[] getAllBoxing() {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		for (InterfaceIconsFirstScreen f : values())
			if (!f.equals(NO_MELEE) && !f.equals(OBSTACLES) && !f.equals(FUN_WEAPONS) && !f.equals(NO_WEAPON_SWITCH))
				list.add(f);
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static InterfaceIconsFirstScreen[] getRequiredInterfacesForFix(InterfaceIconsFirstScreen[] mode) {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		List<InterfaceIconsFirstScreen> mode_list = Arrays.asList(mode);
		for (InterfaceIconsFirstScreen x : values()) {
			boolean is_selected = x.isSelected();
			if (is_selected && !mode_list.contains(x))
				list.add(x);
			if (!is_selected && mode_list.contains(x))
				list.add(x);
		}
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static void clickAll(InterfaceIconsFirstScreen[] all_for_fix, InterfaceIconsFirstScreen[] mode_full,
			boolean isFix) {
		List<InterfaceIconsFirstScreen> x = Arrays.asList(mode_full);
		for (InterfaceIconsFirstScreen r : all_for_fix) {
			if (!DefaultMethods.isFirstInterfaceUp())
				return;
			if (Settings.default_duel_method.valueIsCorrect())
				return;
			RSInterface y = Interfaces.get(r.getParent(), r.getChild());
			if (x.contains(r) && r.isSelected())
				continue;
			if (y != null) {
				if (!isFix) {
					if (General.random(1, 25) <= 1)
						continue;
				}
				if (Settings.default_duel_method.valueIsCorrect())
					return;
				y.click("");
				General.sleep(150, 300);
			}
		}
	}

}

Here's how to determine what settings are set or need to be set to match a certain duel type. Hasn't been updated in years so it's possible the values are off but I doubt the method has changed.

Share this post


Link to post
Share on other sites
1 minute ago, Assume said:
package scripts.assume_staker.staker_api.types.screens;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.tribot.api.General;
import org.tribot.api2007.Game;
import org.tribot.api2007.Interfaces;
import org.tribot.api2007.types.RSInterface;
import org.tribot.api2007.types.RSVarBit;

import scripts.assume_staker.main.Settings;
import scripts.assume_staker.staker_api.methods.DefaultMethods;

public enum InterfaceIconsFirstScreen {

	NO_FORFEIT(482, 50, 0, -1), NO_MOVEMENT(482, 51, 1, -1), NO_WEAPON_SWITCH(482, 52, 2, -1), SHOW_INVENTORIES(482, 53,
			3, -1), NO_RANGED(482, 54, 4, -1), NO_MELEE(482, 55, 5, -1), NO_MAGIC(482, 56, 6, -1), NO_DRINKS(482, 57, 7,
					-1), NO_FOOD(482, 58, 8, -1), NO_PRAYER(482, 59, 9, -1), OBSTACLES(482, 60, 10,
							-1), FUN_WEAPONS(482, 61, 12, -1), NO_SPECIAL_ATTACK(482, 62, 13, -1), HELMET(482, 80, 14,
									643), CAPE(482, 81, 15, 644), NECKLACE(482, 82, 16, 645), WEAPON(482, 83, 17,
											646), BODY(482, 84, 18, 647), SHIELD(482, 85, 19, 648), LEGS(482, 86, 21,
													650), GLOVES(482, 87, 23, 652), BOOTS(482, 88, 24,
															653), RING(482, 89, 26, 655), AMMO(482, 90, 27, 656);

	private static final int SETTING_INDEX = 286;

	private int parent;
	private int child;
	private int bytemod;
	private int varbit;

	InterfaceIconsFirstScreen(int parent, int child, int bytemod, int varbit) {
		this.parent = parent;
		this.child = child;
		this.bytemod = bytemod;
		this.varbit = varbit;
	}

	public int getParent() {
		return parent;
	}

	public int getChild() {
		return child;
	}

	public int getByteMod() {
		return bytemod;
	}

	public int getVarbit() {
		return varbit;
	}

	public boolean isSelected() {
		return getVarbit() == -1 ? ((Game.getSetting(SETTING_INDEX) >> getByteMod()) & 0x1) == 1
				: RSVarBit.get(getVarbit()).getValue() == 1;
	}

	public static InterfaceIconsFirstScreen[] getAllWhipping() {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		for (InterfaceIconsFirstScreen f : values())
			if (!f.equals(NO_MELEE) && !f.equals(OBSTACLES) && !f.equals(FUN_WEAPONS) && !f.equals(WEAPON)
					&& !f.equals(NO_WEAPON_SWITCH))
				list.add(f);
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static InterfaceIconsFirstScreen[] getAllDDSing() {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		for (InterfaceIconsFirstScreen f : values())
			if (!f.equals(NO_MELEE) && !f.equals(OBSTACLES) && !f.equals(FUN_WEAPONS) && !f.equals(WEAPON)
					&& !f.equals(NO_SPECIAL_ATTACK) && !f.equals(NO_WEAPON_SWITCH))
				list.add(f);
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static InterfaceIconsFirstScreen[] getAllBoxing() {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		for (InterfaceIconsFirstScreen f : values())
			if (!f.equals(NO_MELEE) && !f.equals(OBSTACLES) && !f.equals(FUN_WEAPONS) && !f.equals(NO_WEAPON_SWITCH))
				list.add(f);
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static InterfaceIconsFirstScreen[] getRequiredInterfacesForFix(InterfaceIconsFirstScreen[] mode) {
		List<InterfaceIconsFirstScreen> list = new ArrayList<InterfaceIconsFirstScreen>();
		List<InterfaceIconsFirstScreen> mode_list = Arrays.asList(mode);
		for (InterfaceIconsFirstScreen x : values()) {
			boolean is_selected = x.isSelected();
			if (is_selected && !mode_list.contains(x))
				list.add(x);
			if (!is_selected && mode_list.contains(x))
				list.add(x);
		}
		return list.toArray(new InterfaceIconsFirstScreen[list.size()]);
	}

	public static void clickAll(InterfaceIconsFirstScreen[] all_for_fix, InterfaceIconsFirstScreen[] mode_full,
			boolean isFix) {
		List<InterfaceIconsFirstScreen> x = Arrays.asList(mode_full);
		for (InterfaceIconsFirstScreen r : all_for_fix) {
			if (!DefaultMethods.isFirstInterfaceUp())
				return;
			if (Settings.default_duel_method.valueIsCorrect())
				return;
			RSInterface y = Interfaces.get(r.getParent(), r.getChild());
			if (x.contains(r) && r.isSelected())
				continue;
			if (y != null) {
				if (!isFix) {
					if (General.random(1, 25) <= 1)
						continue;
				}
				if (Settings.default_duel_method.valueIsCorrect())
					return;
				y.click("");
				General.sleep(150, 300);
			}
		}
	}

}

Here's how to determine what settings are set or need to be set to match a certain duel type. Hasn't been updated in years so it's possible the values are off but I doubt the method has changed.

Thanks for the addition Assume :D

Share this post


Link to post
Share on other sites

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

    • Over the past few months, I’ve been working diligently on a new project - TRiBot X. Everything has been written from the ground up, with all of the best practices of software engineering. Every aspect of TRiBot has been re-imagined to support three main goals: flexibility, useability, and reliability.
        • Like
      • 39 replies
    • Come give us feedback on the next version of TRiBot!
        • Thanks
        • Like
      • 75 replies
    • TRiBot is looking to improve a lot of its customer relationship management, customer on boarding process, customer experience, design elements, community engagement and pretty much everything else you can imagine when it comes to marketing.

      Our goal: To ensure that the marketing done TRULY reflects the experience and does not shine an inaccurate light on what TRiBot is lacking in.

      So I ask, what do you love about TRiBot and what do you hate about TRiBot? What does O S Bot, Rune M8, PowR Bot and Dre amBot do better? (yes I purposely didn't spell it right 😂).

      Love, 

      RileyZ
        • Like
      • 23 replies
    • Over the last three weeks, I've been working on upgrading our server infrastructure. It's finally ready and is now live!

      Why?

      Increased reliability - less server errors


      Increased availability - less downtime


      Increased security - keeping us and you secure


      Increased capacity - ability to serve you better


      Increased speed - less waiting for things to load


      Faster development - server and service updates will come faster


      What are the changes?

      Move from a single AWS EC2 instance to AWS ECS (Elastic Container Service)


      Distributed computing


      Load balancing


      Git management of server files and filesystem


      Redis caching


      How?

      AWS ECS (with 10 EC2 instances)


      AWS ElastiCache (Redis)


      AWS Load Balancing


      AWS EFS (Elastic file system)


      Please bare with us as I continue to tune the server for maximum performance. Slow loading speeds may occur temporarily. I thank everyone for their patience.

      Please post on this thread if you experience any issues other than slow loading times.
        • Like
      • 51 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Sad
        • Haha
        • Thanks
        • Like
      • 90 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...