Social Icons

Sunday, 6 May 2012

[Tut]Delay Without Thread.sleep[Tut]

I have seen many people asking for something like this and decided to make a tutorial on it...
Well here goes...

Step 1.
First make a new class called (hackname)Timer in my case ill be using it for a spam hack... so "SpamTimer" will work for me....

Step 2.
Define these:

Code:
Timer spamtimer;

Step 3.
Add this code in, to schedule the task after a delay
Code:
public SpamTimer(double d) {
    spamtimer = new Timer();
    spamtimer.schedule(new SpamTask(), (long) (d * 1000));
  }

Step 4.
Make a new class in "(hack)Task", and a method
Code:
class SpamTask extends TimerTask {
    public void run() {

Step 5.
put this inside run, its basically saying if your toggle is on, and your in multiplayer, restart the timer when its done....
Code:
if(Minecraft.isMultiplayerWorld() && hacks.numspam){
     new SpamTimer(0.15);
Step 6.
Put your code you want to run under that....
Code:
Minecraft.thePlayer.sendChatMessage("OMGWTFTHISISASPAMMESSAGE")

Step 7.
Now add this wherever your toggle/console command is....
Code:
if(message.startsWith("numspam"))
    {
    new Spamtimer(0.15);
    hacks.numspam = !hacks.numspam;         
    }
Thnx for reading, leave constructive criticism ONLY below!!

P.S. the "new Spamtimer(0.15);" double is in seconds, so 0.15 will be 150ms and 1.5 will be 1 and a half seconds....


Credit To: dmkiller11

No comments:

Post a Comment