1

I'm making a Minecraft 1.16 datapack and I need to check if a player is in a certain location. I want to check for that condition every tick and then run a function when it is met.

I'm currently using this command: execute as @a[x = 10, y = 56, z = 42, dx = 8, dy = 10, dz = 0] run say Passed
The problem is that when the condition is met, the run say Passed part also executes every tick, which is not what I want.

When the condition is met, I want that command to only run once, and not every tick, while still checking the condition every tick. But, I also want the command to be able to run again after a second or so.

Could I do this by checking the condition every tick, then running a function that has a timer that only executes a command if it was previously executed 1 or more seconds ago?

5
  • if im understanding correctly you want it to check every tick but not run every tick the condition is met? – Topcode Dec 30 '20 at 14:43
  • So you want to continually check if the condition is met until the condition is met and then resume the check when the condition is no longer met? – randomuser922 Dec 30 '20 at 17:46
  • If you were making an adventure map or something of that nature, I would advise you to hook a command block to a monostable redstone circuit. But I don't think you can do that in a data pack. I suspect the answer you are looking for involves scoreboards in some fashion, but I don't know enough about how they work to provide a more specific answer. – Kevin Dec 30 '20 at 21:01
  • @Topcode Yes, that's what I'm looking for – Lapraniteon Dec 31 '20 at 20:48
  • @randomuser922 Pretty much yeah – Lapraniteon Dec 31 '20 at 20:48
1

you could make a scoreboard that stores a timer, that counts down to 0 and once that 0 is hit, the command can be run again setup:

/scoreboard objectives add Timers dummy

so you'll run these functions each tick:

execute if score FunctionX Timers matches 1.. run scoreboard players remove FunctionX Timers 1
execute if score FunctionX Timers matches 0 run execute as @a[x = 10, y = 56, z = 42, dx = 8, dy = 10, dz = 0] run function <namespace>:passed

and in passed.mcfunction

scoreboard players add FunctionX Timers 20
say passed

this will make the command run only every 20 gameticks

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.