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

First line of Sign

Discussion in 'Development' started by bySentixPE, May 26, 2018.

  1. bySentixPE

    bySentixPE Spider Jockey

    Messages:
    37
    How can I check if the first line of a sign is "buy"?
     
  2. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    The Sign is A tile so make a little search in pmmp files and you can see
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/tile/Sign.php#L120-L125
    PHP:
    //Check if the block is an instanceof Sign
    $tile $player->getLevel()->getTile($block);
    if(
    $tile instanceof Sign){
    //$text is an array of wht is written in the sign
    $text$tile->getText();
    //$line1 contain what is written in the first line of a sign
    $line1$tile->getLine(0)
    if(
    $line1== "[BUY]"){
    #Your code
     
  3. bySentixPE

    bySentixPE Spider Jockey

    Messages:
    37
    $block = ?
     
  4. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Depends of what event are you using....
    $block is a block.......
    If you want to know what is block i think you did not try to search how to get the block
    In interact Event its $event->getBlock()
     
  5. bySentixPE

    bySentixPE Spider Jockey

    Messages:
    37
    The code not Working i dont become a error but its not working
     
  6. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Send the code...
    And i just gived you an idea i didnt gave you the code
     
  7. bySentixPE

    bySentixPE Spider Jockey

    Messages:
    37
    public function onInteract(PlayerInteractEvent $event){
    $block = $event->getBlock();
    $player = $event->getPlayer();
    $tile = $player->getLevel()->getTile($block);

    if($tile instanceof Sign){
    $text = $tile->getText();
    $line1 = $tile->getLine(0);
    if($line1 == "[Buy]") {
    $player->sendMessage("Dont hit this Sign!");
    }
    }
    }
    }
     
  8. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    If you dont know there are "[PHP ]"
    And Send the code entirelly maybe you didt register the Event
    Or Your "Sign" is an instance of blocks(pocketmine/block/Sign) not an instance of pocketmine/tile/Sign
     
  9. bySentixPE

    bySentixPE Spider Jockey

    Messages:
    37
    Also i must import use pocketmine\tile\Sign; ?
     
  10. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Yes just that not the block class
     
  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.