Jump to content

Where am I wrong?


MySQLi

Recommended Posts

Hey guys, just working on my first script, I've ran into another issue I can't seem to figure out.

Spoiler

 

				
			import org.osbot.rs07.api.model.Entity;
		import org.osbot.rs07.api.model.RS2Object;
		import org.osbot.rs07.script.Script;
		import org.osbot.rs07.script.ScriptManifest;
		import org.osbot.rs07.utility.ConditionalSleep;				
			import java.awt.*;
		 
		@ScriptManifest(author = "MySQLi", info = "Basic Chicken Killer", name = "SqlChickenKiller", version = 1.0, logo = "")
		public class Main extends Script {
		 
		    @Override
		    public void onStart() {
		        log("Script made by MySQLi, Enjoy!");
		        
		    }
		    //What are we going to do in our script
		    private enum State{
		        KILL,WAIT,LOOT
		    };
		    
		    //Declare our conditions
		    private State getState(){
		        Entity chicken = getNpcs().closest("Chicken");
		        if(chicken != null  && chicken.interact("Attack")) {
		            new ConditionalSleep(5000){
		                
		                public boolean condition2(){
		                    return myPlayer().isAnimating() || !chicken.exists();
		                }
		                @Override
		                public boolean condition() throws InterruptedException {
		                    // TODO Auto-generated method stub
		                    return false;
		                }
		            }.sleep();
		        }
		        Entity bones = getGroundItems().closest("Bones");
		        if(bones != null && bones.interact("Take")) {
		            new ConditionalSleep(5000){
		                public boolean condition(){
		                    return myPlayer().isAnimating() || !bones.exists();
		                }
		            }.sleep();
		            Entity feather = getGroundItems().closest("Feather");
		            if(feather != null && feather.interact("Take")) {
		                new ConditionalSleep(5000){
		                    public boolean condition(){
		                    return false;
		                    }
		                }.sleep();
		            }
		            
		        }
		        
		        if (bones != null)
		            return State.LOOT;
		        if (feather != null)
		            return State.LOOT;
		        if(chicken != null)
		            return State.KILL;
		        return State.WAIT;
		    }
		    
		    @Override
		    public int onLoop() throws InterruptedException {
		        switch (getState()){
		        case LOOT:
		            Entity bones = getGroundItems().closest("Bones");
		            Entity feather = getGroundItems().closest("Feather");
		            if(bones != null) {
		                bones.interact("Take");
		                if(feather != null){
		                    feather.interact("Take");
		                }
		            
		            }
		            break;
		        case KILL:
		        Entity chicken = getNpcs().closest("Chicken");
		   
		                if(chicken != null) {
		                    chicken.interact("Attack");
		                }
		                break;
		        case WAIT:
		            sleep(random(500, 700));
		            break;
		                }
		        return random(200, 300);
		    }
		 
		    @Override
		    public void onExit() {
		        log("Thank you, come again!");
		    }
		 
		    @Override
		    public void onPaint(Graphics2D g) {
		 
		    }
		 
		}				
			

Where I'm;

if (feather != null)

return state.LOOT;

 

It's saying feather cannot be resolved to a variable, although I have it declared, can anyone tell me what I did wrong?

Link to comment
Share on other sites

Feather shouldn't be entity. It's a GroundItem. Also, I believe it's "Feathers" not "Feather"

So like this:

GroundItem feather = getGroundItems().closest("Feathers");

 

16 minutes ago, MySQLi said:

Entity chicken = getNpcs().closest("Chicken");

Chicken is an NPC not Entity.

Same goes for bones. It's a GroundItem

Edited by Visty
Link to comment
Share on other sites

7 minutes ago, Visty said:

Feather shouldn't be entity. It's a GroundItem. Also, I believe it's "Feathers" not "Feather"

So like this:


GroundItem feather = getGroundItems().closest("Feathers");

 

Chicken is an NPC not Entity.

I fixed that, but it still doesn't fix my issue, thank you for pointing that out though.

Link to comment
Share on other sites

8 minutes ago, MySQLi said:

I fixed that, but it still doesn't fix my issue, thank you for pointing that out though.

A better way imo to use states, is by creating a method for each state. In your case, make a method like public void Loot() {} //In this method you put everything you need.

Then in your getStates say like if (this & that) { return State.Loot; }

Then in your onLoop say like case LOOT: Loot(); break;

public enum State {
        WALK_TO_OAKS
}

public int onLoop() throws InterruptedException {
        s = getState();

        switch (s) {
			case WALK_TO_OAKS:
                Walk_To_Oak();
                break; 
        }
  
public void Walk_To_Oak() throws InterruptedException {
      paint.status = "Going To Oak Trees...";

      getWalking().walkPath(Arrays.asList(Oak_Path));
}

This is an example in one of my scripts that uses States.

Because tbf, reading that code gives me headaches, I can't see :doge: Because you are simply repeating your States on your onLoop.

Edited by Visty
Link to comment
Share on other sites

2 minutes ago, Visty said:

A better way imo to use states, is by creating a method for each state. In your case, make a method like public void Loot() {} //In this method you put everything you need.

Then in your getStates say like if (this & that) { return State.Loot; }

Then in your onLoop say like case LOOT: Loot(); break;

I just did that, It is working now. I must of had a small error somewhere that I wasn't picking up. Thanks, I appreciate it. When you're implementing sleeps, what time do you usually use? 5000 MS works for me, I one hit chickens, if you figure a level 3 fighting chickens, what do you image a good wait time is? Or is there another check without using waits to just check if the player is currently fighting, or looting?  

Link to comment
Share on other sites

10 minutes ago, MySQLi said:

I just did that, It is working now. I must of had a small error somewhere that I wasn't picking up. Thanks, I appreciate it. When you're implementing sleeps, what time do you usually use? 5000 MS works for me, I one hit chickens, if you figure a level 3 fighting chickens, what do you image a good wait time is? Or is there another check without using waits to just check if the player is currently fighting, or looting?  

I would use a conditionalSleep to check whether my player is under attack. I'm not too familiar with looting tbf, haven't worked with it yet. But I think you can do conditionalSleep then check in the inventory.

Edited by Visty
Link to comment
Share on other sites

25 minutes ago, Visty said:

Feather shouldn't be entity. It's a GroundItem. Also, I believe it's "Feathers" not "Feather"

So like this:


GroundItem feather = getGroundItems().closest("Feathers");

 

Chicken is an NPC not Entity.

Same goes for bones. It's a GroundItem

I'd suggest you read about inheritance and familiarise yourself with the API before you starting throwing claims about what is what.
Both GroundItem and NPC implement Entity.

Link to comment
Share on other sites

31 minutes ago, Adept said:

l0l would you prefer to be corrected or continue living in ignorance?
oh wait, I know the answer
I appreciate it when ppl point out my mistakes. You'll start making mistakes too once you start writing your own code :leech:
:kappa:

Considering actually learning Java as a language is neither my career choice nor something I actually give two shitsticks about, as long as I pull in an income to avoid having to slave while at Uni, ignorance is bliss. :boge:

(Also still awaiting for my own special :spoonfeed: emote :kappa:)

  • Like 1
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...