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

Advice needed on improving some code

Discussion in 'Programming & Hardware' started by tafani, Nov 16, 2016.

  1. tafani

    tafani Banned for Scamming

    Joined:
    May 25, 2016
    Messages:
    352
    Likes Received:
    74
    Alright so What this does is When you are in a certain location it initiates a Timer, & if you aren't in that location the timer is canceled and is removed. I need some advice on how I could improve this.

    Code (Javascript):
    1. package com.rs.game.player.wilderness;
    2.  
    3. import com.rs.game.player.Player;
    4. import com.rs.game.player.controlers.Wilderness;
    5. import com.rs.game.tasks.WorldTask;
    6. import com.rs.game.tasks.WorldTasksManager;
    7.  
    8. /**
    9. *
    10. * @author Tafanii
    11. * Wilderness Time count
    12. * @Sketchy ass timer lmao
    13. *
    14. */
    15. public class Timer {
    16.  
    17.     private Player c;
    18.  
    19.     public Timer(Player c) {
    20.         this.c = c;
    21.     }
    22.  
    23.     public String chat(String text) {
    24.         return text + "";
    25.     }
    26.  
    27.     public void sendTimer() {
    28.         c.cancelTimer = false;
    29.         System.out.println("Timer Initiated - "+c.timeCount);
    30.         c.getPackets().sendHideIComponent(745, 6, true);
    31.         c.getPackets().sendIComponentText(745, 5, "" + c.timeCount);
    32.         chat("PvP Timer: "+c.timeCount);
    33.     }
    34.  
    35.     public void hideTimer() {
    36.         //hide timer
    37.     }
    38.  
    39.     public boolean isAtDitch() {
    40.         if (c.getX() >= 3039 && c.getY() >= 3523 &&
    41.             c.getX() <= 3303 && c.getY() <= 3524) {
    42.             return true;
    43.         }
    44.         return false;
    45.     }
    46.  
    47.     public boolean cancelTimer() {
    48.         System.out.println("Timer Canceled");
    49.         c.timeCount = -1;
    50.         hideTimer();
    51.         return false;
    52.     }
    53.  
    54.     public void callTimer() {
    55.         chat("Timer inited.");
    56.         c.timeCount = 10;
    57.         countDown();
    58.     }
    59.  
    60.     public void countDown() {
    61.         WorldTasksManager.schedule(new WorldTask() {
    62.  
    63.             @Override
    64.             public void run() {
    65.                 if (c.timeCount <= -1) {
    66.                     System.out.println("[PvP Timer] has Reached ending sequence state");
    67.                     hideTimer();
    68.                     c.getPackets().sendHideIComponent(745, 3, false);
    69.                     stop();
    70.                 }
    71.                 if (c.getControlerManager().getControler() instanceof Wilderness) {
    72.                     if (!isAtDitch()) {
    73.                         c.getPackets().sendHideIComponent(745, 3, false);
    74.                         c.timeCount = -1;
    75.                         return;
    76.                     }
    77.          
    78.                 }
    79.                 sendTimer();
    80.                 c.timeCount--;
    81.          
    82.             }          
    83.         }, 0, 1);
    84.     }
    85.  
    86. }
    87.  
    88.  
    89.  
     

Share This Page

Loading...