Suggestion Discussion - How should randoms be handled

Discussion in 'Client & Site Suggestions' started by Salvation, Apr 30, 2014.

  1. Salvation

    Salvation First Bot Author

    Aug 7, 2013
    Likes Received:
    In this thread I will group random events into several categories based on their signature.

    Group A: Talk and Done: These require the user to click on the anti-random, perhaps click continue a few times and nothing more. Examples: Drunken Dwarf, Strange plant

    Group B: Talk and Puzzle: These require the user to click on the anti-random and solve a puzzle on the spot. Examples: Rick Turpentin, Sandwich Lady

    Group C: Teleport: These teleport the user into a safe area to complete a puzzle. Examples: Evil Twin, Beekeeper

    Group D: Fight or Run: These requires the user to either fight off, or run from. Examples: Evil Chicken, Shade, Zombie

    Now Imagine the client would handle all random events by default, and the script bot is paused while it's solving a random event. This means the script bot has no means to interfere. How would each group be handled?

    Starting with C: This seems the easiest group to handle, as when the player is teleported, the script bot has no desire to do anything anymore, nor is the player in danger: the random solver can start right away!

    But then A and B, which often require the player to be out of combat before talking. Now, if the random solver activates instantly and simply waits for the user to become idle: that might never happen and the player might die. You'd need the script bot to tell the client when it is safe to solve the random event!

    The same goes for D: How would the client decide whether to fight or to run? Imagine Ultra Bandits: which protects melee at all times as the player is under attack by a large amount of bandits. Fighting an evil chicken would be stupid, as it uses magic. However, fighting a melee-based random event wouldn't be an issue as it wouldn't hit anything. I would want the script bot to be able to tell the client which it's going to fight, and which it is not! If I am a level 3 player woodcutting some yew logs and get any combat-based event: I'd run! But this also poses a problem, as the client wouldn't know where to run to, especially if you're inside a closed-off compound: such as a house, or a cow pen! The script bot would at least require the option to walk manually!

    I've therefore come up with a clean way of dealing with randoms, which I will illustrate by implementing it.
    Code (Text):
    2. import;
    3. import;
    4. import;
    5. import;
    6. import;
    8. @Manifest(
    9.         categories = Category.OTHER,
    10.         compatibility = GameType.OSRS,
    11.         name = "Example Script",
    12.         version = "1.0.00",
    13.         description = "Example Description.")
    14. public final class ExampleScript extends LoopingScript implements RandomListener {
    16.     private RandomEvent randomEvent;
    18.     @Override
    19.     public void onLoop() {
    20.         if (randomEvent != null) {
    21.             //get to safety
    22.         }
    23.     }
    25.     @Override
    26.     public boolean safeToTalk(final RandomEvent event) {
    27.         randomEvent = event;
    28.         return Players.getLocal().getHealthGauge() == null;
    29.     }
    31.     @Override
    32.     public void onRandomEvent(final RandomEvent event) {
    33.         if (event.getGroup() == RandomEvent.Group.FIGHT_OR_RUN) {
    34.             if (event == RandomEvent.EVIL_CHICKEN) {
    35.                 event.setSolveMode(RandomEvent.Mode.RUN); //Let the client decide a location to run to and do everything itself
    36.                 //or
    37.                 event.setSolver(new EvilChickenRunner());
    38.             } else {
    39.                 event.setSolveMode(RandomEvent.Mode.FIGHT); //Let the client do the fighting
    40.                 //or
    41.                 event.setSolver(new RandomFighter());
    42.             }
    43.         }
    44.     }
    46.     @Override
    47.     public void onRandomEventComplete(final RandomEvent event) {
    48.         randomEvent = null;
    49.     }
    51.     private final class EvilChickenRunner implements Runnable {
    53.         @Override
    54.         public void run() {
    55.             //my own running method
    56.         }
    57.     }
    59.     private final class RandomFighter implements Runnable {
    61.         @Override
    62.         public void run() {
    63.             //my own way of fighting a random
    64.         }
    65.     }
    66. }
    It isn't perfect, but it illustrates the idea. What do you guys think about the handling of randoms?
  2. Cloud

    Jul 28, 2013
    Likes Received:
    I like it, I may implement something similar in the future.
  3. Arbiter

    Arbiter Mod Automation

    Jul 26, 2013
    Likes Received:
    Correct me if I'm wrong but I do believe you can only get randoms when you are out of combat, in which case the trying to talk while in combat argument is moot.

    On a more general note, I'm torn on this. I like the traditional structure in which random handling is abstracted out of the control of an individual bot/author as not everyone can develop code to the quality you can and any shortcomings would reflect on the client instead of the bot. That being said, I do see the use case (as you suggested being stuck in a pen when needing to run) to allow devs some level of control. I would, however, emphasize the need for the anti-random to have default behaviors with optional methods in the API to over-ride certain behaviors. For example, an attack or run anti-random would run by default, but allow the author to over-ride that and attack if he so wishes.
  4. Salvation

    Salvation First Bot Author

    Aug 7, 2013
    Likes Received:
    I believe Jagex has indeed made randoms not appear while in combat (although this wasn't the case back in the days), but aggressive creatures can still attack if it's a random event of group A or B.
  5. Viewer

    Viewer Discretion is advised

    Jan 2, 2014
    Likes Received:
    I like it, Rick Turpentine is a talking random btw :p
  6. Salvation

    Salvation First Bot Author

    Aug 7, 2013
    Likes Received:
    Then what was the one which shows you three objects? O well
  7. Viewer

    Viewer Discretion is advised

    Jan 2, 2014
    Likes Received:
    Its called Certer
  8. Aidden

    Aidden The better executive

    Dec 3, 2013
    Likes Received:
    Good idea however perhaps we should consider a system similar to osbots where the client handles the randoms by default, however scripts bots also has access to methods that help in this situation, those being one that executes before the random handler does its thing, one that executes after the random has completed and one that completely replaces the default random handler if i remember correctly. This sort of system would allow the script bot to exit for example the chicken pen before allowing the solver to take over and upon completing the solver, reenter the pen.

    This is something what it looks like in osbot
    Code (Text):
    2. import org.osbot.script.Script;
    3. import org.osbot.script.rs2.model.NPC;
    4. import org.osbot.script.rs2.randoms.RandomBehaviourHook;
    5. import org.osbot.script.rs2.randoms.RandomManager;
    8. public class Example extends Script{
    9.     @Override
    10.     public void onStart() {
    12.         randomManager.registerHook(
    13.                 new RandomBehaviourHook(RandomManager.STRANGE_PLANT) {
    15.                     @Override
    16.                     public boolean shouldActivatePreLoop() {
    17.                         return false;
    18.                     }
    20.                     @Override
    21.                     public int preLoop() {
    22.                         return 100;
    23.                     }
    25.                     @Override
    26.                     public int onLoop() throws InterruptedException {
    27.                         NPC plant = closestNPCForName("Strange Plant");
    29.                         if (plant != null) {
    30.                             if (plant.isFacing(client.getMyPlayer()))
    31.                                 plant.interact("Pick");
    32.                         }
    33.                         return super.onLoop();
    34.                     }
    36.                     @Override
    37.                     public boolean shouldActivatePostLoop() {
    38.                         return false;
    39.                     }
    41.                     @Override
    42.                     public int postLoop() {
    43.                         return 100;
    44.                     }
    46.                 }
    47.         );
    48.     }
    49. }
    I wouldn't consider this copying but rather using the most sensible and logical approach.
    And after reading the code you posted i realized this is practically the same idea, lol
    #8 Aidden, May 2, 2014
    Last edited: May 2, 2014

Share This Page