Jump to content

My first script, please feedbacks!


OsPlay

Recommended Posts

Hi, i started yesterday to write in Java (i'm not a programmer and is not my language), i watch the tutorial on youtube about woodcutting, and try to do something similar...

but most of his code is deprecated, but the idea is the same, if someone has tip or tutorial wich think that is important, a hand will be great!

Anyway, i didn't use inside the loop (wich i think will hurt performance), also managed the code from onStart with a while...

I will play a little bit with it, just cutt for now basic trees at the exchange market... i have to learn about equipament and exchange (for buy axes and equip, etc..), also i have to pass text to vars.

i know maybe already someone ask or even i will try, but when i use:

getWalking().webWalk(//area to go);

i can travel for long distances??

package com.osplay.script;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "MyFirstChopBot", author = "OsPlay", version = 0.0, info = "My First Ugly Script, only Works up to lvl 15 of wood and for F2P!", logo = "")

public class Main extends Script {



    @Override
    public void onStart() throws InterruptedException {
        super.onStart();

        /* BRAIN OF THE SCRIPT
        *
        * 00 - SET STATUS TASK
        * 01 - LOOP
        * 02 - GO TO CHOP
        * 03 - GO TO BANK
        * 04 - HANDLE ERRORS
        *
        *  */

        STATUS_TASK = STATUS_TASK_TYPE.IDLE;
        ERROR_STATUS status_of_the_task = ERROR_STATUS.ALL_OK;

        log("Bot Executed - By OsBay the N00b D:");
        while(true){

            if(TASK_ENDED)
                return;

            // SECURITY LOOP !
            sleep(random(1000,3000));

            _Execute_Print_Debug(status_of_the_task);

            if(STATUS_TASK == STATUS_TASK_TYPE.IDLE){

                log("Bot is idle, will reached next step!");
                if (getInventory().isFull()) {
                    log("Executing Banking -/-");
                    status_of_the_task = _Execute_Go_Banking();
                } else {
                    log("Executing cutting -/-");
                    status_of_the_task = _Execute_Cutting_Trees();
                }
                continue;
            }

            if(STATUS_TASK == STATUS_TASK_TYPE.CUTTING_REQUIRED || STATUS_TASK == STATUS_TASK_TYPE.CUTTING){
                log("Executing cutting -/-");
                status_of_the_task = _Execute_Cutting_Trees();
                continue;
            }

            if(STATUS_TASK == STATUS_TASK_TYPE.BANKING_REQUIRED || STATUS_TASK == STATUS_TASK_TYPE.BANKING){
                log("Executing Banking -/-");
                status_of_the_task = _Execute_Go_Banking();
                continue;
            }
        }

    }


    @Override
    public void onExit() throws InterruptedException {
        super.onExit();
        TASK_ENDED = true;
    }


    @Override
    public int onLoop() throws InterruptedException {

        return 0;
    }


    // -- HERE GOES ALL VARS --

    public boolean TASK_ENDED = false;

    public enum STATUS_TASK_TYPE {
        IDLE,
        IDLE_REQUIRED,
        CUTTING,
        CUTTING_REQUIRED,
        BANKING,
        BANKING_REQUIRED
    }

    public enum ERROR_STATUS {
        ALL_OK,
        FAIL_ALREADY_CHOPPING,
        FAIL_INVENTORY_FULL,
        FAIL_OBJECT_TREE_NOT_FIND,
        FAIL_PLAYER_IS_IN_ANIMATION,
        FAIL_PLAYER_IS_MOVING,
        FAIL_REQUIRED_ACTION,
        FAIL_CANT_GET_BANKER_NPC,
        FAIL_BANK_IS_NOT_OPEN,
        FAIL_INVENTORY_COULDNT_BANK,
        FAIL_UNKNOWN_WHY_SHAME_ON_ME;
    }

    public static STATUS_TASK_TYPE STATUS_TASK;

    public enum OBJECTS_NAMES{
        TREE("Tree"),
        OAK("Oak"),
        WILLOW("Willow"),
        MAPLE("Maple"),
        YEW("Yew");

        OBJECTS_NAMES(String empty) {

        }
    }

    /*
        AREAS ARE DEFINED INSIDE THE RESPECTIVE TASK
     */

    // -- HERE ENDS ALL VARS --


    // -- HERE GOES ALL FUNC --

    private ERROR_STATUS _Execute_Cutting_Trees() throws InterruptedException {

        Area area_to_chop_tree = new Area(3149,3450,3171,3462);

        /*
            A00 - The player is idle so or requires to chop ->
                A01 - check if is need to bank
                A02 - check if is in the place of the exchange area
                A03 - search for a tree in x place
                A04 - chop the tree

            B00 - The player is already chopping ->
                B01 - check if need to bank
                B02 - verify is chopping
                B03 - sleep and until 01 required.
         */

        // A00
        if(STATUS_TASK == STATUS_TASK_TYPE.IDLE || STATUS_TASK == STATUS_TASK_TYPE.CUTTING_REQUIRED){

            // ask to banking A01
            if(getInventory().isFull()){
                STATUS_TASK = STATUS_TASK_TYPE.BANKING_REQUIRED;
                return ERROR_STATUS.FAIL_REQUIRED_ACTION;
            }

            // go to the place A02
            if(!area_to_chop_tree.contains(0, myPosition().getY())){
                // go to the place!
                getWalking().webWalk(area_to_chop_tree);
            }

            Entity tree_to_chop = getObjects().closest(OBJECTS_NAMES.TREE.toString());

            if(tree_to_chop == null) return ERROR_STATUS.FAIL_OBJECT_TREE_NOT_FIND;

            // we enter to a loop where gonna check A03 and A04

            if(myPlayer().isMoving()){
                sleep(random(2000,5000));
            }

            if(!tree_to_chop.isVisible()){
                getCamera().toEntity(tree_to_chop);
                sleep(random(2000,4000));
            }

            tree_to_chop.interact("Chop down");
            sleep(random(2000,4000));
            STATUS_TASK = STATUS_TASK_TYPE.CUTTING;
        }

        // B00
        if(STATUS_TASK == STATUS_TASK_TYPE.CUTTING){

            boolean flag_check_if_is_afk = false;

            while (true){
                // check if needs bank B01
                if(getInventory().isFull()){
                    STATUS_TASK = STATUS_TASK_TYPE.BANKING_REQUIRED;
                    return ERROR_STATUS.FAIL_REQUIRED_ACTION;
                }

                // for some reason is not cutting, first flag! B02
                if(!myPlayer().isAnimating()) {
                    flag_check_if_is_afk = true;
                }

                // 2nd time of flag, we must go to another
                if(flag_check_if_is_afk && !myPlayer().isAnimating()){
                    STATUS_TASK = STATUS_TASK_TYPE.CUTTING_REQUIRED;
                    return ERROR_STATUS.ALL_OK;
                }

                sleep(random(2000,5000)); //B03


            }

        }

        return ERROR_STATUS.FAIL_UNKNOWN_WHY_SHAME_ON_ME;
    }

    private ERROR_STATUS _Execute_Go_Banking() throws InterruptedException {

        Area area_banking_exchange_bottom = new Area(3160,3479,3168,3487);
        /*
                A00 - We gonna to the bank near the exchange!
                    A01 - We check if are in the place
                    A02 - if not We go to the place

                B00 - We gonna execute the banking
                    B01 - We talk with them
                    B02 - We bank all
                    B03 - Check, and ask to go cutting!
                    B04 - Set To Chop!

         */

        // A00 WE GONNA TO THE BANK
        if(STATUS_TASK == STATUS_TASK_TYPE.BANKING_REQUIRED || STATUS_TASK == STATUS_TASK_TYPE.IDLE){

            if(!getInventory().isFull()){
                STATUS_TASK = STATUS_TASK_TYPE.CUTTING_REQUIRED;
                return ERROR_STATUS.FAIL_INVENTORY_COULDNT_BANK;
            }

            // A01 0 is because are shared X but not Y
            if(!area_banking_exchange_bottom.contains(0,myPosition().getY())){
                // A02
                getWalking().webWalk(area_banking_exchange_bottom);
            }

            if(area_banking_exchange_bottom.contains(myPosition().getX(), myPosition().getY())){
                STATUS_TASK = STATUS_TASK_TYPE.BANKING;
            }
        }


        // B00 WE MUST START BANKING
        if(STATUS_TASK == STATUS_TASK_TYPE.BANKING){

            if(myPlayer().isMoving() || myPlayer().isAnimating()){
                // wait, he don't have to move!
                while (true){

                    if(myPlayer().isMoving() || myPlayer().isAnimating()){
                        sleep(random(2000,5000));
                    } else {
                        break;
                    }


                }

            }

            NPC banker_npc_to_talk = getNpcs().closest("Banker");

            // B01 banker is not reachable?
            if(banker_npc_to_talk == null) return ERROR_STATUS.FAIL_CANT_GET_BANKER_NPC;

            banker_npc_to_talk.interact("Bank");

            sleep(random(3000,6000));

            if(!bank.isOpen()) return ERROR_STATUS.FAIL_BANK_IS_NOT_OPEN;

            // B02

            bank.depositAll();

            // B03
            if(getInventory().isFull()) return ERROR_STATUS.FAIL_INVENTORY_COULDNT_BANK;

            //B04
            STATUS_TASK = STATUS_TASK_TYPE.CUTTING_REQUIRED;

        }

        return ERROR_STATUS.ALL_OK;

    }

    private void _Execute_Print_Debug(ERROR_STATUS status_to_print){

        switch (status_to_print){

            case ALL_OK:
                log("Task Completed!");
            break;

            case FAIL_ALREADY_CHOPPING:
                log("Fail: bot is already Chopping a tree?");
                break;
            case FAIL_INVENTORY_FULL:
                log("Inventory is full!");
                break;
            case FAIL_OBJECT_TREE_NOT_FIND:
                log("Fail: couldn't find the tree!");
                break;
            case FAIL_PLAYER_IS_IN_ANIMATION:
                log("Fail: player is in busy with an animation.");
                break;
            case FAIL_PLAYER_IS_MOVING:
                log("Fail: Player is moving to a location.");
                break;
            case FAIL_REQUIRED_ACTION:
                log("Fail: Player couldn't do that action.");
                break;
            case FAIL_CANT_GET_BANKER_NPC:
                log("Fail: Player couldn't go to the Banker NPC.");
                break;
            case FAIL_BANK_IS_NOT_OPEN:
                log("Fail: Bank is not opened!");
                break;
            case FAIL_INVENTORY_COULDNT_BANK:
                log("Fail: Player couldn't bank!");
                break;
            case FAIL_UNKNOWN_WHY_SHAME_ON_ME:
                log("Fail: Bot Error reached!");
                break;
            default:
                log("Error to print error ? LMAO");
            break;
        }

    }
    // -- HERE ENDS ALL FUNC --

}


Good job with this bot, is easy to understand and work, even for a n00b like me xD

 

Link to comment
Share on other sites

6 minutes ago, Naked said:

Time to go get chemo

LMAO

 

To start, onStart() is called once when the script is first started. I'd recommend using onLoop() instead. Personally, everyone learns differently so just copy and pasting code in hopes of making it work may not be the best choice for you if you don't even understand the language.

 

Also, look at the api here https://osbot.org/api/ to get a better understanding of what each function does. This way you can see when a function gets called or how to access it, etc etc.

Edited by Aether
  • Like 1
Link to comment
Share on other sites

17 hours ago, Naked said:

Time to go get chemo

Yeah, hahahaha.

17 hours ago, Malcolm said:

    @Override
    public int onLoop() throws InterruptedException {

        return 0;
    }

This should be utilized to create your actual script functionality.

https://osbot.org/api/org/osbot/rs07/script/Script.html

onStart()

Called when this script gets started.


onExit()

Called when this script exits.

 

onLoop()

Called by the script executor.

 

 

On another note, I'd highly suggest breaking down your code into functions. I personally may do this too much, but I don't like to have huge methods.

I tend to stick to 15-20 lines tops for a single method, a lot are even shorter than that.

Oh, thx, i work more with classes, but i didn't know how to extend from script without carring onLoop in a new classes, so i thought on hurt performance if i call multiples onLoop in diferent instances...

17 hours ago, Aether said:

LMAO

 

To start, onStart() is called once when the script is first started. I'd recommend using onLoop() instead. Personally, everyone learns differently so just copy and pasting code in hopes of making it work may not be the best choice for you if you don't even understand the language.

 

Also, look at the api here https://osbot.org/api/ to get a better understanding of what each function does. This way you can see when a function gets called or how to access it, etc etc.

Thx for the tip, yep on youtube call to client class...when i go in to the code and typ... wait what?? 😧...
so i started to play with functions 🤪
and then i come with that ugly non functional script hahaha.

13 hours ago, Protoprize said:

You've really over complicated a simple script idea, it's good that you're trying to learn, but you might want to think about the simple logic that you're really doing. You'd be surprised at how simple some scripts are compared to what they actually do  

Oh, i create first all java stuff just for test (enum, class, etc) and check differences with .NET where i have a lot of stuff like structs,interfaces also cheap ways to go arround like out and goto, also i was worried because threads are a pain if you don't manage correctly.
The funny thing was when i start to write the script, was like: "Shiiiiit", most of the time i have to battle with Cheat Engine and opcode :( , but here is so easy to manage things, that mean a lot of work for the developers!

5 hours ago, erenjwz said:

I feel you went a little overboard with the enumerations for such a simple bot.

Maybe look at

 

WOW AWSOME!! i'm reading it right now, you just anwser my question 😍 .

thx for the feedbacks, i create a new script, now can chop and change axe and locations 😁

public class Main extends Script {

    public String AXE_REQUIRED = null;
    public String AXE_EQUIPPED = null;

    public Area AREA_TO_CHOP = null;
    public Area AREA_TO_BANK = null;

    public final int MAX_FLAG = 3;

    public String TREE_TO_CHOP = null;

    @Override
    public int onLoop() throws InterruptedException {

        _Check_Required_For_Set();

        // AFK
        sleep(random(1000,2000));

        if(_Check_Axe_What_Axe_Is_Equipped()){
            log("Your axe is not equipped!");
            return 0;
        }

        if(getInventory().isFull()){

            if(!_Execute_Go_To_Area(AREA_TO_BANK)) return 0;

            if(!_Execute_Action(ACTION_TYPE.BANK)) return 0;

            if(!_Check_Axe_Is_Optimal()){
                log("Your axe is not optimal for you level, choose: " + AXE_REQUIRED);

                if(_Execute_Get_Bank_Axe()){
                    _Execute_Set_Optimal_Axe();
                }
            }

        }

        if(!_Execute_Go_To_Area(AREA_TO_CHOP)) return 0;

        if(!_Execute_Action(ACTION_TYPE.CHOP)) return 0;

        // player is chopping!
        while (myPlayer().isAnimating() || myPlayer().isMoving()){
            sleep(random(2000,4000));
        }

        return 0;
    }

    private void _Check_Required_For_Set(){

        int skill_level_woodcutting = getSkills().getDynamic(Skill.WOODCUTTING);
        int skill_level_attack = getSkills().getDynamic(Skill.ATTACK);

        AXE_REQUIRED = OBJECTS.BRONZE_AXE;

        AREA_TO_CHOP = AREAS.TREE_EXCHANGE;
        AREA_TO_BANK = AREAS.EXCHANGE_BOTTOM;
        TREE_TO_CHOP = OBJECTS.TREE;

        if(skill_level_woodcutting < 11) {
            AXE_REQUIRED = OBJECTS.BRONZE_AXE;
            AREA_TO_CHOP = AREAS.TREE_EXCHANGE;
            AREA_TO_BANK = AREAS.EXCHANGE_BOTTOM;
            return;
        }

        if(skill_level_woodcutting > 14){
            TREE_TO_CHOP = OBJECTS.OAK;
            AREA_TO_CHOP = AREAS.OAK_EXCHANGE;
            AREA_TO_BANK = AREAS.EXCHANGE_LEFT;
        }

        if(skill_level_woodcutting < 21 && skill_level_attack > 9) {
            AXE_REQUIRED = OBJECTS.BLACK_AXE;
            AREA_TO_CHOP = AREAS.OAK_EXCHANGE;
            AREA_TO_BANK = AREAS.EXCHANGE_LEFT;
            return;
        }

        if(skill_level_woodcutting < 31 && skill_level_attack > 20) {
            AXE_REQUIRED = OBJECTS.MITHRIL_AXE;
            return;
        }

        if(skill_level_woodcutting > 29 && AXE_EQUIPPED == OBJECTS.MITHRIL_AXE){
            TREE_TO_CHOP = OBJECTS.WILLOW;
            AREA_TO_CHOP = AREAS.WILLOW_DRAYNOR;
            AREA_TO_BANK = AREAS.BANK_DRAYNOR;
        }

        if(skill_level_woodcutting < 41 && skill_level_attack > 30){
            AXE_REQUIRED = OBJECTS.ADAMANT_AXE;
            return;
        }

        if(skill_level_attack > 40){
            AXE_REQUIRED = OBJECTS.RUNE_AXE;
        }
    }

    private boolean _Check_Axe_What_Axe_Is_Equipped(){
        Item axe = getEquipment().getItem(OBJECTS.AXE);

        if(axe == null) return false;

        String axe_name = axe.getName();
        if(axe_name == null) return false;

        // for some reason switch requires that static to object but i like annotation

        if(axe_name == OBJECTS.BRONZE_AXE){
            AXE_EQUIPPED = OBJECTS.BRONZE_AXE;
            return true;
        }

        if(axe_name == OBJECTS.BLACK_AXE){
            AXE_EQUIPPED = OBJECTS.BLACK_AXE;
            return true;
        }

        if(axe_name == OBJECTS.MITHRIL_AXE){
            AXE_EQUIPPED = OBJECTS.MITHRIL_AXE;
            return true;
        }

        if(axe_name == OBJECTS.ADAMANT_AXE){
            AXE_EQUIPPED = OBJECTS.ADAMANT_AXE;
            return true;
        }

        if(axe_name == OBJECTS.RUNE_AXE){
            AXE_EQUIPPED = OBJECTS.RUNE_AXE;
            return true;
        }

        AXE_EQUIPPED = null;
        return false;

    }

    private boolean _Check_Axe_Is_Optimal(){

        if(AXE_REQUIRED == AXE_EQUIPPED) return true;

        return false;

    }

    private boolean _Execute_Go_To_Area(Area area_to_go){

        int flag = 0;

        while (flag != MAX_FLAG){

            if(!area_to_go.contains(0,myPlayer().getY())){
                getWalking().webWalk(area_to_go);

                if(area_to_go.contains(myPosition().getX(),myPlayer().getY())){
                    return true;
                }

            }

            flag++;
        }

        return false;
    }

    private boolean _Execute_Action(ACTION_TYPE action) throws InterruptedException {

        int flag = 0;

        while (myPlayer().isMoving() || myPlayer().isAnimating()){
            if(flag == MAX_FLAG){
                log("Fail: Player is not static when is close to the object.");
                return false;
            }
            sleep(random(1000,3000));
            flag++;

        }

        Entity object = null;

        if(ACTION_TYPE.CHOP == action){
            object = getObjects().closest(TREE_TO_CHOP);
        } else {
            object = getNpcs().closest(OBJECTS.BANKER);
        }

        if(object == null) return false;

        flag = 0;

        while (!object.isVisible()){

            if(flag == MAX_FLAG) {
                log("Fail: Camera can't reach to the object!");
                return false;
            }

            getCamera().toEntity(object);
            sleep(random(2000,4000));
            flag++;
        }

        String interaction = null;

        if(action == ACTION_TYPE.CHOP){
            interaction = INTERACTIONS.CHOP;
        } else {
            interaction = INTERACTIONS.BANK;
        }

        if(!object.interact(interaction)){
            log("Fail: couldn't interact with the object!");
            return false;
        }

        sleep(random(2000,4000));

        if(action == ACTION_TYPE.BANK) {

            flag = 0;

            while (!bank.isOpen()) {

                if (flag == MAX_FLAG) {
                    log("Fail: couldn't open the object!");
                    return false;
                }

                sleep(random(2000, 4000));

            }

            bank.depositAll();

            if (getInventory().isFull()) {
                log("For someone reason, couldn't save the items!");
                return false;
            }

        }

        return true;


    }

    private boolean _Execute_Get_Bank_Axe(){

        if(!bank.isOpen()){
            log("Fail: Bank is not open!");
        }

        return bank.withdraw(AXE_REQUIRED,1);

    }

    private boolean _Execute_Set_Optimal_Axe() throws InterruptedException {

        if(bank.isOpen()){
            bank.close();
        }

        if(!getEquipment().equip(EquipmentSlot.WEAPON, AXE_REQUIRED)){
            log("Fail: you can't equip an axe!");
            return false;
        }

        if(_Execute_Action(ACTION_TYPE.BANK)){
            log("Fail: couldn't bank the axe!");
            return false;
        }

        return true;

    }

    enum ACTION_TYPE {
        CHOP,
        BANK;
    }
}

class AREAS{

    public static Area EXCHANGE_BOTTOM = new Area(3160,3479,3168,3487);
    public static Area TREE_EXCHANGE = new Area(3149,3450,3171,3462);

    public static Area OAK_EXCHANGE = new Area(3189,3464, 3200,3456);
    public static Area EXCHANGE_LEFT = new Area(3170,3487,3167,3491);

    public static Area BANK_DRAYNOR = new Area(3092,3240,3095,3246);
    public static Area WILLOW_DRAYNOR = new Area(3087,3223,3089,3237);



}

class INTERACTIONS {
    public static String BANK = "Bank";
    public static String CHOP = "Chop down";
}

class OBJECTS{
    public static String TREE = "Tree";
    public static String OAK = "Oak";
    public static String WILLOW = "Willow";
    public static String BANKER = "Banker";
    public static String AXE = " axe";
    public static String BRONZE_AXE = "Bronze axe";
    public static String BLACK_AXE = "Black axe";
    public static String MITHRIL_AXE = "Mithril axe";
    public static String ADAMANT_AXE = "Adamant axe";
    public static String RUNE_AXE = "Rune axe";
}

for some reason java force me to put as static the list of objects and then i lose the syntax, sorry @Naked you will require another round of chemo, because i don't use switch 😭

Thx for the support, great community also!

PD: english is not my mother language, sorry x2!

Link to comment
Share on other sites

Hello OsPlay,

I made this for you. Dont over think things and don't do anything fancy.  Just fill out the methods. It will make you a realy good wood cutting bot and I hope you learn alot in the posses. 

package com.bacon.bot;

import com.bacon.bot.scheme.prim.finalproduct.Area;
import org.osbot.rs07.script.Script;

import java.util.ArrayList;

public class Main extends Script {


    class Axe{
        private final String name;
        private final int woodcuttingLevel;
        private final int attackLevel;
        Axe(String name, int woodcuttingLevel, int attackLevel){


            this.name = name;
            this.woodcuttingLevel = woodcuttingLevel;
            this.attackLevel = attackLevel;
        }
        public String getName() {
            return name;
        }
        public int getWoodcuttingLevel() {
            return woodcuttingLevel;
        }
        public int getAttackLevel() {
            return attackLevel;
        }
        /**
         * @return True Is this axe inside the bank
         *         False if you are wearing it.<<<<100% important
         */
        public boolean doIHave() {
            return  false;
        }

        /**
         * Withdraws the axe from the bank
         */
        public void withDraw() {

        }
    }

    class Trees{
        public String getName() {
            return name;
        }

        public Area[] getArea() {
            return area;
        }

        public int getWoodcuttingLevel() {
            return woodcuttingLevel;
        }

        private final String name;
        private final Area [] area;
        private final int woodcuttingLevel;
        Trees(String name, int woodcuttingLevel, Area... area){

            this.name = name;
            this.woodcuttingLevel = woodcuttingLevel;
            this.area =area;
        }


    }


    boolean drop_Logs =false;
    ArrayList<Trees> trees =new ArrayList<>();
    ArrayList<Axe> axes =new ArrayList<>();
    ArrayList<Area> banks =new ArrayList<>();

    Trees curentTree=null;

    @Override
    public void onStart() throws InterruptedException {
        //code that sets this may make a gui?
        drop_Logs=false;
        //add the trees and areas here
        trees.add(new Trees("tree",1, Area1,Area2,Area3....));
        trees.add(new Trees("Oak",15, Area1,Area2,Area3....));
        //add the axes here
        axes.add(new Axe("Bronze",1,1));
        axes.add(new Axe("Iron",1,1));
        //add banks here
        banks.add(new Area(1,1,1,1));
        banks.add(new Area(1,1,1,1));
    }

    @Override
    public int onLoop() throws InterruptedException {

    curentTree= bestTree();


        if (insideABank()){
            UseTheBank();
        }else if (needToBank()){
            walkToBank();
        }else if(needToDrop()){
            dropLogs();
        }else if(notNearTrees()){
            walkToTrees();
        }else if(notChoppingTrees()){
            ChopTrees();
        }else {
            //does nothing nothing should be here.
        }

        return 2312;//<<<<< this is a loop timer so it will say pause for 2312 ms and the
                    //play this again
    }

    /**
     * @return   finds the best tree and the closest patch
     */
    private Trees bestTree() {
        return  new Trees();
    }


    /**
     * @return loop though all your supported banks and see if your inside one.
     */
    private boolean insideABank(){
        return false;
    }

    private void UseTheBank(){
        if (bankNotOpen()){
            OpenBank();
        }else if(inventoryHasWrongItems()){
            getShitOrDeposit();
        }else {
            walkToTrees();
        }

    }

    /**
     * @return If the bank is "not" open AKA True is bank closed
     */
    private boolean bankNotOpen() {
        return false;
    }

    /**
     * This just opens the bank.
     */
    private void OpenBank() {
    }
    /**
     * @return IF the Inv has logs
     * or
     * the player does not have an axe
     * or
     * the bank has a better axe it can use.
     */
    private boolean inventoryHasWrongItems() {


        return false;
    }
    /**
     * Gets Items from the bank or deposits logs
     * Don't make it to hard on yourself
     */
    private void getShitOrDeposit() {
        if (inv_full()){
            Deposit_all_but_axe();
        }else if (bestAxInsideBankOROnMEThatICanUse().doIHave()){
            bestAxInsideBankOROnMEThatICanUse().withDraw();
        }


    }


    /**
     * @return True If the inv is full,
     * better would be to say if the bot has things that are not an axe.
     */
    private boolean inv_full() {

        return false;
    }

    /**
     * Deposits all the items that are not the an axe
     */
    private void Deposit_all_but_axe() {

    }

    /**
     * @return Loops though all the axes and returns the best one
     *         that you are wearing or is in your bank
     *         So say you have a bronze axe on and your wc is 21
     *         and you have mith axe it would return mith
     *         and also say you have a mith axe in your inv and your wc is
     *         21 still returns mith axe
     */
    private Axe bestAxInsideBankOROnMEThatICanUse(){



        return new Axe(name, woodcuttingLevel, attackLevel);
    }




    /**
     * @return True if your inv is full or you dont have an axe.
     */
    private boolean needToBank(){
        return false;
    }

    /**
     * Walks to the closest bank
     */
    private void walkToBank(){

    }

    /**
     * @return returns true if inv is full and drop_logs is true
     */
    private boolean needToDrop() {
        return drop_Logs&& ;
    }

    /**
     * Drops all logs
     */
    private void dropLogs() {

    }

    /**
     * @return True if your not in the Tree area
     */
    private boolean notNearTrees(){
//        curentTree [use it ]
        return false;
    }
    /**
     * Walks to the Tree area
     */
    private void walkToTrees(){
//        curentTree [use it ]
    }

    /**
     * @return True if your not chopping a tree
     */
    private boolean notChoppingTrees(){
        return false;
    }

    /**
     * Clicks a tree.
     */
    private void ChopTrees(){
//        curentTree [use it ]
    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

On 7/20/2020 at 3:53 AM, OsPlay said:

Yeah, hahahaha.

Oh, thx, i work more with classes, but i didn't know how to extend from script without carring onLoop in a new classes, so i thought on hurt performance if i call multiples onLoop in diferent instances...

Thx for the tip, yep on youtube call to client class...when i go in to the code and typ... wait what?? 😧...
so i started to play with functions 🤪
and then i come with that ugly non functional script hahaha.

Oh, i create first all java stuff just for test (enum, class, etc) and check differences with .NET where i have a lot of stuff like structs,interfaces also cheap ways to go arround like out and goto, also i was worried because threads are a pain if you don't manage correctly.
The funny thing was when i start to write the script, was like: "Shiiiiit", most of the time i have to battle with Cheat Engine and opcode :( , but here is so easy to manage things, that mean a lot of work for the developers!

WOW AWSOME!! i'm reading it right now, you just anwser my question 😍 .

thx for the feedbacks, i create a new script, now can chop and change axe and locations 😁


public class Main extends Script {

    public String AXE_REQUIRED = null;
    public String AXE_EQUIPPED = null;

    public Area AREA_TO_CHOP = null;
    public Area AREA_TO_BANK = null;

    public final int MAX_FLAG = 3;

    public String TREE_TO_CHOP = null;

    @Override
    public int onLoop() throws InterruptedException {

        _Check_Required_For_Set();

        // AFK
        sleep(random(1000,2000));

        if(_Check_Axe_What_Axe_Is_Equipped()){
            log("Your axe is not equipped!");
            return 0;
        }

        if(getInventory().isFull()){

            if(!_Execute_Go_To_Area(AREA_TO_BANK)) return 0;

            if(!_Execute_Action(ACTION_TYPE.BANK)) return 0;

            if(!_Check_Axe_Is_Optimal()){
                log("Your axe is not optimal for you level, choose: " + AXE_REQUIRED);

                if(_Execute_Get_Bank_Axe()){
                    _Execute_Set_Optimal_Axe();
                }
            }

        }

        if(!_Execute_Go_To_Area(AREA_TO_CHOP)) return 0;

        if(!_Execute_Action(ACTION_TYPE.CHOP)) return 0;

        // player is chopping!
        while (myPlayer().isAnimating() || myPlayer().isMoving()){
            sleep(random(2000,4000));
        }

        return 0;
    }

    private void _Check_Required_For_Set(){

        int skill_level_woodcutting = getSkills().getDynamic(Skill.WOODCUTTING);
        int skill_level_attack = getSkills().getDynamic(Skill.ATTACK);

        AXE_REQUIRED = OBJECTS.BRONZE_AXE;

        AREA_TO_CHOP = AREAS.TREE_EXCHANGE;
        AREA_TO_BANK = AREAS.EXCHANGE_BOTTOM;
        TREE_TO_CHOP = OBJECTS.TREE;

        if(skill_level_woodcutting < 11) {
            AXE_REQUIRED = OBJECTS.BRONZE_AXE;
            AREA_TO_CHOP = AREAS.TREE_EXCHANGE;
            AREA_TO_BANK = AREAS.EXCHANGE_BOTTOM;
            return;
        }

        if(skill_level_woodcutting > 14){
            TREE_TO_CHOP = OBJECTS.OAK;
            AREA_TO_CHOP = AREAS.OAK_EXCHANGE;
            AREA_TO_BANK = AREAS.EXCHANGE_LEFT;
        }

        if(skill_level_woodcutting < 21 && skill_level_attack > 9) {
            AXE_REQUIRED = OBJECTS.BLACK_AXE;
            AREA_TO_CHOP = AREAS.OAK_EXCHANGE;
            AREA_TO_BANK = AREAS.EXCHANGE_LEFT;
            return;
        }

        if(skill_level_woodcutting < 31 && skill_level_attack > 20) {
            AXE_REQUIRED = OBJECTS.MITHRIL_AXE;
            return;
        }

        if(skill_level_woodcutting > 29 && AXE_EQUIPPED == OBJECTS.MITHRIL_AXE){
            TREE_TO_CHOP = OBJECTS.WILLOW;
            AREA_TO_CHOP = AREAS.WILLOW_DRAYNOR;
            AREA_TO_BANK = AREAS.BANK_DRAYNOR;
        }

        if(skill_level_woodcutting < 41 && skill_level_attack > 30){
            AXE_REQUIRED = OBJECTS.ADAMANT_AXE;
            return;
        }

        if(skill_level_attack > 40){
            AXE_REQUIRED = OBJECTS.RUNE_AXE;
        }
    }

    private boolean _Check_Axe_What_Axe_Is_Equipped(){
        Item axe = getEquipment().getItem(OBJECTS.AXE);

        if(axe == null) return false;

        String axe_name = axe.getName();
        if(axe_name == null) return false;

        // for some reason switch requires that static to object but i like annotation

        if(axe_name == OBJECTS.BRONZE_AXE){
            AXE_EQUIPPED = OBJECTS.BRONZE_AXE;
            return true;
        }

        if(axe_name == OBJECTS.BLACK_AXE){
            AXE_EQUIPPED = OBJECTS.BLACK_AXE;
            return true;
        }

        if(axe_name == OBJECTS.MITHRIL_AXE){
            AXE_EQUIPPED = OBJECTS.MITHRIL_AXE;
            return true;
        }

        if(axe_name == OBJECTS.ADAMANT_AXE){
            AXE_EQUIPPED = OBJECTS.ADAMANT_AXE;
            return true;
        }

        if(axe_name == OBJECTS.RUNE_AXE){
            AXE_EQUIPPED = OBJECTS.RUNE_AXE;
            return true;
        }

        AXE_EQUIPPED = null;
        return false;

    }

    private boolean _Check_Axe_Is_Optimal(){

        if(AXE_REQUIRED == AXE_EQUIPPED) return true;

        return false;

    }

    private boolean _Execute_Go_To_Area(Area area_to_go){

        int flag = 0;

        while (flag != MAX_FLAG){

            if(!area_to_go.contains(0,myPlayer().getY())){
                getWalking().webWalk(area_to_go);

                if(area_to_go.contains(myPosition().getX(),myPlayer().getY())){
                    return true;
                }

            }

            flag++;
        }

        return false;
    }

    private boolean _Execute_Action(ACTION_TYPE action) throws InterruptedException {

        int flag = 0;

        while (myPlayer().isMoving() || myPlayer().isAnimating()){
            if(flag == MAX_FLAG){
                log("Fail: Player is not static when is close to the object.");
                return false;
            }
            sleep(random(1000,3000));
            flag++;

        }

        Entity object = null;

        if(ACTION_TYPE.CHOP == action){
            object = getObjects().closest(TREE_TO_CHOP);
        } else {
            object = getNpcs().closest(OBJECTS.BANKER);
        }

        if(object == null) return false;

        flag = 0;

        while (!object.isVisible()){

            if(flag == MAX_FLAG) {
                log("Fail: Camera can't reach to the object!");
                return false;
            }

            getCamera().toEntity(object);
            sleep(random(2000,4000));
            flag++;
        }

        String interaction = null;

        if(action == ACTION_TYPE.CHOP){
            interaction = INTERACTIONS.CHOP;
        } else {
            interaction = INTERACTIONS.BANK;
        }

        if(!object.interact(interaction)){
            log("Fail: couldn't interact with the object!");
            return false;
        }

        sleep(random(2000,4000));

        if(action == ACTION_TYPE.BANK) {

            flag = 0;

            while (!bank.isOpen()) {

                if (flag == MAX_FLAG) {
                    log("Fail: couldn't open the object!");
                    return false;
                }

                sleep(random(2000, 4000));

            }

            bank.depositAll();

            if (getInventory().isFull()) {
                log("For someone reason, couldn't save the items!");
                return false;
            }

        }

        return true;


    }

    private boolean _Execute_Get_Bank_Axe(){

        if(!bank.isOpen()){
            log("Fail: Bank is not open!");
        }

        return bank.withdraw(AXE_REQUIRED,1);

    }

    private boolean _Execute_Set_Optimal_Axe() throws InterruptedException {

        if(bank.isOpen()){
            bank.close();
        }

        if(!getEquipment().equip(EquipmentSlot.WEAPON, AXE_REQUIRED)){
            log("Fail: you can't equip an axe!");
            return false;
        }

        if(_Execute_Action(ACTION_TYPE.BANK)){
            log("Fail: couldn't bank the axe!");
            return false;
        }

        return true;

    }

    enum ACTION_TYPE {
        CHOP,
        BANK;
    }
}

class AREAS{

    public static Area EXCHANGE_BOTTOM = new Area(3160,3479,3168,3487);
    public static Area TREE_EXCHANGE = new Area(3149,3450,3171,3462);

    public static Area OAK_EXCHANGE = new Area(3189,3464, 3200,3456);
    public static Area EXCHANGE_LEFT = new Area(3170,3487,3167,3491);

    public static Area BANK_DRAYNOR = new Area(3092,3240,3095,3246);
    public static Area WILLOW_DRAYNOR = new Area(3087,3223,3089,3237);



}

class INTERACTIONS {
    public static String BANK = "Bank";
    public static String CHOP = "Chop down";
}

class OBJECTS{
    public static String TREE = "Tree";
    public static String OAK = "Oak";
    public static String WILLOW = "Willow";
    public static String BANKER = "Banker";
    public static String AXE = " axe";
    public static String BRONZE_AXE = "Bronze axe";
    public static String BLACK_AXE = "Black axe";
    public static String MITHRIL_AXE = "Mithril axe";
    public static String ADAMANT_AXE = "Adamant axe";
    public static String RUNE_AXE = "Rune axe";
}

for some reason java force me to put as static the list of objects and then i lose the syntax, sorry @Naked you will require another round of chemo, because i don't use switch 😭

Thx for the support, great community also!

PD: english is not my mother language, sorry x2!

Looking better

Link to comment
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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...