#How do I run a command once daily?
14 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
This is doable with command blocks and by extension with kubejs
time is measured in ticks. 1 second has 20 ticks
/scoreboard objectives add timer minecraft.custom:minecraft.play_time
This triggers a /summon after someone has spent 9999 ticks on the server
It resets and repeats itself
/execute as @a[scores={timer=9999..}] run summon minecraft:lightning_bolt
/execute as @a[scores={timer=9999..}] run scoreboard players set @s timer 0
Okay, but that would only allow me to run the command based on in-game time, and would include time that the player is offline too, wouldn't it?
the timer ticks when the player is online
if u use command blocks you'd have to forceload them or put them in spawnchunks
I'd prefer not to use command blocks, if possible. But how could I make it so the resulting command can only run once per IRL day?
my knowledge of scoreboard commands is kinda outdated (13 major versions) but what u could do is scoreboard players add dummy timer 1 in a repeating cmd block which adds 1 score per tick and implement a check to look at 'dummy's score and execute the command
im sure its not too hard to implement in kube
u could literally just use the command block logic with kubejs using server.runCommandSilent
Okay, but that still doesn't solve the problem of limiting the command to only running once per IRL day?
/scoreboard objectives add dayCheck dummy
/scoreboard players add dummy dayCheck 9999
/execute if score dummy timer >= dummy timer2 run summon minecraft:lightning_bolt
/execute if score dummy timer >= dummy timer2 run scoreboard players set dummy timer 0
that runs it as long as the server is running
Update: After considerable testing and tweaking, I think I've gotten everything working correctly in my script. Here's the code I came up with (this goes in server_scripts):
// Defines 'date' to be used for both PlayerEvents
const date = 'BLANK'
PlayerEvents.loggedIn(event => {
// Set player's time online back to 0 (necessary to set to 0 for new players)
event.player.persistentData.timeOnline = 0
// Set the current date as string
const today = new Date()
const day = today.getDate()
const month = today.getMonth() + 1
const year = today.getFullYear()
date = `${day}-${month}-${year}`
})
PlayerEvents.tick(event => {
// Cancel further checks if reward has already been claimed today (to minimize lag)
if (event.player.persistentData.lastReward === date) return
// If no reward was claimed by the player yet today, add 1 tick to time online
event.player.persistentData.timeOnline++
// Give reward after 20 consecutive minutes online
if (event.player.persistentData.timeOnline >= 24000) {
event.server.runCommand(`numismatics pay ${event.player.username} 1 COG`)
event.player.tell([
{ text: 'Thanks for playing, ', color: 'light_purple' },
{ text: event.player.username, color: 'aqua' },
{ text: '! You\'ve received ', color: 'light_purple' },
{ text: '1 cog', color: 'aqua' },
{ text: ' as your daily reward.', color: 'light_purple' }
])
// Mark reward as claimed for today's date, and reset time online value
event.player.persistentData.lastReward = date
event.player.persistentData.timeOnline = 0
console.log(`${event.player.username} received daily reward for ${event.player.persistentData.lastReward}.`)
}
})```