Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • erroneous tiles?


    Zuul

    Recommended Posts

    When i want to record a path, i use this code: (some code found from the net)

    Tile currentPosition = getLocalPlayer().getTile();
            if (currentPosition.distance(lastTile) > 1.9) {
                walkTiles.add(currentPosition);
                lastTile = currentPosition;
            }

    the recorded tiles are in a list, and this is how i save it to a file:  (some code found from the net)

    String str = "\nTile[] path = {";
     for (int i=0; i < walkTiles.size(); i++) {
      Tile p = walkTiles.get(i);
      if (i == walkTiles.size() - 1) {
        str += String.format("new Tile(%d, %d, %d)};", p.getX(), p.getY(), p.getZ());
       }
       else {
        str += String.format("new Tile(%d, %d, %d), ", p.getX(), p.getY(), p.getZ());
       }
      }
      try {
    	saveFileText(str);
      } catch (FileNotFoundException e) {
       //do stuff
      }

    Theres nothing wrong with the code, but

    I get erroneous tiles in the list, which seems to occur when a new region is loaded... That is, a new part of the map is loaded.

    spacer.png

    Any ides how to avoid this?

     

    Spoiler
    package org.zuul.simple.utilities;
    
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.concurrent.ThreadLocalRandom;
    
    import org.dreambot.api.methods.map.Map;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.listener.ChatListener;
    import org.dreambot.api.wrappers.widgets.message.Message;
    
    @ScriptManifest(author = "Zuul", name = "Paths", version = 1.0, description = "Path Recorder", category = Category.UTILITY, image = "")
    public final class ZuulPathRecorder extends AbstractScript implements ChatListener {
    
        private final RenderingHints antialiasing = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
    
        private final Font infoFont = new Font("Monospaced", 0, 12);
    
        private java.util.List<Tile> walkTiles;
        private Tile lastTile;
        
        @Override
        public void onStart() {
            walkTiles = new ArrayList<Tile>();
            lastTile = getLocalPlayer().getTile();
            walkTiles.add(lastTile);
        }
    
        @Override
        public int onLoop() {
            Tile currentPosition = getLocalPlayer().getTile();
            if (currentPosition.distance(lastTile) > 1.9) {
             walkTiles.add(currentPosition);
             lastTile = currentPosition;
            }
            sleep(ThreadLocalRandom.current().nextInt(10, 20));
            return 0;
        }
    
    
        @Override
        public void onExit() {
            String str = "\nTile[] path = {";
            for (int i=0; i < walkTiles.size(); i++) {
             Tile p = walkTiles.get(i);
             if (i == walkTiles.size() - 1) {
              str += String.format("new Tile(%d, %d, %d)};", p.getX(), p.getY(), p.getZ());
             }
             else {
              str += String.format("new Tile(%d, %d, %d), ", p.getX(), p.getY(), p.getZ());
             }
            }
            try {
             saveFileText(str);
            } catch (FileNotFoundException e) {
             //
            }
        }
    
        @Override
        public void onGameMessage(Message message) {
        }
    
        @Override
        public void onPaint(Graphics2D g) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHints(antialiasing);
            g2.setFont(infoFont);
            g.setColor(Color.YELLOW);
            if (!walkTiles.isEmpty()) {
             for (Tile t : walkTiles) {
              if ( Map.isTileOnScreen(t) ) {
               g2.drawPolygon(t.getPolygon());
               g2.drawString(String.format("%d, %d, %d", t.getX(), t.getY(), t.getZ()),
               (int) t.getPolygon().getBounds().getCenterX(), (int) t.getPolygon().getBounds().getCenterY());
              }
             }
            }
        }
    
        public void saveFileText(String str) throws FileNotFoundException {
            PrintWriter out = new PrintWriter(getManifest().name() + "_" + System.currentTimeMillis() + ".txt");
            out.println("");
            out.println(str);
            out.close();
        }
    }

     

     

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.