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

Re: Speed Modifier

Discussion in 'Development' started by minijaham, Nov 11, 2020.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Hello, it's me again but with a slightly different problem.

    I've set up a repeating task to see if respawning is an actual cause of setting an attribute value.
    Source: https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/Player.php#L3840
    Thank you wolfdale for helping me in the previous thread :D

    And it was. I've tested several times and..yeah the problem was in the respawn.

    Here is the task code(repeating)
    PHP:

    class CheckAttributeTask extends Task
    {
        private 
    $plugin;

        public function 
    __construct(Main $plugin)
        {
            
    $this->plugin $plugin;
        }
        public function 
    onRun($currentTick)
        {
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $player){
                
    $name $player->getName();
                
    $value $this->plugin->speed->get($name);
                
    $attr $player->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
                
    $attr->setValue($value); // Set speed
                
    $player->sendMessage((string)$attr->getValue()); // Check what value you are on
            
    }
        }
    }
    The code works. However, the problem is it doesn't set the new value after respawning, regardless of how long the time passes by. Is there a way to workaround?
     
  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.