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

Solved How to spawn items randomly ?

Discussion in 'Development' started by Matrox, Jun 12, 2019.

  1. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    how can I spawn items in a defined area ?
     
  2. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    Are you wanting to spawn items randomly in or in a defined area?
     
  3. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Yes :)
     
  4. Akmal

    Akmal Spider

    Messages:
    10
    GitHub:
    AkmalFairuz
    Use this code :
    PHP:
    $items = [
         
    Item::get(Item::DIAMOND01),
         
    Item::get(Item::GOLD_INGOT01),
         
    Item::get(Item::APPLE01)
    ]; 
    //list of Items
    $x 0// position x
    $y 5// position y
    $z 0// position z
    $pos = new Vector3($x$y$z);
    /** @var Level $level */
    $level->dropItem($pos$items[rand(0, (count($items) - 1))]);
     
    OnTheVerge likes this.
  5. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    For my parents I use :
    PHP:
    $level->dropItem($pos$items[array_rand($items)]);
     
    OnTheVerge likes this.
  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.