Jump to content

Splasher


donaldchen34

Recommended Posts

I am new to writing scripts and am looking for advice and feedback. The script should work though :)

Also looking for help to learn muling and grandexhange support.

Spoiler

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import java.awt.*;

@ScriptManifest(name ="Splasher", author ="", logo = "", version =1 , info ="" )
public class Main extends Script {

    public Area LumbridgeCastle = new Area(3201, 3207, 3221, 3203);
    public final String[] staff = {"Smoke battlestaff", "Cursed goblin staff", "Staff of fire"};
    //public final String[] armor = {"Iron full helm", "Iron platebody", "Iron kiteshield", "Iron plateskirt", "Iron plateleg"};

    public enum state {
        STAFF,
        SPLASH,
        ATTACK,
        MOVEMOUSE,
        WAIT
    }

    public state getState() throws InterruptedException {
        if (!getEquipment().isWieldingWeaponThatContains(staff))
            return state.STAFF;
        if (!getConfigs().isSet(108, getSpell()))
            return state.SPLASH;
        if (!myPlayer().isUnderAttack() && !myPlayer().isAnimating() && getConfigs().isSet(108,getSpell()))
            return state.ATTACK;
        if (myPlayer().isUnderAttack())
            return state.MOVEMOUSE;

        return state.WAIT;
    }


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

    @Override
    public int onLoop() throws InterruptedException {

        switch (getState()) {
            case STAFF:
                getStaff();
                break;
            case SPLASH:
                autocast();
                break;
            case ATTACK:
                attack();
                break;
            case MOVEMOUSE:
                moveMouse();
                break;
            case WAIT:
                sleep(random(200, 500));
        }

        return 500;
    }


    public void getStaff() throws InterruptedException {
        if (!getInventory().contains(staff)) {
            if (!Banks.LUMBRIDGE_UPPER.contains(myPlayer())) {
                getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
            }
            else {
                if (!getBank().isOpen()) {
                    getBank().open();
                } else {
                    getBank().withdraw("Cursed goblin staff", 1);
                    getBank().withdrawAll("Fire Rune");
                    getBank().withdrawAll("Air Rune");
                    getBank().withdrawAll("Mind Rune");
                    getBank().withdraw("Iron full helm", 1);
                    getBank().withdraw("Iron platebody", 1);
                    getBank().withdraw("Iron kiteshield", 1);
                    getBank().withdraw("Iron plateskirt", 1);
                    getBank().withdraw("Iron plateleg", 1);
                    getBank().close();
                }
            }
        }
        else {
            log("equip");
            getInventory().interact("Wear", "Iron full helm");
            getInventory().interact("Wear", "Iron platebody");
            getInventory().interact("Wear", "Iron kiteshield");
            getInventory().interact("Wear", "Iron plateskirt");
            getInventory().interact("Wear", "Iron plateleg");
            getInventory().interact("Wield", staff);
            //getInventory().interact("Wield")
        }
    }

    public boolean isSplashed(NPC npc) {
        return !getPlayers().filter(p -> p.isInteracting(npc)).isEmpty();
    }

