Skip to content

PlayerSettings

Overview

The PlayerSettings class is a DreamBot helper class that enables you to extract various information from the game client. The game uses this data to store current game state on the client. The information obtained from these Varps/Varbits may differ greatly from account-to-account depending on the current game state. Information such as current quest stages, cannon ammo count, and account type to name a few. PlayerSettings are primarily broken up into two types of data, VarPlayers (also known as "Varps", "Configs", or "Settings") and Varbits. In this guide we'll break down what VarPlayers and Varbits are, how to find them, and go over some examples on where you might use them in your scripts.

Info

VarPlayers and Varbits are set by the server and cannot be modified. That is to say, VarPlayers and Varbits are read-only.

DreamBot's API documentation on PlayerSettings can be found here.

Obtaining PlayerSettings

Many of the commonly used Varps and Varbits can be found online in open-source scripts, tutorials, and even the OSRS wiki.

Danger

While VarPlayers and Varbits may have similar names, they can (and will) map to entirely different values. For example, VarPlayer ID 43 may return one value, and Varbit ID 43 may return a different value. You should be mindful of this and ensure you do not confuse a Varp for a Varbit and vice-versa.

To manually find a Varp/Varbit ID and its value, open the DreamBot client, go to "Tools", and click "Game Explorer". Or, simply press "CTRL + G" with the DreamBot client open.

image

Then, navigate to the "Player Settings" tab in the Game Explorer

image

The left pane is separated by two tabs, with "Settings" for Varps and "Varbits" for Varbits. You can easily view the current state of all Varps/Varbits in this pane. The number on the left is the Varp/Varbit ID and the number after the colon is the current value of that Varp/Varbit.

In the example below, we can see that the current value of the Varp associated with the player's current attack style (ID 43) is 3

image

On the right pane you will find recent Varp/Varbit updates. Any time a Varp or Varbit is updated in the game, the following information will be displayed in the right pane:

  • The time of change
  • The type of PlayerSetting that was changed
    • "Config" for Varps
    • "Varbit" for Varbits
  • The Varp/Varbit ID
  • The previous value (before the change)
  • The current value (after the change)

In the example below, we can see the state of the Varp associated with the player's current attack style (ID 43) change.

image

You may also notice that Varp ID 46 changes with almost every attack style change. This demonstrates how even the smallest change in game state may affect multiple PlayerSettings and the sometimes "odd" behavior of PlayerSettings.

For further resources on obtaining commonly used Varps and Varbits, please see the following:

VarPlayers (Varps)

VarPlayers (hereby referred to as "Varps") are 32-bit integers that are set by the server and are account-specific. You can think of a Varp as a sort of "mapping" that allows you to quickly view the current game state. Each Varp can only be associated with one integer value at any given time, though these values may change rapidly.

In the example below we will demonstrate how to read the VarPlayers associated with the player's current attack style.

Example: Obtaining player attack style

Referencing some of the resources above, we find that the VarPlayer ID associated with the player's attack style is 43. You can also find this yourself by opening the Player Settings tab in the Game Explorer, changing your attack style, and observing the results in the "Recent Updates" pane.

In the DreamBot API we see that the PlayerSettings.getConfig(int id) method can be used to obtain a specific config value. We will combine what we know about the attack style Varp and this method to obtain the player's attack style when the player is holding a Bronze Sword.

Info

Remember that VarPlayer, Varp, Setting, and Config are all names for the same thing.

int currentAttackStyle = PlayerSettings.getConfig(43); // currentAttackStyle = 0

The value of currentAttackStyle returned 0 as our attack style is currently set to "Stab". We will write down for our own notes that the value for "Stab" is 0.

Then, we change our attack style to "Lunge" and run the same code as above.

int currentAttackStyle = PlayerSettings.getConfig(43); // currentAttackStyle =  1

The value of currentAttackStyle returned 1 as our attack style is currently set to "Lunge". We will write down for our own notes that the value for "Lunge" is 1.

We then continue this process to map out the various attack styles and the values returned from the attack style Varp. At the end of this exercise we've mapped out all of the different attack styles and their values, like so:

  • Stab -> 0
  • Lunge -> 1
  • Slash -> 2
  • Block -> 3

With this information, we can easily determine the player's current attack style without having to open the "Combat Options" tab in-game. For example, if we wanted to ensure that the player's attack style is set to "Slash", we can run the code provided above and verify the value returned is 2.

Warning

The attack styles and values returned from this Varp may change depending on which weapon (or lack thereof) is currently equipped by the player. The example above uses a Bronze Sword for demonstration.

Varbits

Varbits have a variable size, are also set by the server, and are also account-specific. They function similarly to Varps but as their name suggests, internally they work as bits. For our purposes as scripters using DreamBot's API, we shouldn't have to worry too much doing bit-shifting or bit-masking. It may still be good to be mindful of this fact though in the event that you run into odd or large values when obtaining values from Varbits.

In the example below we will demonstrate how to read the VarPlayers associated with the player's currently selected auto-cast spell.

