Thread: Execute code after x amount of time. HELP!

Results 1 to 7 of 7
  1. #1 Execute code after x amount of time. HELP! 
    Registered Member
    Join Date
    Apr 2014
    Posts
    20
    Thanks given
    0
    Thanks received
    7
    Rep Power
    11
    Hello, I'm using PI source and right now I have this code:

    if (itemId == 1779 && objectId == 7849) {

    try
    {
    Thread.currentThread().sleep(2000);
    }
    catch(InterruptedException ex)
    {
    Thread.currentThread().interrupt();
    }
    c.sendMessage("test");
    }

    I want it to do this "c.sendMessage("test");" after 2 seconds, only problem with my code is that the whole server stops for 2 seconds, I just want the code to be delayed by 2 seconds.
    Reply With Quote  
     

  2. #2  
    Administrator

    Kevy's Avatar
    Join Date
    Jul 2006
    Posts
    1,178
    Thanks given
    87
    Thanks received
    1,593
    Discord
    View profile
    Rep Power
    4893
    You need to create a new delayed task/event for this.
    Thanks, Kevin.
    Reply With Quote  
     


  3. #3  
    ya


    Join Date
    Jul 2014
    Posts
    572
    Thanks given
    198
    Thanks received
    203
    DiscordTag
    Suic#0543
    Rep Power
    1817
    yes the whole server stops because ur stopping the main thread
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Registered Member
    Join Date
    Apr 2014
    Posts
    20
    Thanks given
    0
    Thanks received
    7
    Rep Power
    11
    Quote Originally Posted by Kevy View Post
    You need to create a new delayed task/event for this.
    Can you tell me more, I've tried this also

    if (System.currentTimeMillis() - c.ft > 5000) {
    c.ft = System.currentTimeMillis();

    c.sendMessage("");
    }

    }else{
    c.sendMessage("test");
    }

    That didnt work as planned either.
    Reply With Quote  
     

  6. #5  
    Super Donator

    Tyluur's Avatar
    Join Date
    Jun 2010
    Posts
    4,061
    Thanks given
    1,374
    Thanks received
    1,299
    Rep Power
    736
    Quote Originally Posted by bajskorv View Post
    Can you tell me more, I've tried this also

    if (System.currentTimeMillis() - c.ft > 5000) {
    c.ft = System.currentTimeMillis();

    c.sendMessage("");
    }

    }else{
    c.sendMessage("test");
    }

    That didnt work as planned either.
    i recommend you read this thread line by line [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #6  
    Wut can u say when theres nothin to tell

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    20
    Posts
    1,541
    Thanks given
    661
    Thanks received
    400
    Rep Power
    988
    Quote Originally Posted by Tyluur View Post
    i recommend you read this thread line by line [Only registered and activated users can see links. ]
    i would recommend first learning the basics of the language



    [Only registered and activated users can see links. ]


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #7  
    Rune-Server Affiliate
    Patrity's Avatar
    Join Date
    Jul 2008
    Age
    27
    Posts
    822
    Thanks given
    91
    Thanks received
    166
    DiscordTag
    Patrity#0001
    Rep Power
    419
    There's a ton of ways to do this.
    Sometimes you need to expand your google searches. Remember that Java is Java, and googling "RSPS..anything" will not get you anywhere.

    [Only registered and activated users can see links. ]
    Free map releases: [Only registered and activated users can see links. ]



    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Replies: 0
    Last Post: 08-15-2016, 10:55 PM
  2. Replies: 2
    Last Post: 06-30-2013, 01:20 AM
  3. Execute code after X amount of time?
    By Tigra in forum Help
    Replies: 13
    Last Post: 12-27-2012, 10:50 PM
  4. Replies: 0
    Last Post: 09-14-2009, 01:09 AM
  5. Replies: 47
    Last Post: 05-01-2008, 02:25 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •