How to make mobs spawn where the player is at random intervals?



  • Hello I'm trying to make a plugin/mod where mobs(1 - 31) randomly spawn at the players coords, but I'm very new to coding in Minecraft so any help will be appreciated.

    I'm playing on 1.18



  • You can use Psuedo Random, it is not entirely random but it's fast enough to be "random". To do Pseudo Random you can add a dummy scoreboard to yourself

    /scoreboard objectives add psuedoRandom dummy
    

    Then you can create a repeating command block that increments it or changes it to a random one

    /scoreboard players add @s psuedoRandom 1
    

    Then add a repeating command block that resets it everytime it goes to the max limit

    /execute if score @s pseudoRandom matches 100.. run scoreboard players reset psuedoRandom
    

    Then you can add a repeating command block that checks if the psuedo random is at a specific number then summon depending on what mob you choose

    /execute if score @s pseudoRandom matches 69 run summon tnt ~ ~1 ~
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2