Example: Obtaining player auto-cast spell

Referencing some of the resources above, we find that the Varbit ID associated with the player's currently selected auto-cast spell is 276. You can also find this yourself by opening the Player Settings tab in the Game Explorer, clicking "Varbit" in the left pane, changing your auto-cast spell, and observing the results in the "Recent Updates" pane.

In the DreamBot API we see that the PlayerSettings.getBitValue(int id) method can be used to obtain a specific bit value. We will combine what we know about the auto-cast spell Varbit and this method to obtain the player's auto-cast spell.

First, we'll start off with having no spell selected for auto-casting and run the code below.

int currentAutoCastSpell = PlayerSettings.getBitValue(276); // currentAutoCastSpell = 0

The value of currentAutoCastSpell returned 0 as we have no spell set for auto-casting. We will write down for our own notes that the value for "No Spell" is 0.

Then, we change our auto-cast spell to "Wind Strike" and run the same code as above.

int currentAutoCastSpell = PlayerSettings.getBitValue(276); // currentAutoCastSpell = 1

The value of currentAutoCastSpell returned 1. We can surmise that this value is associated with the "first" auto-castable spell, "Wind Strike". We will write down for our own notes that the value for "Wind Strike" is 1.

We then continue this process to map out the various spells and the values returned from the auto-cast spell Varbit. At the end of this exercise we've mapped out all of the different basic spells and their values, like so:

  • No Spell -> 0
  • Wind Strike -> 1
  • Water Strike -> 2
  • Earth Strike -> 3
  • Fire Strike -> 4

With this information, we can easily determine the player's current auto-casted spell without having to open the "Combat Options" tab in-game. For example, if we wanted to ensure that the player's auto-cast spell is set to "Earth Strike", we can run the code provided above and verify the value returned is 3.

Warning

The auto-casted spells and values returned from this Varbit may change depending on which spellbook is currently equipped by the player. The example above uses an Air Staff on the Normal Spellbook for demonstration.

Going Further

Above are two simple examples for obtaining the current state of our attack style (using Varps) and our selected auto-cast spell (using Varbits). Below we will demonstrate some more examples that may be more relevant to scripts you might find yourself writing.

Example: Refilling cannon ammo when low

The example below shows one approach a scripter might take to determine if their Dwarf Multi-Cannon is low on ammo, and how they might refill it.

// Create a constant for the Cannon Ammo Count Varp
// The ID for this Varp is 3
// This ID was obtained by having our cannon fire and observing the results in the "Recent Updates" pane
final int AMMO_COUNT_VARP_ID = 3;

@Override
public int onLoop() {
    // Obtain the current ammo count using the Varp ID from above
    // The value returned here is a number from 0-30 depending on how many cannonballs are in the cannon
    int currentAmmoCount = PlayerSettings.getConfig(AMMO_COUNT_VARP);

    // If our ammo count is 10 or less, we should refill the cannon
    if (currentAmmoCount <= 10) {
        // Grab the closest cannon
        // Note that this may break if there are multiple cannons in the area
        // A more robust script would keep track of the player's cannon once it has been placed
        GameObject cannonObject = GameObjects.closest("Dwarf multicannon");

        // Check that the cannon is not null, and interact with it to load it
        // Then return a random number between 1000 and 2500 to loop
        if (cannonObject != null && cannonObject.interact("Fire")) {
            return Calculations.random(1000, 2500);
        }
    }

    // Then return a random number between 500 and 1000 to loop
    return Calculations.random(500, 1000);
}

Determining quest state for X Marks The Spot

The example below shows one approach a scripter might take to determine their current progress in the X Marks The Spot quest.

// Create a constant for the X Marks The Spot quest state Varbit ID
// The ID for this Varp is 8063
// This ID was obtained from one of the quest Varbit resources provided above
final int X_MARKS_THE_SPOT_VARBIT_ID = 8063;

@Override
public int onLoop() {
    // Obtain the current quest state for the X Marks The Spot quest
    int xMarksTheSpotState = PlayerSettings.getBitValue(X_MARKS_THE_SPOT_VARBIT_ID);

    // We should choose what the player should do depending on the value we got above
    // In this case, the values 0-7 tell us which stage the quest is in and 8 lets us know the quest is complete
    switch (xMarksTheSpotState) {
        case 0:
        case 1:
            talkToVeos();
            break;
        case 2:
            digOutsideBobsAxes();
            break;
        case 3:
            digOutsideCastle();
            break;
        case 4:
            digNearDraynor();
            break;
        case 5:
            digByMartin();
            break;
        case 6:
            talkToVeosInPortSarim();
            break;
        case 7:
            finishQuest();
            break;
        case 8:
            questComplete();
            break;
        default:
            Logger.log("Unknown state! Do we have the right Varbit?");
    }

    return Calculations.random(500, 1000);
}

Info

Switch cases like the one shown above may not be the best approach for more complex scripts. Take the above snippet only as a quick example and consider using a framework such as a Tree for your own scripts.