1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Sleep() problem

Discussion in 'Facepalm' started by Harviy11, Feb 4, 2017.

  1. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    i used sleep to wait 1 second in interact event but it wait and then use all code
    PHP:
    public function onInteract(PlayerInteractEvent $event)
    {
        
    $block $event->getBlock();
        
    $player $event->getPlayer();
        
    $inventory $player->getInventory();
        if (
    $block->getId() === Block::CHEST) {
            if (
    $inventory->contains(new Emerald(01))) {
                
    $event->setCancelled();
                
    $player->sendMessage("§6[MineDox] §aOpening crate chest...");
                
    sleep(1);
                
    $player->sendMessage("§a3");
                
    sleep(1);
                
    $player->sendMessage("§a2");
                
    sleep(1);
                
    $player->sendMessage("§a1");
                
    $level $player->getLevel();
                
    $x $block->getX();
                
    $y $block->getY();
                
    $z $block->getZ();
                
    $r 0;
                
    $g 255;
                
    $b 255;
                
    $center = new Vector3($x 1$y$z);
                
    $radius 0.5;
                
    $count 100;
                
    $particle = new DustParticle($center$r$g$b1);
                for (
    $yaw 0$y $center->y$y $center->4$yaw += (M_PI 2) / 20$y += 20) {
                    
    $x = -sin($yaw) + $center->x;
                    
    $z cos($yaw) + $center->z;
                    
    $particle->setComponents($x$y$z);
                    
    $level->addParticle($particle);
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    YAAY
    another post to be moved to facepalm
    http://php.net/manual/en/function.sleep.php READ!
    D E L A Y S execution. That means everything else also gets stopped. Events aren't in another thread. Please search the forums on how to create Delayed/Repeating tasks.
     
  3. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
  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.