Code:public void wait(int time) { try { Thread.sleep(time); catch(InterruptedException inter) { System.i=out.println("Thread Interrupted \n"); inter.printStackTrace(); } }
|
I have that so far, and for my actual method I have:Code:public void wait(int time) { Thread.sleep(time); } try{ }
All help is appreciatedCode:for (int i = 0; i < server.npcHandler.npcs.length; i++) { if (server.npcHandler.npcs[i] != null && server.npcHandler.npcs[i].npcType == 0 && random123 == 1) { server.npcHandler.npcs[i].updateRequired = true; server.npcHandler.npcs[i].textUpdateRequired = true; server.npcHandler.npcs[i].textUpdate = "The portal next to me is to the Green dragons, bring an anti-d shield."; } } wait(2000); for (int i = 0; i < server.npcHandler.npcs.length; i++) { if (server.npcHandler.npcs[i] != null && server.npcHandler.npcs[i].npcType == 0 && random123 == 0) { server.npcHandler.npcs[i].updateRequired = true; server.npcHandler.npcs[i].textUpdateRequired = true; server.npcHandler.npcs[i].textUpdate = "Talk to me to teleport (training too)."; } }
Code:public void wait(int time) { try { Thread.sleep(time); catch(InterruptedException inter) { System.i=out.println("Thread Interrupted \n"); inter.printStackTrace(); } }
A system timer would be better then using Thread.sleep()
You can try something like this:
And make sure you declareCode:for (int i = 0; i < server.npcHandler.npcs.length; i++) { if(System.currentTimeMillis() - npcTextTimer < 2000){ if (server.npcHandler.npcs[i] != null && server.npcHandler.npcs[i].npcType == 0 && random123 == 1) { server.npcHandler.npcs[i].updateRequired = true; server.npcHandler.npcs[i].textUpdateRequired = true; server.npcHandler.npcs[i].textUpdate = "The portal next to me is to the Green dragons, bring an anti-d shield."; } } else { if (server.npcHandler.npcs[i] != null && server.npcHandler.npcs[i].npcType == 0 && random123 == 0) { server.npcHandler.npcs[i].updateRequired = true; server.npcHandler.npcs[i].textUpdateRequired = true; server.npcHandler.npcs[i].textUpdate = "Talk to me to teleport (training too)."; npcTextTimer = System.currentTimeMillis(); } } }
UnderCode:public long npcTextTimer;
Code:public class *CLASS NAME* {
client.java:22742: 'catch' without 'try'
catch(InterruptedException inter) {
^
client.java:22742: ')' expected
catch(InterruptedException inter) {
^
client.java:22742: not a statement
catch(InterruptedException inter) {
^
client.java:22742: ';' expected
catch(InterruptedException inter) {
^
client.java:22740: 'try' without 'catch' or 'finally'
try {
^
5 errors
Finished!
Press any key to continue . . .
=\
I don't recommend using the sleep() method, but that's just me. Make sure it's delaying the correct thread, by the way.
I lawl'd, enjoy.
Code:public void sleepLol(long milli) { try { Thread.sleep(milli); } catch (Exception e) { System.out.println("lawl whatever kk hav fun"); } }
changed to :
And it worked, but the players couldn't move except once every 2 seconds because it was set to:Code:public void wait(int time) { try { Thread.sleep(time); } catch (InterruptedException ie) { System.out.println("Interrupted Exception"); } }
If anyone could tell me why it lagged the server that will be my fix. thanks very much .Code:wait(2000);
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |