1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resource [Snippet] Some useful little snippets (random event related)

Discussion in 'Tutorials & Resources' started by Salvation, Mar 30, 2014.

  1. Salvation

    Salvation First Bot Author

    Joined:
    Aug 7, 2013
    Messages:
    262
    Likes Received:
    68
    Shut down your script bot when a random event teleports you to a random location:
    Code (Text):
    1.  
    2. //Declare this field anywhere in your class
    3.     private Coordinate lastPosition;
    4.  
    5. //Create this method anywhere in your class
    6.     private void teleportCheck() {
    7.         final Player player = Players.getLocal();
    8.         final Coordinate currentPosition = player != null ? player.getPosition() : null;
    9.      
    10.         if (currentPosition != null) {
    11.             if (lastPosition == null) {
    12.                 lastPosition = currentPosition;
    13.             } else if (lastPosition.distanceTo(currentPosition) > 50) {
    14.                 Game.logout(true);
    15.                 stop();
    16.             } else {
    17.                 lastPosition = currentPosition;
    18.             }
    19.         }
    20.     }
    21.  
    22. //Paste this at the top of your onLoop:
    23.         teleportCheck();
    24.  
     
    #1 Salvation, Mar 30, 2014
    Last edited: Mar 30, 2014
    Viewer likes this.
  2. Viewer

    Viewer Discretion is advised

    Joined:
    Jan 2, 2014
    Messages:
    306
    Likes Received:
    77
    Will be very useful while we implement randoms :)
     

Share This Page

Loading...