Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Some basic questions, help very much appreciated!


    Nosta

    Recommended Posts

    Hey guys! Nice to meet you, I'm new to coding.
    I followed a guide on how to make a bot using Dreambot and I've got some questions regarding an error that I got:
     

    Spoiler
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.methods.tabs.Tab;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.NPC;
    
    @ScriptManifest(author = "Nosta", description = "NostaBotDesc", name = "NostaBot", category = Category.MAGIC, version = 1.14)
    
    //This is my "main"
    public class NostaBot extends AbstractScript {
    	
    	State state;
    	NPC npc;
    	
    	Area lumbySpawn = new Area(new Tile(3226, 3213) , new Tile(3217, 3224));
    	Area ratArea = new Area(new Tile(3199, 3199) , new Tile (3191, 3211));
    	
    	Tile[] pathToRats = {new Tile (3211, 3210), new Tile (3202, 3217), new Tile (3197, 3201)};
    	
    	@Override //Infinite loop
    	public int onLoop() {
    		
    		//Determined by which state gets returned by getState() then do that case.
    		switch(getState()) {
    		case WALKINGTORATS:
    			log("Walking to Rats");
    			
    			if(!getTabs().isOpen(Tab.INVENTORY)) {
    				getTabs().open(Tab.INVENTORY);
    			}
    			
    			if(getTabs().isOpen(Tab.INVENTORY)) {
    				if(getInventory().contains("Wooden shield")) {
    					getInventory().interact("Wooden shield", "Wield");
    					sleep(randomNum(1000, 500));
    					getInventory().interact("Bronze sword", "Wield");
    					sleep(randomNum(1000, 500));
    				}
    			}
    			
    			//TO-DO: Make the bot have maximum 5 walking attempts before assigning a new tile to walk on before re-trying.
    			for(int i = 0; i < pathToRats.length; i++) {
    				while (!getLocalPlayer().getTile().equals(pathToRats[i])) {
    					if(!getLocalPlayer().isMoving()) {
    						getWalking().walk(pathToRats[i]);
    						sleep(randomNum(1000, 2000));
    					}
    				}
    			}
    			
    			
    			break;
    		
    		case LOOKING4RATS:
    			log("Looking for rats");
    			npc = getNpcs().closest(rat -> rat != null && rat.getName().equals("Giant rat") && !rat.isInCombat() && ratArea.contains(rat));
    			if(npc != null) {
    				if(!npc.isOnScreen()) {
    					getCamera().keyboardRotateToEntity(npc);
    					sleep(randomNum(500, 1000));
    				}
    				
    				npc.interact("Attack");
    				sleep(randomNum(1000, 2000));
    			}
    			
    			
    			break;
    		
    		case FIGHTING:
    			sleep(randomNum(500, 1000));
    			log("Fighting rat");
    			if(npc != null) {
    				if(!npc.exists() || npc.getHealthPercent() == 0) {
    					npc = null;
    				}
    			}
    			
    			
    			break;
    		default: log("an error has occurred");	
    		}
    		return 0;
    	}
    	
    	//State names
    	private enum State {
    		FIGHTING, WALKINGTORATS, LOOKING4RATS, BREAK
    	}
    	
    	//Checks if a certain condition is met, then return that state.
    	private State getState() {
    		if(lumbySpawn.contains(getLocalPlayer())) {
    			state = State.WALKINGTORATS;
    		}else if(ratArea.contains(getLocalPlayer()) && !getLocalPlayer().isInCombat()) {
    			state = State.LOOKING4RATS;
    		}else if(ratArea.contains(getLocalPlayer()) && getLocalPlayer().isInCombat()) {
    			state = State.FIGHTING;
    		}
    		return state;
    	}
    	
    	//When script start load this.
    	public void onStart() {
    		log("Bot Started");
    	}
    	
    	//When script ends do this.
    	public void onExit() {
    		log("Bot Ended");
    	}
    	
    	public int randomNum(int i, int k) {
    		int num = (int)(Math.random() * (k - i + 1)) + i;
    		return num;
    	}
    }

    getTabs and getInventory throws me: "The static method isOpen(Tab) from the type Tabs should be accessed in a static way"

    getWalking, getNpcs and getCamera throws me: "The method getWalking() from the type MethodContext is deprecated"

    The code runs fine, but I'm stuck wondering if I did something wrong to get these two errors, and how to correct them.
    I'm very thankful for any help on the subject, I've also attatched my code in case you have some constructive feedback as well, I always appreciate it.

    I'd like to wish you a great day :)
    ~Nosta


     


     

     

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.