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

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

  1. 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. Will be very useful while we implement randoms :)
     

Share This Page

Loading...