Jump to content
  • 0
lickanart

Help with getClosest(npc id) error

Question

Im getting this error in my command prompt then script stops. 

code is:

public void execute(){
    Npc seatroll = Npcs.getClosest(3847); // 10070 shadow king 3847 sea troll king
    if(seatroll != null){
        seatroll.interact(1);
        Time.sleep(2000);
        Time.sleep(new SleepCondition(){
            public boolean isValid() {
                return Players.getMyPlayer().isInCombat();
            }
        }, 3215);
    }
}

errors.png

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 1
9 hours ago, lickanart said:

Im getting this error in my command prompt then script stops. 

code is:

public void execute(){
    Npc seatroll = Npcs.getClosest(3847); // 10070 shadow king 3847 sea troll king
    if(seatroll != null){
        seatroll.interact(1);
        Time.sleep(2000);
        Time.sleep(new SleepCondition(){
            public boolean isValid() {
                return Players.getMyPlayer().isInCombat();
            }
        }, 3215);
    }
}

errors.png

public void execute(){
	try {
		Npc[] seatroll = Npcs.getNearest(3847); // 10070 shadow king 3847 sea troll king
		if(seatroll != null && seatroll.length > 1) {
			seatroll[0].interact(1);
			Time.sleep(new SleepCondition(){ 
            	public boolean isValid() { 
                	return Players.getMyPlayer().isInCombat(); 
                } 
            }, 3215);
		}
	} catch (NullPointerException e) {
		e.printStackTrace();
	}
}

 

Share this post


Link to post
Share on other sites
  • 0
6 hours ago, lickanart said:

Im getting this error in my command prompt then script stops. 

code is:

public void execute(){
    Npc seatroll = Npcs.getClosest(3847); // 10070 shadow king 3847 sea troll king
    if(seatroll != null){
        seatroll.interact(1);
        Time.sleep(2000);
        Time.sleep(new SleepCondition(){
            public boolean isValid() {
                return Players.getMyPlayer().isInCombat();
            }
        }, 3215);
    }
}

errors.png

Use .getNearest

 

Why are you using 2 sleep timers?

 

Time.sleep(2000);
        Time.sleep(new SleepCondition(){
            public boolean isValid() {
                return Players.getMyPlayer().isInCombat();
            }
        }, 3215);

 

 

Edited by cyanic

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×