Advertisement
Guest User

Untitled

a guest
Sep 14th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package com.gmc.actions;
  2.  
  3. import com.gmc.*;
  4.  
  5. import org.osbot.script.rs2.def.*;
  6. import org.osbot.script.rs2.model.*;
  7. import org.osbot.script.rs2.ui.Option;
  8. import org.osbot.script.mouse.*;
  9.  
  10. import java.awt.*;
  11.  
  12. public class UseItemOnObject implements Action {
  13.  
  14.     int dataNum[] = new int[8];
  15.     String dataWord[] = new String[8];
  16.    
  17.     public UseItemOnObject(int dataNum[], String dataWord[]) {
  18.         this.dataNum = dataNum;
  19.         this.dataWord = dataWord;
  20.     }
  21.  
  22.     @Override
  23.     public String getBuildText() {
  24.         return "Use " + new Item(dataNum[0], 1).getDefinition().getName()  + "("  + dataNum[0] + ") on " + ObjectDefinition.forId(dataNum[1]).getName() + "("  + dataNum[1] + ")";
  25.     }
  26.    
  27.     @Override  
  28.     public void executeAction(SuperScript script) throws InterruptedException {
  29.         boolean returns = false;
  30.         RS2Object obj = script.closestObject(dataNum[1]);
  31.         String action = "Use <col=ff9040>" + new Item(dataNum[0], 1).getDefinition().getName() +"<col=ffffff> -> <col=ffff>" + ObjectDefinition.forId(dataNum[1]).getName();
  32.         if(obj != null) {
  33.             script.client.getInventory().interactWithId(dataNum[0], "Use");
  34.             script.sleep(200);
  35.             script.client.moveMouse(obj.getMouseDestination(), true);
  36.             script.sleep(50);
  37.             script.client.clickMouse(true);
  38.             script.sleep(50);
  39.             int i = -1;
  40.             for (int index = 0; index < script.client.getMenuCount(); index++) {
  41.                 String indexaction = ((Option)script.client.getMenu().get(index)).action + " " + ((Option)script.client.getMenu().get(index)).noun;
  42.                 if (indexaction.equals(action)) {
  43.                     i = index;
  44.                     break;
  45.                 }
  46.             }
  47.             if (i == -1) {
  48.                 returns = false;
  49.             }
  50.             Point menu = new Point(script.client.getMenuX(), script.client.getMenuY());
  51.             int xOff = script.random(4, 95);
  52.             int yOff = 21 + 16 * i + 3;
  53.             RectangleDestination rectangle_destination = new RectangleDestination(new Rectangle(menu.x, menu.y + yOff, xOff, 8));
  54.             script.client.moveMouse(rectangle_destination, true);
  55.             if (script.client.isMenuOpen()) {
  56.                 script.client.clickMouse(false);
  57.                 script.sleep(25);
  58.                 returns = true;
  59.             }
  60.             returns = false;   
  61.         } else {
  62.             script.sleep(2000);
  63.             script.log("Cannot find object - " + dataNum[1] + "!");
  64.         }
  65.     }
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement