Hey guys welcome back to the timber forge today i have a pretty simple but also useful tutorial about how to create timers delays and command sequences by using commands inside of a data pack or using command blocks i do recommend that you use a data pack Though and if you don’t know how to create a data pack make sure to check out more information down in the description below now before i go over the different ways that you could create timers and delays i first want to go over the schedule command which you can use to create some Very simple delays so the schedule command the main thing to know about it is that there’s two modes so you have schedule and then clear you could do to clear any schedules that you have already created but i’m not going to go into that because it’s pretty self-explanatory So schedule function and you pick the name of the function so for me i have timers and i have global single this is literally just a say command so if you go check it it’s literally just say global single and the reason you need a function is just because That’s how the schedule command works you can’t schedule individual commands only entire functions so back inside of minecraft if i schedule a function which just leads to a say command i can choose the amount of time so i could do days seconds or ticks and if you remember 20 ticks makes one second in terms of command ticks so let’s say i want uh three seconds i’ll do three seconds and then you have append or replace basically append creates a new timer every single time you run the command and i run this three times you’ll notice it says global single Three times because it ran three independent timers it’s kind of like if you were to run this redstone example if i press the button and then i press the button again you’ll notice it goes on twice since it’s two separate timers now on the other hand if you do replace And i run this three times you’ll notice that it only runs the command once and that’s because it’s removing any previous timers that were going for this specific function it replaces them with the new one and to go with the redstone analogy replace would be like if i press the Button but then i press the button again it would delete the old timer and activate a new timer so as you saw the first way to create a command delay is to just use a schedule function command but this also has some limits which i’ll go into after this But i also want to show you how to create a scheduling function that repeats constantly as soon as you load the data pack and to do that you want to create a new function which you’ll be using for the repeating whatever you’re trying to do and inside of there you’ll basically have it Schedule itself so you do schedule function and then just link it to the function that this is inside of and then put your delay and put replace and i’ll show you why you need to do replace then inside of the function just put whatever you want to repeat For me i’m just going to use a say command since that’s a simple example so if i go into minecraft and reload you’ll notice that it won’t actually be working and the reason for that is the function has to schedule itself but in order to schedule itself it has to Run in the first place so all you have to do is go into the load command and make sure to run the function there so if i do function timers global repeat then when i reload the data pack it’s going to run that the first time and then it’s Going to keep repeating itself and now the reason that i needed to use replace is because this function is going to be run every single time that you reload the data pack so if i didn’t do replace this would no longer run only once every second since It would create new timers every time i reload the data pack by putting replace i make sure that there’s only one timer running at all times now even though the schedule function command is super easy to implement it’s also very limiting since you can’t have separate and independent timers for different entities So for example with a normal command if i were to do execute as at s run function timers global single which is just the say command now where to run that you’ll notice that it says timber forge global single because i was running the command so i said global single Now it works differently if i were to run a schedule command so execute as s run schedule function and then i’ll put a delay of one second if i were to run that you’ll notice that the server says global single not me even though i specified i’m executing as myself And that’s one of the limitations of the schedule function is that you can’t specify per entity or basically change any information about where or who is running the function that means for example if i wanted creepers to have separate delays for their explosions like a custom creeper mob I wouldn’t be able to use the schedule function command to give those creepers separate delays what the schedule command is useful for is for any types of delays or timers that run over your entire data pack so for example if you had a custom mob and it attempts to spawn And replace a certain amount of mobs every like 10 seconds or so that’s where you could use the schedule function command and another limitation is that you can’t really change the length of the schedule once you schedule it it’s set for that length you can cut it off early but you Can’t really extend the schedule function or anything like that a method of creating timers and delays which gives you a lot more flexibility and control is by using scoreboards so to start off you have to create the actual scoreboard objective obviously so in your load function do scoreboard Objectives add and then name it whatever you want and then just put dummy afterwards which indicates that only commands are going to manipulate the scoreboard and how it’s going to work is that we’re going to be using a command to set our score to a certain number and If it’s above zero that’ll indicate to our other commands that it should start counting down all the way down to zero and right before it hits zero it’ll detect that and run whatever function that we want so right now it’s up at 40 and we want it to count down Now in your loop function or what you probably should do is be running a separate function from your loop function but for the shape of example i’m just going to be putting it in the loop function so you first want to have it count down so scoreboard players Remove and then you put the entities that you want to remove the score from and it says players but if you’re new to the scoreboard command that doesn’t actually mean that only players could do it basically any entity could have a scoreboard so scoreboard players remove any entities that have A score for your timer that timer name that you set over one that’s what the dot dot means it means one or more so if you have greater than zero score then it will remove one from your timer one objective what will happen is that it’ll count down to zero so Anytime i set it to 40 it’s going to count back down to zero and it’ll stop or if i set it to 60 or whatever and as you can see this will give you a lot more control over the length of your delay so let’s say it’s 60 but then you want to Reset it in the middle you could also do that but now let’s say you want it to actually do something obviously what you have to do is just detect if your scoreboard has counted all the way down or not so i do execute as all entities that have a score Of exactly one then i will go to the position of that entity and run my function timer1 result which is literally just a say command and the reason i did one is because it’s going to count down to zero so once it hits zero it’s going to stay At zero and i don’t want this to repeat while it’s at zero so i just did it at one you could also make it count up if you want but i find that it’s easier to understand the change in length if you make it count down since you’ll always know it’s going To execute at one and also you don’t need it to only run at one you can make it run at any point along the sequence you could have certain commands that run halfway through or a third of the way through or a quarter of the way through all just by changing which number So i could set this to run at 10 and then i could maybe set another one to run at 20 or something like that so if i go into my minecraft right now you’ll notice anytime i set my score above zero it’s going to count down and it’s going To execute right when the timer runs out and as you can see it’s actually running as myself so i’m able to do it for multiple entities if i had three creepers here i could have three creepers with their own different timer score and if you want your scoreboard timer to Constantly repeat and not just do a single delay then just make sure to go to your function that runs after your timer runs out and make sure that it resets itself so if you’re counting down what you want to do is make sure to do scoreboard players set At s because that’s probably who’s running the function then your timer one or whatever and then set the score to whatever you want the delay to be this way as soon as your timer runs out it’ll run your function run your results and also it’ll reset your timer so it’ll continue going And to make sure that it starts the first time you just have to make sure that somewhere you manually set the score to your high number so that could be when you summon the custom mob for example if you’re doing a custom mob or let’s say you’re going to have a mob That flashes or something once it starts attacking then you would want to set the score as soon as it starts attacking i hope you guys found this video helpful make sure to like comment and subscribe for more data pack content if you have any feedback or suggestions For future tutorial videos make sure to leave a comment down in the description below [Applause] Video Information
This video, titled ‘EASY Timers with Commands || Minecraft Data Pack Tutorial’, was uploaded by Timber Forge on 2021-02-03 19:00:14. It has garnered 45112 views and 907 likes. The duration of the video is 00:09:36 or 576 seconds.
This simple video goes over how to make timers or delays with the schedule command and with scoreboards. Something I forgot to mention is that you can use fake player names in scoreboards, instead of targeting an entity. Just put a fake player name in the target selector. (Something like .attackSpeed)
SPECIAL THANKS TO ApexHosting! They have amazing servers and great service. Use this affiliate link to get your own server and to support me as well: https://billing.apexminecrafthosting.com/aff.php?aff=4317
Check out my new website about data pack making! Start at “Essential Skills” if you are new! https://tinyurl.com/timberforge
0:00 – Intro 0:18 – Schedule Command 2:13 – Repeating Schedule Function 3:36 – Limitations and Uses Schedule 5:13 – Delays with scoreboards 8:18 – Scoreboard Timers (Repeating)
Join our discord for help and inspiration! https://discord.gg/bwBsSbr
#datapacks #minecraftmods #minecraftdatapacks