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

Player can move a little code

Comments in 'Plugin Development' started by korado531m7, Oct 12, 2015.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I've survival games server. But, when people waiting start, player can't move (using setCancelled() ).
    How to player can move a little?
    It like LifeBoat server.
    Thank you for reading my thread, and answering.
    Last edited: Oct 12, 2015
  2. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Try
    PHP:
    if($event->getTo() !== $event->getFrom){
      
    $event->setCancelled();
    }
    Taha_The_Hacker likes this.
  3. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Thank you. I'll try it.
  4. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I tried. But player can't move.
  5. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    You mean can look around but not move?
  6. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    I believe so, as in LifeBoat, players cant actually move until the timer ends up at 0.
  7. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    But.. won't that always cancel? How can $event->getTo() equal $event->getFrom()? Btw, you left out a () after $event->getFrom
    PEMapModder likes this.
  8. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    notice the "!==" XD
  9. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    I know, but there's no point for that "if" statement. It's basically just always cancelling it.

    EDIT: This is my 600th post!
    zombie_Power likes this.
  10. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Just trying to take my revenge :rolleyes:
    Legoboy0215 likes this.
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ok. I am being nice, since I used my brain to SEARCH.
    PHP:
    public function onMove(PlayerMoveEvent $event){
            if (
    $event->isCancelled()) return;
            
    $p $event->getPlayer();    
                
    // Lock position but still allow to turn around
                
    $to = clone $event->getFrom();
                
    $to->yaw $event->getTo()->yaw;
                
    $to->pitch $event->getTo()->pitch;
                
    $event->setTo($to);
        }
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You know that there exists the === and !== operators, right?

    This probably makes things run slower, but this code looks more beautiful:
    PHP:
    if($event->getTo()->distanceSquared($event->getFrom()) > 0$event->setCancelled();
    But this uses distanceSquared, which involves some unnecessary calculation, although the code is shorter.

    The fastest way should be:
    PHP:
    $from $event->getFrom();
    $to $event->getTo();
    if(
    $from->!== $to->or $from->!== $to->or $from->!== $to->z$event->setCancelled();
    jojoe77777 and Creeperface like this.
  13. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Oops forgot the ()

Share This Page

Advertisement