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

How do you spawn at random when you go to the world doing

Comments in 'Plugin Development' started by musaichi, Aug 24, 2015.

  1. musaichi
    Offline

    musaichi New Member

    Joined:
    Mar 2, 2015
    Posts:
    33
    Minecraft User:
    musaichi
    I want the code to be able to teleport at random when entering the specified world.
    please help me.
    (sorry...i don't speak english.so i use automatic traslation.)
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    PHP:
    public function onLevelChange(EntityLevelChangeEvent $e){
            if((
    $world $e->getTarget())->getName() == "world_name"){
                
    $p $e->getEntity();
                if(!
    $p instanceof Player){
                    return 
    false;
                }
                
    $spawn $world->getSpawnLocation();
                
    $rnd_x rand($spawn->10000$spawn->10000);
                
    $rnd_z rand($spawn->10000$spawn->10000);
                
    /*if(!$world->isChunkLoaded($rnd_x, $rnd_z)){
                    $world->loadChunk($rnd_x, $rnd_z);
              }*/
              
    $p->teleport($world->getSafeSpawn(new Vector3($rnd_x128$rnd_z)));
            }
        }
    musaichi likes this.
  3. musaichi
    Offline

    musaichi New Member

    Joined:
    Mar 2, 2015
    Posts:
    33
    Minecraft User:
    musaichi
    thanks!i'm glad!
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but dont forget like :p
    musaichi likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    mt_rand is better than rand.
    jojoe77777 likes this.
  6. Creeper_Face
    Offline

    Creeper_Face Banned

    Joined:
    Aug 25, 2015
    Posts:
    6
    Minecraft User:
    Creeperface001
    why what is differnce between mt_rand and rand
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    mt_rand is faster and better.
    musaichi and Creeper_Face like this.

Share This Page

Advertisement