Jump to content

I need to know some things


Recommended Posts

Posted

 Hey guys,

I'm making my first script and I have a question:
 
  - How can I select something like a chair after it clicks on build chairspace (picture 1)

 

this is my code:

 

 

package core;

 
import nodes.TabMaking;
import nodes.Unnoting;
 
import org.osbot.rs07.api.Mouse;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Option;
import org.osbot.rs07.input.mouse.ClickMouseEvent;
import org.osbot.rs07.input.mouse.EntityDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
import utils.Walking;
 
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
@ScriptManifest(name = "JonesConstruction", author = "Jones", version = 0.1, info = "Construction Script made by Jones", logo = "")
public class JonesConstruction extends Script {
private String status = "";
 
 
@Override
public void onStart() {
 
 
}
 
private enum State {
GOING_OUTSIDE,GOING_INSIDE, SEARCHING_CHAIR, MAKING_CHAIRS, UNNOTING, WAITING
};
 
private State getState() {
Entity portal = objects.closest("Portal");
if (inventory.contains(960)) {
if (myPlayer().getX() > 12000) {
if(myPlayer().isAnimating()){
return State.MAKING_CHAIRS;
}else{ return State.SEARCHING_CHAIR;}
 
}else{
return State.GOING_INSIDE;
}else{
if(myPlayer().getX() > 12000) {
return State.GOING_OUTSIDE;
}else{
return State.UNNOTING;
}
}
 
 
 
}
 
@Override
public int onLoop() throws InterruptedException {
switch(getState()){
case GOING_INSIDE:
log("Searching for portal");
Entity portal = objects.closest("Portal");
if(portal != null ){
portal.interact("Enter");
sleep(random(1000,1250));
keyboard.typeString("2");
sleep(random(1000,1500));
}
break;
 
case SEARCHING_CHAIR:
log("Searching for Chair space");
Entity chairSpace = objects.closest(4517);
 
while(!inventory.isEmptyExcept(961, 995, 4820, 8794,2347)){
if(chairSpace != null){
chairSpace.interact("Build");
Entity rockingChair = objects.closest("Rocking chair");
rockingChair.interact("Build");
Entity chair = objects.closest("Chair");
chair.interact("Remove");
keyboard.typeString("1");
}
}
break;
case GOING_OUTSIDE:
log("Searching for portal");
portal = objects.closest("Portal");
portal.interact("Enter");
break;
case UNNOTING:
inventory.interact(961,"Use");
if(inventory.isItemSelected()){
NPC Phials = npcs.closest(1614);
keyboard.typeString("3");
}
break;
default:
break;
}
return random(200,300);
 
}
 
private boolean hoverEntityOption(Entity entity, String option) throws InterruptedException {
   if(entity == null)
       return false;
 
   if(menu.isOpen()) {
       List<Option> options = menu.getMenu();
 
       if(options != null) {
           Rectangle optionRec = null;
    
           for(int index = 0; index < options.size(); index++) {
               if(options.get(index).action.equals(option)) {
                   optionRec = menu.getOptionRectangle(index);
 
                   if(optionRec != null) {
                       if(!optionRec.contains(mouse.getPosition())) {
                           int x = menu.getX() + Script.random(10, 160);
                           int y = menu.getY() + 23 + index * 15;
                           Script.sleep(Script.random(200, 400));
                           return mouse.move(x, y);
                       }
                   }
               }
           }
       }
   } else {
       EntityDestination ed = new EntityDestination(bot, entity);
       mouse.click(ed, true);
   }
 
   return false;
}
}
 

 

I hope some people can help me and give me some tips on how to program better. 

THANKS A LOT!

post-167351-0-08199800-1436826015_thumb.png

Posted
RS2Widget w = widgets.get(int parent id, int child id); //parennt and child ids can be found using widget debugger in settings tab
if (w != null && w.isVisible())
    w.interact("Build"); //or whatever the action is

PS in future, post code using the code button not the quote button smile.png

 

apa

 

or just force left click with

 w.interact();
  • Like 1

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
  • Recently Browsing   0 members

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