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

Adjust player's speed in creative

Discussion in 'Facepalm' started by Thouv, Apr 22, 2017.

  1. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    Is it possible to set a player's flight speed (in creative mode) so that they go, say, twice faster than the regular speed in creative? Aka what lots of PC mods achieve with /speed 2?
    If it's not possible while they're in creative, is it possible if they're in survival?
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    setting effects on game mode change event
     
  3. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    Speed effect doesn't affect creative mode though
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    There are a few ways that this can be done
    1. You can check a player's gamemode and if they are flying, then you can use Entity::setMotion() and Entity::getMotion() with a little bit of math to make the player move faster.
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Entity.php#L1557-L1567
    2. Set the MOVEMENT_SPEED attribute of the player while they are in creative and flying to 2x the original number. The attribute is already modified here for sprinting:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Entity.php#L439-L445
     
    Last edited: Apr 24, 2017
  5. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    Is there a way to use the second method only on one player when they type /speed <number>? Or will it affect all players flying in creative to change the value?
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    it will only affect the specific player's speed
     
  7. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    So I need to add an attribute that sets movement speed to 2x and set that to the player?
     
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Look at the links I've provided to see how it can be done
     
  9. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    Soooooooooo
    PHP:
    $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED)->setValue(2);
    ??
    As you can see I'm a huge noob, testing this right now
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  11. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
  12. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    Ok, so I think I got it. Each player's attribute map is separate, right?
    And I'm pretty sure what I posted above works because this is Effect.php lines 307-309
    PHP:
    $attr $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
    $attr->setValue($attr->getValue() / (0.2 $this->amplifier));
     
  13. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    GG mate, I think you figured it out! Now you can implement it in with the rest of your code and move on!
     
  14. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    So, this is perfect for setting the speed in survival, but it doesn't affect the flying speed in creative... Which doesn't make sense to me, because if I sprint in creative I fly faster, and I'm guessing that setSprinting() is called when I sprint in cmode
     
  15. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    The first method will work in creative, but stopping may be difficult
     
  16. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    I'll try to figure out something that works with the first method.
    The thing is, we go faster if we sprint in creative... Is there a different method than setSprinting that's called for that?
     
  17. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    There may be if the speed is adjusted each time the player is ticked
     
  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.