Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Help - PlayerMoveEvent

Comments in 'Plugin Development' started by Kvetinac97, Jul 30, 2015.

  1. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    public function portalJoin(PlayerMoveEvent $ev){
      if (!(
    $this->getServer()->getLevelByName("lobby")->getBlockIdAt($ev->getTo()->getX(),$ev->getTo()->getY()-1,$ev->getTo()->getZ()) == 133)){
      if (
    $ev->getTo()->getLevel()->getName() == "lobby" and in_array($ev->getTo()->getX(), [126,127,128]) and in_array($ev->getTo()->getY(), [36,37]) and in_array($ev->getTo()->getZ(), [140,141,142])){
       
    $num rand(1,5);
       
    $this->joinGame($ev->getPlayer(), $num);
      }     
    }
    else {
     
    $ev->getPlayer()->knockback(4);   
    }
    }
    I'm using this code, but when I stand on Emerald, I don't get any knockback and when I move into position e.g. 126,36,140, I won't join game
    PianoPlayer38, TheKofola12 and Ake like this.
  2. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    try $ev->getPlayer()->getX(),$ev->getPlayer()->getY()-1,$ev->getPlayer()->getZ()

    or why "!"

    if (!($this->getServer()->getLevelByName("lobby")->getBlockIdAt($ev->getTo()->getX(),$ev->getTo()->getY()-1,$ev->getTo()->getZ()) == 133)){
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use $a !== $b instead of ! ($a === $b)
    Ake likes this.
  4. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    can u say why? the difference is only that he checked if the result of both is the same typ of result (int, string...)...
    Ake likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Neater code. Probably a few nanoseconds faster.
    Ake likes this.
  6. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I found out this problem. $this->getTo()->getX() returns e.g. 127,1237777000, so it can't be in array 126,127,128, so I use floor() and it works :)
    PianoPlayer38, TheKofola12 and Ake like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    126 <= $i and $i <= 128
  8. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Yes, this is possible too, but I used:
    PHP:
     $ev->getTo()->getFloorX()
    $ev->getTo()->getFloorZ() 
    PianoPlayer38, TheKofola12 and Ake like this.

Share This Page

Advertisement