Jump to content

I need to know some things


Jonasstams

Recommended Posts

 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

Link to comment
Share on other sites

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
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...