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

How to make a command that only excecuted when you step on certain block?

Discussion in 'Development' started by AmalCraft, May 31, 2021.

  1. AmalCraft

    AmalCraft Creeper

    Messages:
    5
    The title of this thread has self-explanatory. I am making a city roleplay server and I need a plugin that the command can only execute- when you step on a certain block, its for robbery plugin so the player can only use /startrob when they step on the bank floor (example gold block)
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    // onCommand
    $block $player->getLevel()->getBlock($player->subtract(010));
    if(
    $block->getId() !== Block::GOLD_BLOCK) { // I'm not sure if it's golden or just gold
           
    $player->sendMessage("You may not execute this command here.");
           return;
    }
     
    NTT and Axon like this.
  3. Axon

    Axon Zombie

    Messages:
    276
    Don't forget to make sure the player is on the bank's region! Otherwise players can just create gold blocks and defeat the system.
    Example:
    PHP:
    $x = [100200];
    $y = [2050];
    $z = [100200];
    $minY min($y);
    $minZ min($z);
    $maxX max($x);
    $maxY max($y);
    $maxZ max($z);
    $pos $player->getPosition();
    if(
        
    $pos->>= $minX and $pos-><= $maxX and
        
    $pos->>= $minY and $pos-><= $maxY and
        
    $pos->>= $minZ and $pos-><= $maxZ
    ){
     
    // Player is inside the region
    }
     
    Agent, NTT and minijaham like this.
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    A very nice addition! Yes. This is definitely necessary @AmalCraft
     
    Axon likes this.
  5. Ayush

    Ayush Witch

    Messages:
    62
  6. Axon

    Axon Zombie

    Messages:
    276
    Agent 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.