    public void attack() {
        NPC rat = getNpcs().closest(new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                return npc != null && npc.isVisible() && getMap().canReach(npc) && !npc.isUnderAttack() && !isSplashed(npc);
            }
        });
        if (!LumbridgeCastle.contains(myPlayer())) {
            getWalking().webWalk(LumbridgeCastle);
        } else {
            if (rat != null ) {
                rat.interact("Attack");
                new ConditionalSleep(5000, 1500) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !myPlayer().isAnimating();
                    }
                }.sleep();
            }
        }
    }


    public int getSpell() {
        if (getSkills().getDynamic(Skill.MAGIC) < 13)
            return 3;
        if (getSkills().getDynamic(Skill.MAGIC) > 13)
            return 9;

        return 0;
    }



    public void autocast() {
        RS2Widget autoCast = getWidgets().get(593,27);
        RS2Widget fireStrike = getWidgets().get(201,1,4);
        RS2Widget windStrike = getWidgets().get(201,1,1);

        if (getSkills().getDynamic(Skill.MAGIC) < 13) {
            if (windStrike != null && windStrike.isVisible()) {
                windStrike.interact();
                new ConditionalSleep(2000, 1000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return autoCast.isVisible();
                    }
                }.sleep();
            }
            else {
                if (!getTabs().getOpen().equals(Tab.ATTACK)) {
                    getTabs().open(Tab.ATTACK);
                    autoCast.interact();
                } else {
                    if (windStrike != null && windStrike.isVisible()) {
                        windStrike.interact();
                        new ConditionalSleep(2000, 1000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return autoCast.isVisible();
                            }
                        }.sleep();
                    }
                }
            }
        }
        else {
            if (getSkills().getDynamic(Skill.MAGIC) > 13) {
                if (fireStrike != null && fireStrike.isVisible()) {
                    fireStrike.interact();
                    new ConditionalSleep(2000, 1000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return autoCast.isVisible();
                        }
                    }.sleep();
                } else {
                    if (!getTabs().getOpen().equals(Tab.ATTACK)) {
                        getTabs().open(Tab.ATTACK);
                    } else {
                        autoCast.interact();
                    }
                }
            }
        }
    }

    public void moveMouse() throws InterruptedException {
        switch (random(1,3)) {

            case 1:
                if (!getTabs().getOpen().equals(Tab.INVENTORY)) {
                    getTabs().open(Tab.INVENTORY);
                    sleep(random(180000, 1080000));
                }
                else {
                    if (getTabs().getOpen().equals(Tab.INVENTORY)) {
                        getTabs().open(Tab.SKILLS);
                        sleep(random(180000, 1080000));
                    }
                }
                break;
            case 2:
                mouse.click(75,458,false); //CHANGE TO LEFT CLICK
                sleep(random(180000, 1080000));
                break;
            case 3:
                if (!getTabs().getOpen().equals(Tab.ATTACK)) {
                    getTabs().open(Tab.ATTACK);
                    sleep(random(180000, 1080000));
                }
                else {
                    sleep(random(2000,10000));
                }
        }

    }

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

    @Override
    public void onPaint(Graphics2D IIiIiiiiIiII) {
        super.onPaint(IIiIiiiiIiII);
    }
}

 

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

  • Remove onExit and onPaint if you're not using them.
  • Remove anti-ban stuff because it's fairly redundant (unless it's there to avoid logging out).
  • Rework your autocast method so that you pass in the spell you want to select as a parameter. This would halve that block of code easily.
  • I'd caution against using state-based scripts because they can be very limiting and inefficient if improperly used (e.g. if you're searching for an NPC twice).

 

Also, when handling weapon/armour, you should (ideally) only do this once. I would suggest making it so your onLoop function does this check and action once, then when you're certain you're ready, you simply switch a boolean flag and it's never checked again:

Spoiler



	boolean ready = false;
	
	@Override
    public int onLoop() throws InterruptedException {
		
		if (client.isLoggedIn()) { // make sure we are logged in
			
			if (ready) { // assume we're good to go
				
				// botty stuffs here
				
			} else { // do your equipment checking/withdrawing/etc. here
				
				if (isReady()) { // let's check to see if we're good to go
					
					ready = true; // set this flag to 'true' so we never re-check anything again
				}
			}
		}
	}


 

 

Your code is looking good - keep it up!

  • Like 1
Link to comment
Share on other sites

33 minutes ago, liverare said:
  • Remove onExit and onPaint if you're not using them.
  • Remove anti-ban stuff because it's fairly redundant (unless it's there to avoid logging out).
  • Rework your autocast method so that you pass in the spell you want to select as a parameter. This would halve that block of code easily.
  • I'd caution against using state-based scripts because they can be very limiting and inefficient if improperly used (e.g. if you're searching for an NPC twice).

 

Also, when handling weapon/armour, you should (ideally) only do this once. I would suggest making it so your onLoop function does this check and action once, then when you're certain you're ready, you simply switch a boolean flag and it's never checked again:

  Reveal hidden contents

 



	boolean ready = false;
	
	@Override
    public int onLoop() throws InterruptedException {
		
		if (client.isLoggedIn()) { // make sure we are logged in
			
			if (ready) { // assume we're good to go
				
				// botty stuffs here
				
			} else { // do your equipment checking/withdrawing/etc. here
				
				if (isReady()) { // let's check to see if we're good to go
					
					ready = true; // set this flag to 'true' so we never re-check anything again
				}
			}
		}
	}

 

 

 

 

 

