1

Help with functions

Flashbulb's Avatar Flashbulb2/3/21 5:31 pm
2/4/2021 10:24 am
One_Nose's Avatar One_Nose
I am new to datapacks and was wondering how would I make a function, that when used teleports the player to a random location and gives them blindness for 10 seconds?
Posted by Flashbulb's Avatar
Flashbulb
Level 47 : Master Fish
85

Create an account or sign in to comment.

2

3
02/04/2021 10:24 am
Level 57 : Grandmaster Hero
One_Nose
One_Nose's Avatar
You cannot teleport a player to a completely random location, but yhe /spreadplayers command spreads the chosen entities randomly in a chosen area. This is its syntax (text inside < > should be replaced with something of your choice (explained below). Text inside [ ] is optional):spreadplayers <center> <spreadDistance> <maxRange> [under <maxHeight>] <respectTeams> <targets><center>: this is the center point of the area, without Y pos. You would most likely want it to be the point where the player stands (~ ~).
<spreadDistance>: this specifies the minimum distance between the entities that would be teleported. Since you are only telepoting a single player, this doesn't actually means anything, and you want to set it to 0.
<maxRange>: this is the furthest point the player could be teleported. I think the heighest possible value should be either 127, 255 or 256, you can check it out, so that's what you should do if you want to go wild. If you want to go really wild, you can do the /spreadplayers command more than once so the maximum value would be even greater,
under <maxHeight>: this is optional, and if you include it then there would be a maximum height (<maxHeight>) to the teleportation. By default the player would teleport on the top of the heighest block (most likely on the land, maybe on the top of a tree but always a place where it can see the sky). If you include a max height, if the top block is too high the player would teleport at the top block that isn't too high and the player has space to be there, so if the randomly chosen coordinates were on a mountain the player might teleport inside a cave because the mountain was too high,
<respectTeams>: if you choose this to be true, players on the same team would be teleported to the same coordinates (teams can be managed via /team). It's pretty obvious that this shouldn't bother you, so false would be best here.
<targets>: who you want to be teleported. @s marks the player that executes the command.

Here is an example /spreadplayers command. While I give you this command, please don't just copy/paste it. Read it, understand it and write it. This way you will learn to make better data packs and to use the /spreadplayers command, and this way the data pack can be considered to be your work and not mine. See how the command matches the syntax above.spreadplayers ~ ~ 0 127 false @sFor the blindness you can use a simple /effect command. Remember using @s would target the player which is executing the commands.
2
02/03/2021 10:54 pm
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
Use the /spreadplayers command to tp to a random position, and then literally after that apply the blindess
Example:
spreadplayers <x> <z> <spreadDistance> <maxRange> <respectTeams> @s
effect give @s minecraft:blindness 10 0 true


Note the true means the effect wont give off particles
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome