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

Sneak/Sprint

Comments in 'Plugin Development' started by JackboyPlay, Feb 27, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I set a player sneaking/sprinting
    And how can I chck if a player is sneaking/sprinting?
  2. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    If you need check anyone sprinting/sneaking
    This for sneaking
    PHP:
    Public function onSneak(PlayerToggleSneakEvent $ev){
       
    $this->getServer()->getLogger()-($ev->getPlayer()->getName()."is sneaking");
    }
    This for sprinting
    PHP:
    Public function onSprinting(PlayerToggleSprintingEvent $ev){
       
    $this->getServer()->getLogger()-($ev->getPlayer()->getName()."is sprinting");
    }
    JackboyPlay likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    why are you trying to subtract a string from a logger object?
    Moreover, toggle means "toggle on/off".
    PocketKiller and Hotshot_9930 like this.
  4. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    I don't know if this still works but this is how it was before sneaking was added to MCPE.
    PHP:
    //Add entity flag
    //Add sneaking flag
    $player->setDataFlag(Entity::DATA_FLAGSEntity::DATA_FLAG_SNEAKINGtrue);//true = on, false =  off
    //Add springting flag
    $player->setDataFlag(Entity::DATA_FLAGSEntity::DATA_FLAG_SPRINTINGtrue);//true = on, false =  off

    //check if player is sneaking/sprinting
    if($player->isSneaking()){
    //player is sneaking
    //do something...
    }
    if(
    $player->isSprinting()){
    //player is sprinting
    //do something...
    }
    JackboyPlay likes this.
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Thanks :D
  6. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    Public function onSprinting(PlayerToggleSprintingEvent $ev){
       
    $this->getServer()->getLogger()->info($ev->getPlayer()->getName()."is sprinting");
    }
    PHP:
    Public function onSneak(PlayerToggleSneakEvent $ev){
       
    $this->getServer()->getLogger()->info($ev->getPlayer()->getName()."is sneaking");
    }
    Fix
    ----------------
    PHP:
    $player->setSneaking();
    $player->setSprinting();
    Last edited: Feb 28, 2016

Share This Page

Advertisement