#how to loop something / make it run multiple times / make it run for multiple seconds
1 messages · Page 1 of 1 (latest)
💬 While you wait, take this time to provide more context and details.
🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you
✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve
I see what you tried to do, but Minecraft functions are basically just commands in a text file.
oh
They don't work like most programming languages
i believe so yeah
heres the code without the for loop stuff
If i dont reply i have to really quickly do something irl thats why
what is that at the end of the command?
ah
Did I understand that right, that for every entity that enters that 5 block radius, the effect clear command should run 3 seconds?
Yeah
So for 3 seconds it would constantly clear effects
Even if they get out of the 5 block radius
I tried to use a for loop as u saw but didnt really work lmao 😂
Why do you need it to run for 3 seconds?
Im trying to make it so in combat it cancels healing
But the issue is
The mod im using it with knocks the player back a lot so it doesnt have much effect
I was thinking if it would run it 3 times or for 3 seconds itd have more of an effect and actually stop healing
Idk if i can explain it well enough
What you need:
- a scoreboard that acts like a timer for seconds
- a schedule function that runs every second to reduce the timer.
- a tick function that sets the score of every player near you
Do you already have a tick and load function?
Yeah i have tick and load
Load does tellraw every time i reload/load the datapack
Scoreboards is a good thing i need to learn them anyways so its good its a must for the project haha
First you need to add a command in the load function that adds a dummy scoreboard to your world.
scoreboard objectives add levent.heal_block_timer dummy
this adds a new dummy scoreboard objective (dummy means, it is not linked to a statistic) with the name levent.heal_block_timer
next, we add a command to the tick function, that sets the score of every player that is near another player with the Sakura tag to 3.
execute at @a[tag=Sakura] as @a[tag=!Sakura,distance=..5] run scoreboard players set @s levent.heal_block_timer 3
Add a second command to the tick function that clears the effect as long as the player has a score over 0.
effect clear @a[scores={levent.heal_block_timer=1..}] <effect id>
Oh crapp
Yo thank you so much man wth
I love this community already 😭
Ill put them in as soon as im back on pc
That's good to hear
Last thing, create a new function. In there, add a command that reduces the timer score by one
scoreboard players remove @a[scores={levent.heal_block_timer=1..}] levent.heal_block_timer 1
and a second command that calls this function again in 1 second
schedule function <the name of this function> 1s
On its own, this function will do nothing, so to start the cycle call this function once in the load function.
thats all?
yep
It's past midnight where I live, so I might not be here to help you today if you get stuck.
the name of the function in this instance would be score right?
the names can be whatever you want them to be. limitations are [a-z,0-1,_]
no spaces or capital letters
don't forget to save and do /reload
only if you set its to be visible on the sidebar
alright
scoreboard objectives setdisplay sidebar <objective name or no name to remove it>
that's the scoreboard type. The objective name is levent.heal_block_timer
honestly
im gonna leave it be how it is
ill test it tomorrow if i can and i think thats best for both of us
it's late for both of us so i dont wanna keep you up lol
I'll finish my project first anyways
well, regardless i'd be hindering you lol
once again tysm i'll let you know tomorrow if i cant get it to work lol
ill test around with it a bit more rn
👍
Yeah I changed the name because apparently the objective cant be bigger than 16 characters n stuff so i changed some stuff around, pretty sure it works but i'll hit you up tomorrow for sure. have a great night tysm for the help!!
The objective can be more than 16 characters long
They are in an older version where that was not the case
If you've not made many datapacks, you might not be familiar with raycasting. It's a really useful tool which we can use to essentially find where the player is looking and then do stuff (such as spawn explosions 😎).
To create a raycast, we can use a recursive function. A recursive function is a function which will run itself over and over again. In our case, the function will run itself 0.1 blocks forward (^ ^ ^0.1) each time, and repeat until it hits something. It will do this all within the same tick - but bear in mind that the bigger the distance, the more laggy it will be. We can stop this unwanted behaviour by putting a distance limit on the raycast - each time it runs itself, it will count down on a scoreboard, and only repeat if it hasn't hit the limit.
start_raycast function:
# Set the distance limit on the raycast. (10 x limit in blocks, so 1000 would be 100 blocks)
scoreboard players set .limit <any objective> 1000
# Start the raycast
execute at @s anchored eyes positioned ^ ^ ^.1 run function <namespace>:raycast
raycast function:
# Remove one from the limit
scoreboard players remove .limit <objective> 1
# Optional - place a particle, to make the raycast leave a trail
particle minecraft:dust 1 0 0 1 ~ ~ ~
# If the raycast has hit a block, do something
execute unless block ~ ~ ~ #<namespace>:pass_through run setblock ~ ~ ~ diamond_block
# If the raycast hasn't hit a block, continue, but only if the limit is 1 or more (1..)
execute if block ~ ~ ~ #<namespace>:pass_through positioned ^ ^ ^0.1 if score .limit <objective> matches 1.. run function <namespace>:raycast```
namespace/tags/blocks/**pass_through**.json:```
{
"replace": false,
"values": [
"minecraft:air",
"minecraft:cave_air",
"minecraft:void_air"
]
}
This should be it! Make sure you add all the functions, and fill in all the blanks (indicated by <this>). Then, you can run the start_raycast function as a player, and it should work.
yo Hedean
it wont work
It goes from 3 to 2 and then goes right back up to 3 even if im far away from them, i dont wanna ping u cuz yeah but hopefully u see it 🙏
i think we forgot to define a distance here
Fixed
love you
my real goat
whats wrong here?
nvm it works
i love you so much no homo
It just doesn't recognise the custom effect

say it back
I love you too no homo
hey i got more issues for you to solve 😂
the predicate im trying to use
is sneak.json has this:
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"flags": {
"is_sneaking": true
}
}
}
im trying to make it so you get regen 1 until you stop crouching basically
wake up Hede
😭
I was driving my parents to a party. I'll help you in a minute.
All good
i deadass erased all the code in that one file
and it still said the same stuff
let me re-make it
looks alright to me (tip, you don't have to make two files, you can just check unless predicate levent:is_sneak)
What does the log say?
the code just doesnt work
i think this is from the old one
yeah
the current files called "reg.mcfunction"
in the logs, it should show an error why it doesn't work
The logs are where Minecraft displays errors when something goes wrong and can thus help you gain information about why something isn't working for you!
To open the logs:
- Enable logs in the Minecraft Launcher
- Start your game (or restart it if you already have an open instance)
- Enjoy spotting errors getting much easier!
time to restart
💀
oh...
wait..
nvm
i was gonna say i forgot to /reload but i didnt
oh crap
it worekd?
worked* i think?
i did /function the name of function
im crouching but it doesnt work again
hm one sec
ill get logs to open
Alright re-launching MC
opening world
crouching does nothing in logs @hollow meadow
i did /function reg
The error should occur when mc is parsing the files further up in the logs (if there is an error)
oh
theres yellow text, but its either other mods or completely unrelated stuff
i dont think the codes giving out errors
could you send the pack, so I can take a better look?
Yup
one second
Sorry for bothering a lot btw lol
if you're busy with anything else just drop this
It's fine, I wanted to be a helper.
i could delete cut.mcfunction honestly since the code you made already replaces it
I've seen other people use scoreboards to detect sneaking but idk
this should theoretically work
oh crap
i found the "problem"
im just stupid augh
i put a repeating command block down and did /function function
Does it work now?
yeah
🎉
i would need to put it into load.mcfunction or something to avoid having a repeating command block right?
You mean the timer score reduce function?
oh nvm
i meant
you know how i need to put the /function reg in a repeating command block for it to be active 24/7.
I just need to put it in tick.mcfunction right?
yes
yeah alright
one last issue 😭
the thing with the regen effect is when its a repeating command block or a tickmcfunction it constantly gives me regen which stacks (in a way) so even if its regen 1 it heals you to max HP instantaneously
the tick function executes every tick (20 times a second)
the load function executes once when loading the world or using /reload
You can apply it just once, with infinite duration.
how would i do that in a tick function
like how do i give inf duration
what number would it be?
you don't put it into the tick function. Use an advancement with the tick condition. from the image, it looks like the effects already have infinite duration.
Yust make sure to revoke the advancement after the player dies
for 1.16.5, I have to test something
no idea how i got it ngl
I don't know if i understood correctly sorry im slow w this rn ngl but:
When they get a certain advancement they get reg 1 constantly and when they dont have it they just dont get anything right?
effect give @s <effect> <duration>
the max duration is the int limit.
The tick condition tries to give the player the advancement every tick (if they trigger once, they have to be reactivated manually). As a reward for the advancement you can give the player xp, items, or, what we need, execute a function.
Awesome website with generators for almost everything. Also contains a technical changelog for new versions, guides on how to use some features, a performance report inspector and more!
Full list of generators: Loot Tables, Predicates, Item Modifiers, Advancements, Recipes, Text Components, Damage Types, Chat Types, Trim Materials, Trim Patterns, pack.mcmetas, Dimensions, Dimension Types, Biomes, Configured Carvers, Configured Features, Placed Features, Density Functions, Noise, Noise Settings, Structures, Structure Sets, Processor Lists, Template Pools, World Presets, Flat World Presets, World Settings, Block Tags, Entity Type Tags, Fluid Tags, Game Event Tags, Item Tags, Biome Tags, Structure Tags, Blockstates, Models, Fonts, Atlases
hold on i gotta lock in and stop the music for this 😂
{
"criteria": {
"requirement": {
"trigger": "minecraft:tick",
"conditions": {
"player": {
"nbt": "Tags:["Sakura"]"
}
}
}
},
"rewards": {
"function": "levent:subskills/reg"
}
}
i got this
The function that will be rewarded, has all the effects the player is meant to get
i have to make my own advancement right like
and then put the code above in there right?
yes
To add advancements, first create a folder named advancements inside the namespace folder. Then, create a file named (advancement_name).json (You can't put spaces in the file name. Use lowercase letters in the file name). in this folder or in any of its subfolders. This will be your advancement file. Your advancement will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) if the file is located in a subfolder.
1 second
idk why but VSC is being reaaaly slow with creation today
?
its creating files slower than usual
and scripts
one sec advancement files here
i created a file named "toji.json"
and ill put the code in there
when they have the advancement theyd get the regen once and if they stop crouching the advancement gets removed correct?
(theyd get the advancement once they crouch)
if i understood everything correctly that's what we're aiming for rn
oh fixed it
i copied it wrong mb
The advancement executes the function as soon as the player has the Sakura tag. You have to manually revoke the advancement with advancement revoke @s only <advancement path>
hm okay
Is that when thy should get the effects?
If they stop, should the effects go away?
They should get regeneration when they start crouching, and when they stop they should be cleared from
yeah
exactly
ok, that makes it easier than I thought
You need two advancements and two functions
the regen isnt healing me though
Alright on it
{
"criteria": {
"requirement": {
"trigger": "minecraft:tick",
"conditions": {
"player": {
"nbt": "Tags:[\"Sakura\"]",
"flags": {
"is_sneaking": true
}
}
}
}
},
"rewards": {
"function": "minecraft:regen function"
}
}
this is ow the advancement for giving the effects should look.
The function then gives the effects and revokes the advancement that removes the effects.
The remove advancement and function are just the inverse of that.
I forgot something, fixed the json
so
removing the advancement would look like this right:
advancement revoke @s levent:advancements/toji
you don't need to include the advancements folder in the path. Mc automatically recognizes files in that folder as advancements.
so just levent:toji
yes
do i replace this one with that?
this is the one that gives the effects and revokes the advancement
yeah
It sould revoke the advancement that does the opposite
yeah so the one that stops regen
alright i think i got it
ill come back here later with news of it workin or not
(like 5 mins cuz of how slow vsc is being)
alright
about to test it
alright i messed something up apparently
im gonna finish my food n take a mini break and then come back 😭
quick question
{
"criteria": {
"requirement": {
"trigger": "minecraft:tick",
"conditions": {
"player": {
"nbt": "Tags:["Sakura"]",
"flags": {
"is_sneaking": true
}
}
}
}
},
"rewards": {
"function": "levent:subskills/reg"
}
}
is this advancement automatically given when the player crouches or how are they supposed to get i
it*
Advancements are granted as soon as all conditions are met.
int this case, if the player has the Sakura tag and is sneaking
i dont know if the game sees the advancement
i tried sneaking and unsneaking and then even ran /advancement revoke levent_34 only levent:toji
but it just says "unknown advancement"
i mightve messed up while setting the advancement folder up maybe
if it isn't listed in the chat then there is something wrong with it. Broken advancements are usually displayed in the logs.
When you work with datapacks and mods, I suggest always having it open
You're right
ay i think im gonna work on this tomorrow or maybe later
tysm for the help ill come back again if i need help lmao 😂
actual goat tho
I'll be here and help, It's weekend, so I might be awake till 6 am or some stupid time like that
damn man
hj/
heres the file btw
i prob wont work on it today cuz i cant be asked to figure out the issue at midnight 😭
hopefully ur on tomorrow lol
Does the reverse_curse_technique effect affect every entity or just players?
every entity
like
its basically binded to a key
and if you hold the key down it'll give you the effect
and certain entities (mobs) can use it
I'll add a tag, that excludes non living entities, ok?
i forgot to work on it btw ty for reminding
Sure
the RCT stuff works fine btw
its just the crouch healing that isnt working rn
I found one or two bug and fixed them
marry me
i mean
send the new file
i meant to say the latter, definitely
ill look through and see what i did wrong, was it in the advancements?
by the way, i was planning to make it effect mobs too but when i turned it into @e and not @a there was like 300 different numbers on the scoreboard
and at the time i hadn't tested if the count down was working yet so i turned it back into @a and tested it with some friends and after i fixed it i never tried it again with @e
idk if thats helpful to you
Here you go. I added a few comments to explain stuff.
I accounted for that in all the necessary selectors
Btw if you ever need some tags in the future:
A libary of (entity, block, item, etc.) tags containing probably every tag you'll ever need!
ty
whens the baby shower
Hede
i got bad news...
the server i was making this for is updating to 1.20
do i have to re-code everything or can i just import it into 1.20
what is this btw
yo wth this man put notes down on everything 😭
oh, that is something I added but removed, because I had a thinking error
actual goat
alright
change it to #taglib:non_living
yeah
also, the commented out command above that is not used anymore
luckily you didn't use any now deprecated code
minecraft regens so confusing
🙏
yeah regen is working
im gonna put it on regen 2 to see the effect clearer
ily actual goat
<= me irl
ong
me to you
(im glazing)
Hede
i could add slowness too right
testing it
out
rn
works
ily actual goat
if thou art done here please run /resolve to close the channel
👍