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

Solved Disable sprinting ?

Comments in 'Plugin Development' started by Inta, May 18, 2016.

  1. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    How to prevent Player from Sprinting ?
    I've tried cancelling PlayerToggleSprintingEvent but no luck.
  2. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Use PlayerToggleSprintEvent
  3. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    How about adding slowness effect while the player is sprinting
  4. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Could you post the code for me? I've tried cancelling this, but Players still able to sprint though..

    Umm.. Yes! but not as effective as cancelling Sprinting Packet!
  5. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    PHP:
    $player->setDataProperty(Player::DATA_FLAG_SPRINTINGPlayer::DATA_TYPE_BYTEfalse);
    MyNameIsTriXz and Survingo like this.
  6. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Not working. Am i missed something ?
    PHP:
    public function noSprint(PlayerToggleSprintEvent $event) {
            
    // TODO: No Sprint
            
    $player $event->getPlayer();
            
    $player->setDataProperty(Player::DATA_FLAG_SPRINTINGPlayer::DATA_TYPE_BYTEfalse);
        }
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Just use it onJoin
  8. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Really? Then it will be replaced with true whenever the player starts sprinting..
  9. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    There are conflicts with your code...

    If you are willing to send the instruction to player so the client doesn't allow any attempts of sprinting, use:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
         
    // BTW: Order for parameters is: PropertyId, Value, Flag Type....
        
    $player->setDataFlag($player::DATA_FLAGS$player::DATA_FLAG_SPRINTINGfalse$player::DATA_TYPE_BYTE);
    }
    Otherwise, if you are willing to dynamically block sprint, PlayerToggleSprintEvent is your best option:
    PHP:
    public function onSprint(PlayerToggleSprintEvent $event){
        
    $event->setCancelled(true);
    }
    Last edited: May 18, 2016
    Primus likes this.
  10. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    The first code is not working. Maybe you're wrong about the parameters:
    PHP:
    public function setDataFlag($propertyId$id$value true$type self::DATA_TYPE_BYTE){
    as in the Entity.php . I don't know what to fill in the $id. DataFlag's id or Player's id ?

    The second code doesn't work (at all). It's not blocking the sprint, but block to Not stop sprinting. So the player will keep sprinting over and over.
  11. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    no
  12. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Still doesn't work..
  13. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Fixed ;)
  14. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Use the exact same thing, still doesnt work sir..
  15. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    How would it work if you use the "same thing"? Just look at edited code
  16. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Even the edit sir, since the "check edited" post arrived i edited my code, and still doesn't work:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $player->setDataFlag($player::DATA_FLAGS$player::DATA_FLAG_SPRINTINGfalse$player::DATA_TYPE_BYTE);
        }
  17. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Doesn't work :(
  18. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Bump... Is this able to do guys? I've seen this somewhere!
  19. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Have you tried PlayerMoveEvent?
    public function onMove(Move $event){$event->getPlayer()->setSprinting(false);}
    iDirtPlayzMC and Inta like this.
  20. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    WORKS! Why its so simple?
    But will it causes lag ? Because many players will move every tick and ... u know..

Share This Page

Advertisement