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?
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
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?
Soooooooooo PHP: $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED)->setValue(2); ?? As you can see I'm a huge noob, testing this right now
Pay close attention to these two lines: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Entity.php#L442-L443 P.S. It's called the facepalm section for a reason lol
PHP: $attr=$this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED);$attr->setValue($attr->getValue()*2); ?
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() / (1 + 0.2 * $this->amplifier));
GG mate, I think you figured it out! Now you can implement it in with the rest of your code and move on!
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
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?