Jump to content

Woody

Members
  • Posts

    715
  • Joined

  • Last visited

  • Feedback

    100%

Posts posted by Woody

  1. Well I don't think military is stupid...Want to have russia walk into your country and tell you to gtfo, cause thats what would happen without military.I don't want to go there for 9 months but I'll just do it like a man is supposed to.

    Russia can do it even if Lithuania have an army

  2. You are saving the flags of the tiles.

    Not even the tile itself...

     

    This adds a flag of a tile to the list.

    walkableTiles.add(map[x][y])
    

    basicly pointless, since you don't even know which tile it is afterwards.

     

    You want to save the tiles itself.

    ArrayList<Position> walkableTiles = new ArrayList<Position>();

    Try to figure out how to get the global x and y yourself out of the locals x and y wink.png

     

    Khaleesi

    Lol, shame on me... 

     

    So with map[x][y] I can find the flag's tile? 

  3. Here:

    static final int UNWALKABLE = 256 | 0x200000 | 0x40000;
    
    public static boolean isWalkable(int flag) {
       return (flag & (UNWALKABLE)) == 0;
    }
    
    XClippingPlane[] clippingPlanes = script.client.accessor.getClippingPlanes();
    int[][] map = clippingPlanes[script.myPlayer().getZ()].getTileFlags();
    
    for(int i = 0; i < map.length;i++){
       for(int j = 0; j < map[i].length; j++){
          if(isWalkable(map[i][j]))
             //store in list?
       }
    }
    

    Could be typos in it, typed quickly in here.

    That's what you wanted to do right?

     

    Khaleesi

    This is what I have

    ArrayList<Integer> walkableTiles = new ArrayList<Integer>();
    
    @Override
    	public int onLoop() throws InterruptedException {
    
    		XClippingPlane[] planes = map.getRegion().getClippingPlanes();
    		int[][] map = planes[myPlayer().getZ()].getTileFlags();
    
    		for(int x = 0; x < map.length; x++) {
    			for(int y = 0; y < map[x].length; y++) {
    				if(isWalkable(map[x][y])) {
    					walkableTiles.add(map[x][y]);
    				}
    			}
    		}
    		return 5000;
    	}
    
    public void onExit() {
    		try {
    			BufferedWriter writer = new BufferedWriter ( new FileWriter(".\\positions.txt"));
    
    			for(int i = 0; i < walkableTiles.size(); i++) {
    				writer.write(""+walkableTiles.get(i));
    				writer.newLine();
    			}
    
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    

    When I look at the text file, there are mostly zeros and some other values that doesn't look like tile positions...

    3c25ae0384b21f3a1ca14b53e9cbb967.png

     

    I've tested some other methods and experimented with it, but I get the same all the time. What's wrong?

  4. Here:

    static final int UNWALKABLE = 256 | 0x200000 | 0x40000;
    
    public static boolean isWalkable(int flag) {
       return (flag & (UNWALKABLE)) == 0;
    }
    
    XClippingPlane[] clippingPlanes = script.client.accessor.getClippingPlanes();
    int[][] map = clippingPlanes[script.myPlayer().getZ()].getTileFlags();
    
    for(int i = 0; i < map.length;i++){
       for(int j = 0; j < map[i].length; j++){
          if(isWalkable(map[i][j]))
             //store in list?
       }
    }
    

    Could be typos in it, typed quickly in here.

    That's what you wanted to do right?

     

    Khaleesi

    Oh yea.. Now I get it. Thank you!

    • Like 1
  5. Here:

    static final int UNWALKABLE = 256 | 0x200000 | 0x40000;
    
    public static boolean isWalkable(int flag) {
       return (flag & (UNWALKABLE)) == 0;
    }
    
    XClippingPlane[] clippingPlanes = script.client.accessor.getClippingPlanes();
    int[][] map = clippingPlanes[script.myPlayer().getZ()].getTileFlags();
    

    Now just loop through all tiles and check them smile.png

     

    Khaleesi

    I might be dumb, but what do you mean with "just loop through all tiles and check them"  

  6. It will be if you are making a web.

    Consider a tile that contains a door. When that door is closed, the tile is not walkable. That means that using clipping flags, you will see that tile as non walkable.

     

    You could argue that you can check objects on the tile, see if they are something that can be overcome, and yes you could do that.

     

    But objects such as doors, gates, etc. are not the only things that behave in that way.

    Flags are a bit wonky. I suggest just using clipping flags to paint the different tiles values/type and you can see for yourself how clipping behaves.

    I see your point.

     

    As for the painting, how do you paint nodes and print the world map, like this:

    5d1a3da966218ed42f52d834e2fe9b8a.png

  7. You can get a 2d array of tile flags by

     

    XClippingPlane[] planes = getMap().getRegion().getClippingPlanes();

    each plane has a getTileFlags() getter for the int[][] array of flags (index by local coordinates).

     

    I'm not sure what the flag values are, but it should be fairly simple to debug

    For now I just need walkable tiles on plane 0 (surface). 

     

    So planes will contain both x and y value?

     

    If I was to use getRegion().getTiles(), would it return non walkable tiles aswell?

    You can do this but it wont be totally accurate.

    Some tiles will say they are not walkable when they actually are, because some of the flags are shared on walkable tiles and non walkable tiles.

    (If I remember correctly)

     

    It will almost work, but you will end up missing some tiles ultimately.

    Well, as for trying this for the first time, missing some tiles will not be a big issue.

  8. Nice, I'm sure it will help out quite a few people.

     

    Here's some advice to hopefully improve the readability (and managability) of your code:

     

    No need to check if entity != null twice (if statement and else if statement). Simply do

    if(entity != null) {
        if(menu.isOpen()) {
    
        } else {
    
        }
    }

    You have quite a few un-needed return statements. Rather than calling return when options == null, format your code to allow the flow of execution "do nothing" until the return statement at the bottom:

    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;
    }

    As you can tell, I also fixed up the wierd scoping. If you ever find yourself declaring the tracker variable for a for loop outside of the loop, best believe you have a structuring problem. You were breaking from the loop, just to have another block of code (which depends on the tracker variable; the whole reason you have the for loop) return from the entire method. I would recommend the Stream API to decrease the amount of time it takes to iterate through a collection, as Alek suggested, but it might interfere with how you're specifying your mouse location.

     

    Still quite a bit of cognition needed to understand the method. We can lower it through decomposition:

    private boolean hoverOverEntityOption(Entity entity, String option) throws InterruptedException {
        if(entity == null)
            return false;
    
        if(menu.isOpen())
            return moveMouse(option);
        else
            clickEntity(entity);
    
        return false;
    }
    private boolean moveMouse(String option) {
        List<Option> options = menu.getMenu();
    
        if(options != 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);
                        }
               }
    }
    private void clickEntity(Entity entity) {
        EntityDestination ed = new EntityDestination(getBot(), entity);
        mouse.click(ed, true);
    }

    Keep up the good work man smile.png

    Is it worth using Stream API in this method? This method is not so much timeconsuming and it goes pretty fast. But there are maybe some other pros with Stream API which I am not aware of.

     

    Other than that, I really appreciate your help!

  9.  

    While loops are sexy and more readable.

    //#EYECANCER
    for(;;) {
    if(!condition) break;
    doSomething();
    }
    
    //#EYECANDY
    while(condition) {
    ​doSomething();
    ​}
    

    Me != you. 

     

    Jokes. I understand you. :)

    • Like 1
  10. This is a good start and it shows that you know a bit more about scripting than your average Joe, but here are a few suggestions:

     

    1. Try out the new Stream API available in Java 8.

    2. Try using events for their intended function. Event e = new Event(), execute(e), e.hasFailed(), e.hasFinished().

     

    Remember that all friendly API methods fall back on events. Mouse.click will fall back on both MoveMouseEvent and ClickMouseEvent. You should look up these events to see how you can fine-tune your own methods.

    Will do! Thank you!

    for(; index < options.size(); index++)
    

    while loop pls sad.png

     

    The difference?

  11. good idea, can even be useful for other skills such as agility 

    Yes of course. I am using it in my ardy rooftop script to hover next object while performing an animation for faster interaction.

    Nice snippet smile.png

    For moving the mouse inside the rect you might wanna use

     

    MouseEvent me = new MoveMouseEvent(new RectangleDestination(bot, menu.getOptionRectangle(idx)));
    

    that's what Menu#selectAction does (EDIT: might be better considering the upcoming resizable stuff happy.png )

    What are the pros with using MouseEvent?

  12. Using this for Woody's Fighter to attack next monster faster.

             /**
    	 * @author Woody
    	 * @param entity - The entity which has the chosen option
    	 * @param option - The option you want to hover
    	 * @return true if hovering over entity option
    	 * @throws InterruptedException
    	 */
    	private boolean hoverEntityOption(Entity entity, String option) throws InterruptedException {
    		if(entity != null && menu.isOpen()) {
    			List<Option> options = menu.getMenu();
    			Rectangle optionRec = null;
    			int index = 0;
    			if(options != null) { 
    				for(; index < options.size(); index++) {
    					if(options.get(index).action.equals(option)) {
    						optionRec = menu.getOptionRectangle(index);
    						break;
    					}
    				}
    			} else {
    				return false;
    			}
    			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 {
    				return false;
    			}
    		} else if(entity != null && !menu.isOpen()) {
    			EntityDestination ed = new EntityDestination(bot, entity);
    			mouse.click(ed, true);
    		}
    		return false;
    	}
    

    How to use:

    if(myPlayer().getInteracting() != null) {
       NPC goblin = npcs.closest("Goblin");
    	if(goblin != null && goblin.isVisible()) {
    		if(hoverEntityOption(goblin, "Attack")) {
    			//the mouse is now hovering attack option and is ready to attack next goblin, when the                          
                            //fight is over
    	        }
    	}
    } else {
    	if(menu.isOpen()) {
    		if(mouse.click(false)) {
    			for(int i = 0; i < 100 && !myPlayer().isUnderAttack(); i++) {
    				sleep(20, 40);
    			}
    		}
    	} else {
    		if(goblin != null && goblin.isVisible()) {
    			if(goblin.interact("Attack ")) {
    				for(int i = 0; i < 100 && !myPlayer().isUnderAttack(); i++) {
    					sleep(20, 40);
    				}
    			}
    		} else if(goblin != null && !goblin.isVisible()) {
    					camera.toEntity(goblin);
    		} else {
    		        log("Goblin gone?!");
    		}
    	}
    }
    

    Any suggestions/ideas/complains are appreciated.

    • Like 1
  13. Try using widgets. Otherwise you could open menu and use menu.getMenu(). You'll get all menu options stored in a list. Thereafter you could loop through the list and find the menu action you are looking for.

     

    EDIT: You could also use EntityDefinition

    RS2Object stall = objects.closest("Silk stall");
    
    String[] actions = stall.getDefinition().getActions();
    
  14. You could also just go the easy way out as a starter --> add a sleep timer --> sleep(random(300,1200); between every interaction

    Never do this. 

     

    What if it is lagging? This will just fuck things up. Do like the other guys said, a custom method.

    • Like 1
  15. NPC monster = npcs.closest(monsterID);
    
    if(monster != null) { 
       if(monster.isInteracting(myPlayer()) {
          //monster is interacting with my player
       }
    }
    

    OR

    NPC monster = npcs.closest(monsterID);
    
    if(monster != null) {
      if(myPlayer().isInteracting(monster)) {
         // my player is interacting with monster
      }
    }
    
×
×
  • Create New...