Guest User

Untitled

a guest
Apr 8th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. package Base;
  2. //HA ITS UPPERCASE B YOU SCRUBS
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import org.osbot.script.Script;
  8. import org.osbot.script.rs2.model.RS2Object;
  9.  
  10. public class MainScript extends Script {
  11.  
  12.     public enum State{
  13.        
  14.         IDLE,OBSERVE,GO_TO_AREA,CLICK_ON_RESOURCE,WAIT_FOR_RESOURCE,QUEUE_NEXT_ACTION,DROP_ITEMS;
  15.        
  16.     }
  17.    
  18.     State sState = State.IDLE;
  19.    
  20.     public void onStart(){
  21.        
  22.     }
  23.    
  24.     public void preExecution(){
  25.        
  26.         if(this.client.getInventory().getFullSlots() == 28){
  27.             sState = State.DROP_ITEMS;
  28.         }
  29.        
  30.         if(sState.equals(State.IDLE)){
  31.            
  32.             if(myPlayer().isInArea(null)){
  33.                 //Main area replace null with an area object
  34.                 sState = State.OBSERVE;
  35.             }else{
  36.                 sState = State.GO_TO_AREA;
  37.             }
  38.            
  39.         }
  40.        
  41.     }
  42.    
  43.     @Override
  44.     public int onLoop(){
  45.        
  46.         runStates();
  47.        
  48.        
  49.        
  50.         return 0;      
  51.     }
  52.  
  53.     Random r = new Random();
  54.     Timer pauser = new Timer(0);
  55.     RS2Object myTargetObject = null;
  56.     private void runStates() {
  57.        
  58.         String targetName = "Tree/Vein/FishSpot";
  59.        
  60.         switch(sState){
  61.         case OBSERVE:
  62.            
  63.         List<RS2Object> targets = closestObjectListForName(targetName);
  64.         int distance = 20;
  65.         RS2Object fillTarget = null;
  66.         int targetDistance = 0;
  67.        
  68.         for(int i = 0; i < targets.size(); i++){
  69.            
  70.             fillTarget = targets.get(i);
  71.             targetDistance = fillTarget.getPosition().distance(myPosition());
  72.            
  73.             if(targetDistance < distance){
  74.                 myTargetObject = fillTarget;
  75.             }
  76.            
  77.         }
  78.        
  79.         if(fillTarget != null && !myPlayer().isAnimating() && !myPlayer().isMoving()){
  80.             sState = State.CLICK_ON_RESOURCE;
  81.             //If you haven't figured this state case out
  82.             //we're just searching for the closest object.
  83.             //you can do this many ways for the next step.
  84.             //Either make a method that returns the state
  85.             //and pass it through here, make a boolean
  86.             //and if it becomes true, push to the next desired state.
  87.             //you can do MANY MANY things with this. Even surpass premium
  88.             //script capability with this, but since most of them are lame
  89.             //scrubs in the first place, we don't have to worry about that.
  90.             //it's all you here. No offense. Imagination is key.
  91.         }  
  92.             break;
  93.         case CLICK_ON_RESOURCE:
  94.            
  95.             //So here we have to verify if the object exists and then click on it.
  96.             if(myTargetObject != null && myTargetObject.exists()){
  97.                 interactWithObject();
  98.                 sState = State.WAIT_FOR_RESOURCE;
  99.             }else{
  100.                 sState = State.OBSERVE;
  101.                
  102.             }
  103.            
  104.             break;
  105.            
  106.            
  107.         case WAIT_FOR_RESOURCE:
  108.            
  109.             if(myInventoryCountChanged() || objectIsGone()){
  110.                
  111.                     sState = State.OBSERVE;
  112.                
  113.             }else{
  114.            
  115.                 if(myPlayer().isAnimating()){
  116.                     sState = State.QUEUE_NEXT_ACTION;
  117.                 }
  118.                
  119.             }
  120.            
  121.             break;
  122. //That's all i really care to share atm. But as you can see, if you are
  123.             //specific in the switching of states, you can chain many together
  124.             //to do sequentially performed checks.
  125.         case DROP_ITEMS:
  126.             break;
  127.         case GO_TO_AREA:
  128.             break;
  129.         case QUEUE_NEXT_ACTION:
  130.             break;
  131.  
  132.  
  133.        
  134.         }
  135.        
  136.     }
  137.    
  138.     public void interactWithObject(){
  139.        
  140.     }
  141.    
  142.     public boolean myInventoryCountChanged(){
  143.         return false;
  144.     }
  145.    
  146.     public boolean objectIsGone(){
  147.         return false;
  148.     }
  149.    
  150. }
Advertisement
Add Comment
Please, Sign In to add comment