Your code is looking good - keep it up!

  • he is scripter 3, u must hear him :doge:
Link to comment
Share on other sites

2 hours ago, Axldeth said:

nice man i will like to test it

Go for it. I didnt add any graphics yet but lmk how it goes

 

2 hours ago, liverare said:
  • Remove onExit and onPaint if you're not using them.
  • Remove anti-ban stuff because it's fairly redundant (unless it's there to avoid logging out).
  • Rework your autocast method so that you pass in the spell you want to select as a parameter. This would halve that block of code easily.
  • I'd caution against using state-based scripts because they can be very limiting and inefficient if improperly used (e.g. if you're searching for an NPC twice).

 

Also, when handling weapon/armour, you should (ideally) only do this once. I would suggest making it so your onLoop function does this check and action once, then when you're certain you're ready, you simply switch a boolean flag and it's never checked again:

  Reveal hidden contents

 



	boolean ready = false;
	
	@Override
    public int onLoop() throws InterruptedException {
		
		if (client.isLoggedIn()) { // make sure we are logged in
			
			if (ready) { // assume we're good to go
				
				// botty stuffs here
				
			} else { // do your equipment checking/withdrawing/etc. here
				
				if (isReady()) { // let's check to see if we're good to go
					
					ready = true; // set this flag to 'true' so we never re-check anything again
				}
			}
		}
	}

 

 

 

 

 

Your code is looking good - keep it up!

Thanks. I wil work on the changes. What would u suggest other than the getstate method

 

1 hour ago, FuryShark said:

Just a btw, other players cats can attack your rats

I didnt test for that but i was hoping the script would attack another rat ?

Link to comment
Share on other sites

1 minute ago, Malcolm_OS said:

 

Naw hes serious.

I would just do either chickens or spiders man.

Although if you really wanted it to be rats you could just put something in checking if you're in combat


if (myPlayer().isUnderAttack()) {

//sleep

} else {

//attack rat

}

 

Bro what i wrote wasnt even Java l0l.

Unless he didnt mean it litterally

Link to comment
Share on other sites

1 hour ago, Halicarnassus said:

Bro what i wrote wasnt even Java l0l.

Unless he didnt mean it litterally

I meant the feature to hop worlds. Unless ur talking about the cat attacking the rat. Im thinking the cat would eat the rat and then after my sleep it would return state.attack again. If not please explain where its messed up or what i gotta add

Also not sure if litterally was meant as a pun but if it was i caught it 

Edited by donaldchen34
Link to comment
Share on other sites

3 hours ago, Malcolm_OS said:

    @Override
    public int onLoop() throws InterruptedException {

        if (!WeHaveOurShit) {
            if (Banks.LUMBRIDGE_UPPER.contains(myPlayer())) {
                if (getBank().isOpen()) {
                    WithdrawOurShit();
                } else {
                    getBank().open();
                    new ConditionalSleep(2000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return getBank().isOpen();
                        }
                    }.sleep();
                }
            } else {
                getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
            }
        } else {
            if (!ourShitIsEqupped) {
                equipOurShit();
            } else {
                if (!new Area(1111, 1111, 1111, 1111).contains(myPlayer())) {
                    getWalking().webWalk(new Area(1111, 1111, 1111, 1111));
                } else {
                    if (myPlayer().isUnderAttack()) {
                        sleep(random(500, 1000));
                    } else {
                        NPC rat = npcs.closest("Rat");
                        rat.interact("Attack");
                        new ConditionalSleep(2000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return myPlayer().isUnderAttack();
                            }
                        }.sleep();
                    }
                }
            }
        }

        return 1000;
    }

why make a simple splashing script soo complicated? 

 

NOTE: Add the check for hopping worlds somewhere logical

I'd also add something for selecting the proper spell etc etc

 

I wrote this real quick so didn't do everything

HUH

that does look alot simpler

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...