The client is offline due to RuneScape update. You may see instance errors but this is due to the update and not actual instance errors. This should be resolved soon. Join our Discord for more information.

Toggle run energy



  • Hey,

    A lot of you might know this piece of code already, but for new coders this might be handy.

    Just call this method whenever you are walking and it will toggle your run energy if it isn't enabled already and when you have between 20% and 30% run energy.

    import org.rspeer.runetek.api.movement.Movement;
    import org.rspeer.script.Script;
    import org.rspeer.script.ScriptMeta;
    //Import ThreadLocalRandom
    import java.util.concurrent.ThreadLocalRandom;
    
    
    @ScriptMeta(name = "[LUX] Toggle run", desc = "Toggle run energy", developer = "Luxiflex", version = 1.0)
    public class ToggleRun extends Script {
    
    
        //Initialize this integer to keep track of the next change
        private int toggleNextRun = 20;
    
        @Override
        public int loop() {
            //Check run energy while player is moving
            if(Movement.isDestinationSet()){
                checkRunEnergy();
            }
            return 0;
        }
    
        public void checkRunEnergy(){
            if(Movement.getRunEnergy() > toggleNextRun && !Movement.isRunEnabled()){
                Movement.toggleRun(true);
                //Will toggle the run energy when it is between 20 and 30
                toggleNextRun = ThreadLocalRandom.current().nextInt(20, 30 + 1);
            }
        }
    }
    
    

  • Donator

    yo thanks brother i implement this in script ty


  • Director

    It's not 100% ideal to do it this way because assuming you check every loop, it will turn your run energy on at exactly 20% every single time. Which could appear as a bot-like pattern.



  • @MadDev That is true, I am thinking about a sollution and will update it as soon as I've found out how to do this better.


  • Banned

    just find some algorithm to determine the reaction time when it reaches 20 and then count number of loops since you last hit 20, then toggle.

    also probably best not to have every single person use 20, maybe randomizing it per account/user would help (ex. 15, 30, 40)



  • I've updated the code, it now toggles the run energy when it is somewhere between 20 and 30.


  • Director

    Looks good now. I recommend wrapping that logic into a class so it’s easier for beginners to use. Maybe just make a static class and expose setRun()


  • Director

    Looks good now. I recommend wrapping that logic into a class so it’s easier for beginners to use. Maybe just make a static class and expose setRun()



  • @MadDev added the code into a class.



  • Thanks a lot, I was struggling to find the runEnergy stuff in the API, putting this in my first bot.


 

53
Online

16.6k
Users

1.4k
Topics

19.2k
Posts