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

Solved Scatter players

Discussion in 'Development' started by SavionLegendZzz, Feb 25, 2019.

  1. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    I want to scatter players around the world based on a disatance from the world spawn point(or otherwise called radius) i know i have to check the blocks under and somewhat around the player, but how would i go about doing this?
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Muqsit likes this.
  3. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    I got a different method from https://bukkit.org/threads/random-location-within-a-radius-not-a-square-area.131423/#post-1563032 and converted it to PHP
    PHP:
    /**
         * @return Position
         */
        
    public function getNewSpawnPoint(){
            
    $rndGen = new Random();
            
    $r $rndGen->nextBoundedInt($this->getBorder());
            
    $x $rndGen->nextBoundedInt($r);
            
    $z sqrt(pow($r,2) - pow($x,2));
            if(
    $rndGen->nextBoolean()) $x *= -1;
            if(
    $rndGen->nextBoolean()) $z *= -1;

            return new 
    Position($x256$z$this->getLevelByName());
        }
    my only problem is getting a Y i know i have to check if the the block(s) around the player are "safe" ones but i dont know how to go about it somewhat
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You can use $level->getSafeSpawn($pos) to get a safe y
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    That doesn't look uniformly random. Let me make a randomness scattetplot based on your algorithm:
    download (2).png
    There is almost zero chance that a point in the horizontal axis is selected, and the points are highly converged towards the center.

    You should generate r² and yaw uniformly, instead of r and cos(yaw). Otherwise you'd get something like that image
     
    jasonwynn10 likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    If you use the algorithm I linked above (uniform r², uniform theta), you get something like this instead:

    download (3).png
     
  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.