Thread: Wait Method (I think I almost got it this time xD)

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1 Wait Method (I think I almost got it this time xD) 
    Registered Member
    Join Date
    Sep 2009
    Posts
    89
    Thanks given
    0
    Thanks received
    7
    Rep Power
    71
    Code:
    public void wait(int time) {
    Thread.sleep(time);
    }
    	try{
    		
    	}
    I have that so far, and for my actual method I have:
    Code:
    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).";
    			}
    		}
    All help is appreciated
    Did you know?
    - We need "did you know" facts


    Reply With Quote  
     

  2. #2  
    You're My Favourite!

    Join Date
    Aug 2007
    Posts
    1,282
    Thanks given
    485
    Thanks received
    72
    Rep Power
    1397
    Code:
    public void wait(int time) {
    try {
    Thread.sleep(time);
    catch(InterruptedException inter) {
    System.i=out.println("Thread Interrupted \n");
    inter.printStackTrace();
          }
    }




    With Love, Bot.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Sep 2009
    Posts
    89
    Thanks given
    0
    Thanks received
    7
    Rep Power
    71
    Sounds good, I will try this out, Thank you very much
    Did you know?
    - We need "did you know" facts


    Reply With Quote  
     

  4. #4  
    Member

    Join Date
    May 2008
    Posts
    1,288
    Thanks given
    50
    Thanks received
    92
    Rep Power
    0
    A system timer would be better then using Thread.sleep()

    You can try something like this:
    Code:
    		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();
    			}
    		    }
    		}
    And make sure you declare
    Code:
    public long npcTextTimer;
    Under
    Code:
    public class *CLASS NAME* {
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Sep 2009
    Posts
    89
    Thanks given
    0
    Thanks received
    7
    Rep Power
    71
    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 . . .

    =\
    Did you know?
    - We need "did you know" facts


    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Oct 2009
    Posts
    182
    Thanks given
    0
    Thanks received
    0
    Rep Power
    223
    I don't recommend using the sleep() method, but that's just me. Make sure it's delaying the correct thread, by the way.
    Reply With Quote  
     

  7. #7  
    Banned


    Join Date
    Jul 2006
    Posts
    104
    Thanks given
    0
    Thanks received
    0
    Rep Power
    149
    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");
         }
    }

    Ex Administrator of RS-Server
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Oct 2009
    Posts
    182
    Thanks given
    0
    Thanks received
    0
    Rep Power
    223
    Quote Originally Posted by Fusion View Post
    Code:
    public void wait(int time) {
    try {
    Thread.sleep(time);
    catch(InterruptedException inter) {
    System.i=out.println("Thread Interrupted \n");
    inter.printStackTrace();
          }
    }
    Code:
    System.i=out.println("Thread Interrupted \n");
    What...?
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Sep 2009
    Posts
    89
    Thanks given
    0
    Thanks received
    7
    Rep Power
    71
    Quote Originally Posted by badreligion View Post
    A system timer would be better then using Thread.sleep()

    You can try something like this:
    Code:
    		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();
    			}
    		    }
    		}
    And make sure you declare
    Code:
    public long npcTextTimer;
    Under
    Code:
    public class *CLASS NAME* {
    didn't work =\
    Did you know?
    - We need "did you know" facts


    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Sep 2009
    Posts
    89
    Thanks given
    0
    Thanks received
    7
    Rep Power
    71
    Quote Originally Posted by Rat Dawg View Post
    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 :
    Code:
    public void wait(int time)
    {
         try
         {
              Thread.sleep(time);
         }
         catch (InterruptedException ie)
         {
              System.out.println("Interrupted Exception");
         }
    }
    And it worked, but the players couldn't move except once every 2 seconds because it was set to:
    Code:
    wait(2000);
    If anyone could tell me why it lagged the server that will be my fix. thanks very much .
    Did you know?
    - We need "did you know" facts


    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •