Jump to content

Need some Advice/help


hellkeepers

Recommended Posts

Hello osbot community, I've recently made an attempt at creating a script for osbot but i've had some problems;

 

Im trying to recreate a thieving script (Master farmer) But im having some issues with using food

 

>It detects if my hp is below 45%

>eats one piece of food

**Starts dropping all items while inventory isn't full**

 

I just need some advice on how to write it the good way im still in the proccess of learning so any piece of information is welcome.

 

**Also what i noticed that npcs.getclosest Laggs extremely badd is there a way arround that?

**And how should i improve the Npc clicking /timing?

///////////////////////////////////////
	   private enum State {
			STEAL,
			DROP,
			EAT,
			IDLE
		};
		
		///////////////////////////////

		private State getState() {
			if(myPlayer().getHealth() <45){
				return State.EAT;
			}
	        if (inventory.isFull())
	            return State.DROP;
			return State.STEAL; 
		}
		
	////////////////////////////////////
		
    @Override
    public void onStart() {
        log("Let's thief!");
    }
    
////////////////////////////////////////////////////
 		
    @Override
	public int onLoop() throws InterruptedException {
        switch (getState()) {
            case STEAL:
                if (!myPlayer().isAnimating()) {
                	NPC farm = npcs.closest("Master farmer");
                    if(farm != null){
                        farm.interact("pickpocket");
                    }
                    
                }
                break;
            case EAT:
            	if(inventory.contains("Pike")){
            		inventory.getItem("Pike").interact("Eat");
            	}        
            	case DROP:
                    inventory.dropAll();
                    break;
            	case IDLE:
            		sleep(200);
            		break;
            		default:
            			break;
    	}
        return random(200, 300);
    }
 
    ////////////////////////////////////////////
    @Override
    public void onExit() {
        log("Thanks for running my script.");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}
Edited by hellkeepers
Link to comment
Share on other sites

problem is ;  It does eats, But after that it starts dropping all items from my invent.

That's because you don't have a break; statement after the end of the EAT state so your program is falling through into the DROP state.

 

Fix:

  case EAT:
    if(inventory.contains("Pike")){
      inventory.getItem("Pike").interact("Eat");
    }
    break;  

  • Like 1
Link to comment
Share on other sites

Hello osbot community, I've recently made an attempt at creating a script for osbot but i've had some problems;

 

Im trying to recreate a thieving script (Master farmer) But im having some issues with using food

 

>It detects if my hp is below 45%

>eats one piece of food

**Starts dropping all items while inventory isn't full**

 

I just need some advice on how to write it the good way im still in the proccess of learning so any piece of information is welcome.

 

**Also what i noticed that npcs.getclosest Laggs extremely badd is there a way arround that?

**And how should i improve the Npc clicking /timing?

*CODE*

Another point of interest is the break statement. Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block. The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered. The program SwitchDemoFallThrough shows statements in a switch block that fall through. The program displays the month corresponding to the integer month and the months that follow in the year:

public class SwitchDemoFallThrough {

public static void main(String[] args) {

java.util.ArrayList<String> futureMonths =

new java.util.ArrayList<String>();

int month = 8;

switch (month) {

case 1: futureMonths.add("January");

case 2: futureMonths.add("February");

case 3: futureMonths.add("March");

case 4: futureMonths.add("April");

case 5: futureMonths.add("May");

case 6: futureMonths.add("June");

case 7: futureMonths.add("July");

case 8: futureMonths.add("August");

case 9: futureMonths.add("September");

case 10: futureMonths.add("October");

case 11: futureMonths.add("November");

case 12: futureMonths.add("December");

break;

default: break;

}

if (futureMonths.isEmpty()) {

System.out.println("Invalid month number");

} else {

for (String monthName : futureMonths) {

System.out.println(monthName);

}

}

}

}

For more, see https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Edited by dog_
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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