This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Redd56's profile picture

rl time and date, and using it as a basis for in game events

Started by Redd56, 21 March 2018 - 07:49 AM
Redd56 #1
Posted 21 March 2018 - 08:49 AM
so i used a bunch of code from someone else on the site to import the date and time but i dont know lua, i only know a bit of c++
Basicly what i want to use this for is so that at a certain time(s) i can send out a redstone signal to a command block to restart my server.


anyone able to help?
Bomb Bloke #2
Posted 21 March 2018 - 09:28 AM
If you're on ComputerCraft 1.7 or later, you may be better off using a Command Computer. This would lower the risk of a player accessing and activating the command block directly (some other mods these days let them drill through bedrock), and there's also the whole issue where turning on a redstone signal may send your server into a reboot loop (as the code to turn the signal off may never get a chance to run).

Although, there's no command block command to restart a server in vanilla, and Command Computers don't always get access to additional commands added by other mods.

How complex your code will be hinges on whether the date matters at all, whether you want to set more than one restart point in a day, whether those restart points will be evenly spaced or not, and whether you want to delay restarting when players are online (seriously, most servers don't need daily reboots, and doing them while people are trying to play is more annoying than it is practical).

A really simple way of doing it would be to just say "let's have the server reboot every three hours", which would just be a matter of:

rs.setOutput("back", false)

sleep(10800) --# 10,800 seconds == three hours

rs.setOutput("back", true)

There are server extensions which could handle this better and more simply than automated server commands can, though, including the whole "don't reboot while players are online" thing. I'm afraid I don't have direct experience with these, but they're worth researching.
Redd56 #3
Posted 21 March 2018 - 07:45 PM
i was more wanting to have it happen at a certain time of day, as the reboot actualy takes time itself, also how would i have the program always running
Redd56 #4
Posted 21 March 2018 - 09:21 PM
here let me post a link to the original code

http://www.computercraft.info/forums2/index.php?/topic/1415-fetch-rl-timedate-open-church-only-on-sunday-activate-virus-on-wednesday-log-user-intrusions-with-a-rl-datetime

This is the code i used, (the stuff in the spoiler) i am mostly just wanting to find a way to extract the time out of it every so often and set up a timed signal for it.
Lupus590 #5
Posted 22 March 2018 - 09:38 AM
If you are on latest CC you may want to try: https://github.com/dan200/ComputerCraft/pull/183#issuecomment-299637976
Redd56 #6
Posted 24 March 2018 - 10:19 PM
If you are on latest CC you may want to try: https://github.com/d...mment-299637976
unfortunately im playing back in 1.7.10 cause this wing of my pack has mods like icbm, which are stuck in 1.7.10
Lupus590 #7
Posted 24 March 2018 - 11:45 PM
I can only suggest working through this list, creating your own server which provides time via http, or making a mod which allows CC to get the time from MC's host.