Task + seconds etc

Discussion in 'Facepalm' started by Zuruki, May 10, 2017.

  1. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    Hey! So I want to create a task that sends a popup to the player with a timer of about 1 minute.

    After the timer ends, I want to execute a piece of code I have which gives items.
    However, I want the player to receive a title that is like 5,4,3,2,1 every second. (Can someone explain the parameters of addTitle)?

    Also, I want to cancel PlayerMoveEvent for 10 seconds whilst sending the title.

    I need an explanation of task with timers etc, thankyou (like executing function after 30 seconds and sending pop up to player with the amount in seconds left until the function is executed). Thankyou !!
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,552
    GitHub:
    muqsit
    Refer to thread Creating a timer with Tasks
    Use Task:: onCancel()
    PHP:
    //class extending Task
    public function onCancel(){
        
    //your code here.
    }
     
    corytortoise likes this.
  3. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    There is a lot of stuff going on in this thread (maybe split up in future).

    1. The params for addTitle. There is documentation at that link. Could you let us know what part of it is unclear?
    2. Cancelling the PlayerMoveEvent for 10 seconds. You can do this by mapping player objects to the time they were aded. Then you will check in your player move event if (time + 10 > currentTime).
    3. Doing that countdown thingy. I think the cleverest way to do that would be to use a delayed repeating task. Say you want to wait a minute and then count down 5,4,3,2,1 at the end. You would schedule the task to delay 55*20 ticks (55 seconds) and then run every 20 ticks (second). The task would need to know how many times it can expect to run before it should stop (in this case it would be 6) and every time it runs it will reduce the count of times left to run by one. When the counter gets it zero, it will execute the command and destroy itself. You could also use a simple repeating task, but that means it would execute every second and not just toward the end when you want to start displaying a countdown.
    Note: I might be off by one with the ticks, I haven't used the delayed repeating feature.
     
    Last edited: May 10, 2017
  4. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    Thankyou both.
    Hi Falk! Can I get some code regarding the Countdown thingy and using time()? Would appreciate it
     
  5. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    Here is an example of the player move blocking thing. I will try to get you an example of the other too.

     
  6. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    And for the second one I wrote this up. It likely has some errors, but the basic idea is there.

     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.