Jump to content

Ore Layer


Recommended Posts

How do i make a skript that causes a plane of blocks to generate, and it randomly chooses what blocks generate?

for example: it generates a 1000 by 1000 block plane, and each block it generates has a 50% chance to be stone, 25% percent chance to be iron, and a 25% percent chance to be gold.

Thanks to anyone who can help!

Link to comment
Share on other sites

# Defining the function
function randomBlocks(s: player, l1: location, l2: location): # "s" is the player, "l1" is the first location, "l2" is the second location
	loop blocks between {_l1} and {_l2}: # Looping every block between the 2 locations
		set {_i} to random integer between 1 and 100 # Getting a random number for the probability
		if {_i} is between 1 and 50: # Basically like saying "chance of 50%" but easier to have more than 2 options
			set block at loop-block to stone # Sets the looped block to the new desired block
			add 1 to {_stone} # Adds 1 to the total count of that block (useful for knowing how much of each block there is)
		# And the reset basically repeats
		if {_i} is between 51 and 75:
			set block at loop-block to iron ore
			add 1 to {_iron}
		if {_i} is between 76 and 100:
			set block at loop-block to gold ore
			add 1 to {_gold}
		set {_ttl} to {_stone} + {_iron} + {_gold} # Gets the total amount of blocks changed
		set {_stonepercent} to rounded ({_stone} / {_ttl}) * 100 #  \
		set {_ironpercent} to rounded ({_iron} / {_ttl}) * 100 #     --- Gets the percentages
		set {_goldpercent} to rounded ({_gold} / {_ttl}) * 100 #    /
	send "&aThe blocks have been radomly generated! (Approx. %{_stonepercent}%&a%% stone, %{_ironpercent}%&a%% iron and %{_goldpercent}%&a%% gold)" to {_s} # Confirmation message

# Defining the command
command /randomblocks: # Command has no arguments, but you could easily add some... I'm making it so that it automatically makes it 1000x1000 by setting the middle to the player's target block.
  	permission: op # Can be any permission
  	permission message: &cNo permissions. # Message received when command is incorrect
	usage: Usage: /randomblocks # Tells the user how to use the command
		if target block is air:
			message "&cYou must be looking at a block!"
			set {_l1} to location of target block # ---- Sets the variable to the player's targetted block
			set {_l2} to location of target block # -/
			add 499 to x-coord of {_l1} # ---- Adds 499 to the x and z coordinates (adding 500 and removing 500 would make it 1001x1001)
			add 499 to z-coord of {_l1} # -/
			remove 500 from x-coord of {_l2} # ---- Removes 500 from the x and z coordinates
			remove 500 from z-coord of {_l2} # -/
			randomBlocks(player, {_l1}, {_l2}) # Recalls the function

# If you wanted, you could set up a wand for it in a similar way to WorldEdit pretty easily, the dimensions would be more customizable.

The comments took me a while to write, so I really hope they were helpful 😆

Also, I only put it through the SkUnity parser, I never tested it in-game so it's not 100% guaranteed to work

Edited by _iz_
Messed up a comment

» IGN: _iZ_ «

» Joined: 12/18/2016 «

» VIP: 1/13/2018 «

» Helper: 1/29/2021 «

» [<3]: 5/8/2021 «

» Skript dev «

» Discord: iZz#0420 «

I have diabetes

React to this if I was helpful, found this interesting, or you're just nice 🙂

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...