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

Cooldown help :(

Discussion in 'Plugin Help' started by Martti16, Apr 13, 2017.

  1. Martti16

    Martti16 Spider

    Messages:
    14
    GitHub:
    Marttinek
    Look at this code. How to add cooldown to generate stone for this code
    $gracz->getLevel()->setBlock(new Vector3($blok->getFloorX(), $blok->getFloorY()+1, $blok->getFloorZ()), new Stone());


    public function onPlace(BlockPlaceEvent $event){
    $blok = $event->getBlock();
    $gracz = $event->getPlayer();
    $y = $blok->getFloorY();
    $x = $blok->getFloorX();
    $z = $blok->getFloorZ();

    if($blok->getId() == 121){
    if(!($event->isCancelled())){
    $gracz->getLevel()->setBlock(new Vector3($blok->getFloorX(), $blok->getFloorY()+1, $blok->getFloorZ()), new Stone());
    $gracz->sendMessage("• Postawiles stoniarke! •");
    $center = new Vector3($x, $y, $z);
    $particle = new LavaParticle($center);
    for($yaw = 0, $y = $center->y; $y < $center->y + 3; $yaw += (M_PI * 2) / 20, $y += 1 / 20) {
    $x = -sin($yaw) + $center->x;
    $z = cos($yaw) + $center->z;
    $particle->setComponents($x, $y, $z);
    }
    }else{
    $gracz->sendMessage("• Nie możesz postawić tutaj stoniarki, ten teren jest zabezpieczony •");
    }
    }
    }
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    USE CODE TAGS
     
    HimbeersaftLP likes this.
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Please speak English in these forums so we can understand what you said.
     
  4. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    He said:

    I was just asking here exactly the same. So much for another chapter. For the first time you see, I thought you knew such things ;). Would you be interested in co-operation?
    And by associating this plugin, I have onBreak event and canceled after some time
     
    Sandertv likes this.
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    That's probably because Position::getPlugin() isn't a valid method or attribute, Plugin::getLevel() isn't a valid method or attribute, and that line makes no sense. I assume you are trying to set stone, and since you seem to have tried yourself, you can use this to set a block:
    PHP:
     /** @var Position $position */
     
    $this->position->getLevel()->setBlock($this->positionBlock::get(Block::STONE); 
    Also, you need to make $position a global variable for use later on. Do that by adding $this->position = $position; under parent::__construct().
     
    Last edited: Apr 19, 2017
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    One should use Block::get() because of the upcoming block and item rewrite
     
    TheDiamondYT and corytortoise like this.
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You need to remove the ->getPlugin in $this->position->getPlugin->getLevel->setBlock... and add a () right after getLevel. You also need to make $position a global variable in the constructor method. I mentioned how to do that before(basically, do the same thing you did with $plugin).
    Thanks for clearing that up. I knew Item::get() was the suggested method of constructing an item object, but I see a lot of stuff like "new Obsidian()" around here, so I wasn't sure. I'll edit my post to reflect this.
     
  8. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    One should consider stopping referring to ones self as one.
     
  9. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    One can use "one" when not referring to one's self
     
    TheDiamondYT likes this.
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You should schedule a DelayedTask instead of a RepeatingTask, since you only need to run it once. I suggest using this to schedule the task if you want to make a 3 second delay:
    PHP:
     $this->getServer()->getScheduler()->scheduleDelayedTask(new Task($this$blok), 20 3); //20 * 3 = 3 seconds 
    And if you use a delayed task, you won't need to cancel it.
     
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    That's because you are cancelling the event. If you cancel the event, the block will be replaced and it won't drop anything.
     
  12. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Remove the $event->setCancelled() function right after where you schedule the task.
     
  13. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    And then setBlock.. Right? Stone will not appear at all when i remove $evenf->setCanceled()... It is onBreak event
     
  14. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    No, the block will be set 3 seconds later with the task.
     
  15. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Are you testing it by breaking a stone block that is on top of a block with ID 121? Are there any errors? Do you know if the task runs at all? Try debugging to see.
     
  16. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    Wait... Whoooa it WORKS!!!! That You Very Very much for help , i just gave too many ticks, and it was reloading too slow. Thank you!
     
  17. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Glad it worked!
     
    Lorak9904 likes this.
  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.