Solved How to spawn items randomly ?

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

  1. Matrox

    Matrox Slime

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

    MC ATECH Slime

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

    Matrox Slime

    Messages:
    78
    Yes :)
     
  4. Akmal

    Akmal Spider

    Messages:
    9
    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))]);
     
  5. Matrox

    Matrox Slime

    Messages:
    78
    For my parents I use :
    PHP:
    $level->dropItem($pos$items[array_rand($items)]);
     

Share This Page

  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.