Add Factorio/control.lua
Custom commands and MOTD both confirmed to work. Random fact every 30 min and save warning not seen.
This commit is contained in:
		
							parent
							
								
									f89048c4c9
								
							
						
					
					
						commit
						7eaa3521dc
					
				
					 1 changed files with 165 additions and 0 deletions
				
			
		
							
								
								
									
										165
									
								
								Factorio/control.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								Factorio/control.lua
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,165 @@
 | 
				
			||||||
 | 
					local handler = require("event_handler")
 | 
				
			||||||
 | 
					handler.add_lib(require("freeplay"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if script.active_mods["space-age"] then
 | 
				
			||||||
 | 
					  handler.add_lib(require("space-finish-script"))
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					  handler.add_lib(require("silo-script"))
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Define the server Message of the Day (MOTD)
 | 
				
			||||||
 | 
					local MOTD = [[
 | 
				
			||||||
 | 
					Welcome to Clarth's Test Server!
 | 
				
			||||||
 | 
					Enjoy your stay.
 | 
				
			||||||
 | 
					If you need admin powers, talk to Clarth.
 | 
				
			||||||
 | 
					Teleport command and teleporters are your friend, spread out.
 | 
				
			||||||
 | 
					]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Function to send the MOTD to a player
 | 
				
			||||||
 | 
					local function send_motd(player)
 | 
				
			||||||
 | 
					    player.print(MOTD, {r = 0.5, g = 0.75, b = 1}) -- Customize text color if desired
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Event handler: Show MOTD when a player joins the game
 | 
				
			||||||
 | 
					script.on_event(defines.events.on_player_joined_game, function(event)
 | 
				
			||||||
 | 
					    local player = game.get_player(event.player_index)
 | 
				
			||||||
 | 
					    if player then
 | 
				
			||||||
 | 
					        send_motd(player)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					script.on_event(defines.events.on_tick, function(event)
 | 
				
			||||||
 | 
					    -- Define the autosave interval (in ticks)
 | 
				
			||||||
 | 
					    local autosave_interval_ticks = 10 * 60 * 60 -- 10 minutes = 36000 ticks
 | 
				
			||||||
 | 
					    local warning_time_ticks = 30 * 60 -- 30 seconds = 1800 ticks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    -- Check if the current tick is close to an autosave
 | 
				
			||||||
 | 
					    local current_tick = game.tick
 | 
				
			||||||
 | 
					    local ticks_until_next_save = autosave_interval_ticks - (current_tick % autosave_interval_ticks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ticks_until_next_save == warning_time_ticks then
 | 
				
			||||||
 | 
					        -- Notify players 30 seconds before the autosave
 | 
				
			||||||
 | 
					        game.print("[Server]: Autosave will occur in 30 seconds. Please prepare!")
 | 
				
			||||||
 | 
					    elseif ticks_until_next_save == 0 then
 | 
				
			||||||
 | 
					        -- Notify players when the autosave happens
 | 
				
			||||||
 | 
					        game.print("[Server]: Autosave in progress. Hang tight!")
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local fun_facts = {
 | 
				
			||||||
 | 
					 "Did you know? The first version of Factorio was released in 2012 as a crowdfunding project!",
 | 
				
			||||||
 | 
					    "Fun fact: Biters have a family too. But they might not appreciate your pollution...",
 | 
				
			||||||
 | 
					    "Remember: The quickest way to fix a problem is to add more belts.",
 | 
				
			||||||
 | 
					    "Nuclear power is great, but don't forget to wear your lead pants!",
 | 
				
			||||||
 | 
					    "In Factorio, spaghetti is not just a meal. It's a way of life.",
 | 
				
			||||||
 | 
					    "Building trains is fun... until they hit you. Look both ways before crossing!",
 | 
				
			||||||
 | 
					    "Factorio was inspired by games like SimCity, Civilization, and Transport Tycoon.",
 | 
				
			||||||
 | 
					    "Why automate? Because doing things manually is for *non-engineers*!",
 | 
				
			||||||
 | 
					    "Pollution may anger the biters, but it sure makes the factory look cool.",
 | 
				
			||||||
 | 
					    "There are over 60 achievements in Factorio. How many do you have?",
 | 
				
			||||||
 | 
					    "If you're stuck: Always remember, there’s no problem that can't be solved with more assemblers.",
 | 
				
			||||||
 | 
					    "The factory must grow, but so do the biters!",
 | 
				
			||||||
 | 
					    "When in doubt, over-engineer everything. It's the Factorio way.",
 | 
				
			||||||
 | 
					    "Factorio has been played by over 3 million people worldwide!",
 | 
				
			||||||
 | 
					    "Never forget: Biters are just nature’s way of saying 'please stop polluting.'",
 | 
				
			||||||
 | 
					    "The devs behind Factorio (Wube Software) are based in Prague, Czech Republic.",
 | 
				
			||||||
 | 
					    "Building circuits is great! ...until you try debugging them at 2 AM.",
 | 
				
			||||||
 | 
					    "Factorio teaches a life lesson: Logistics are the key to success!",
 | 
				
			||||||
 | 
					    "Why did the engineer cross the belt? To get to the other inserter.",
 | 
				
			||||||
 | 
					    "When you feel overwhelmed, just remember: You started with one burner miner drill.",
 | 
				
			||||||
 | 
					    "Splitters are your best friend. Cherish them.",
 | 
				
			||||||
 | 
					    "Factorio is like chess, but with explosions and trains.",
 | 
				
			||||||
 | 
					    "The game's engine was built from scratch to handle massive factories.",
 | 
				
			||||||
 | 
					    "Ever notice? Your factory makes pollution, but your bots don’t care.",
 | 
				
			||||||
 | 
					    "You’re not overthinking your factory. You’re just *optimizing* it.",
 | 
				
			||||||
 | 
					    "Real engineers build their first rocket... and immediately start building the second.",
 | 
				
			||||||
 | 
					    "Factorio speedrunners can launch a rocket in under 2 hours!",
 | 
				
			||||||
 | 
					    "It's not a bug if it works (sometimes).",
 | 
				
			||||||
 | 
					    "Who needs brakes on trains? Just build another train stop!",
 | 
				
			||||||
 | 
					    "The only thing scarier than a horde of biters? Your power going out mid-battle.",
 | 
				
			||||||
 | 
					    "Factorio has been in development longer than most AAA games.",
 | 
				
			||||||
 | 
					    "Spaghetti factories may be inefficient, but they’re beautiful.",
 | 
				
			||||||
 | 
					    "Factorio’s auto-save exists for a reason. Don’t forget it.",
 | 
				
			||||||
 | 
					    "If at first you don’t succeed, build faster belts.",
 | 
				
			||||||
 | 
					    "Trees are friends... until they block your factory.",
 | 
				
			||||||
 | 
					    "Factorio’s map generator can create maps the size of Earth (but who has time?).",
 | 
				
			||||||
 | 
					    "When in doubt, blame the biters.",
 | 
				
			||||||
 | 
					    "No problem is too big if you have enough construction bots.",
 | 
				
			||||||
 | 
					    "Your factory doesn’t have bugs; it has *features*.",
 | 
				
			||||||
 | 
					    "Take breaks. Your factory won’t build itself, but your brain needs a rest!",
 | 
				
			||||||
 | 
					    "The longest recorded Factorio play session was over 3 days straight!",
 | 
				
			||||||
 | 
					    "There are more than 50 different types of trains in Factorio, and none of them have seatbelts!",
 | 
				
			||||||
 | 
					    "Even the best engineers sometimes forget to turn on their power grid.",
 | 
				
			||||||
 | 
					    "Try placing a few trees in a circle. You might see something interesting...",
 | 
				
			||||||
 | 
					    "There’s a hidden achievement for ‘completing the game without using any belts.’ Good luck with that!",
 | 
				
			||||||
 | 
					    "When the going gets tough, remember: Your factory can always be bigger!",
 | 
				
			||||||
 | 
					    "You can rename any train in Factorio. What will you name yours?",
 | 
				
			||||||
 | 
					    "The Factorio wiki contains more information than some university textbooks!",
 | 
				
			||||||
 | 
					    "If you’re ever feeling lost, try using the map preview to get your bearings.",
 | 
				
			||||||
 | 
					    "Eating pizza is great, but eating pizza while building your factory is even better!",
 | 
				
			||||||
 | 
					    "You can achieve *maximum* productivity with a single well-placed power pole. It's magic.",
 | 
				
			||||||
 | 
					    "Try turning off your lights at night and see how it changes the game. Hint: It's a bit dark.",
 | 
				
			||||||
 | 
					    "Some players have completely automated their entire game, from train schedules to rocket launches!",
 | 
				
			||||||
 | 
					    "Build with efficiency, but never underestimate the power of a well-placed flamethrower!",
 | 
				
			||||||
 | 
					    "Factorio is not just about building factories, it’s about building friendships... and lots of conveyor belts.",
 | 
				
			||||||
 | 
					    "If you find a secret chest in the game, it might contain a hilarious surprise!",
 | 
				
			||||||
 | 
					    "Factorio has been in continuous development since its alpha release, with hundreds of updates improving gameplay.",
 | 
				
			||||||
 | 
					    "Always keep a backup of your game save. You never know when a biter will wreck your day!",
 | 
				
			||||||
 | 
					    "Don’t forget to hydrate while playing! Your factory might need more water than you think.",
 | 
				
			||||||
 | 
					    "The devs have released mods that allow you to play Factorio in VR. Talk about immersive!",
 | 
				
			||||||
 | 
					    "Try placing an enormous amount of electric poles... and wait for the electricity to flow!",
 | 
				
			||||||
 | 
					    "If a rocket launch takes too long, maybe you need to work on your factory logistics a little more.",
 | 
				
			||||||
 | 
					    "A single train can carry more resources than a hundred chests. But where’s the fun in that?",
 | 
				
			||||||
 | 
					    "If you're ever stuck, you can always check the forums for advice or a quick fix to your problem.",
 | 
				
			||||||
 | 
					    "Your factory might be beautiful, but is it *efficient*? Check out some optimization guides!",
 | 
				
			||||||
 | 
					    "If you place an entire factory inside a giant circle of walls, you'll get a cool view of your progress.",
 | 
				
			||||||
 | 
					    "You can automate the creation of solar panels and wind turbines to create an environmentally friendly factory.",
 | 
				
			||||||
 | 
					    "A factory is like a living organism. It needs food (resources) and power to survive!",
 | 
				
			||||||
 | 
					    "Factorio was named after the Latin word for ‘factory’ because it’s all about building systems.",
 | 
				
			||||||
 | 
					    "Take a step back and admire your factory every once in a while. It's a work of art!",
 | 
				
			||||||
 | 
					    "Trains are faster than belts. But they can be tricky. Use them wisely!",
 | 
				
			||||||
 | 
					    "Some players have created entire computer systems within Factorio? Talk about an engineering challenge!",
 | 
				
			||||||
 | 
					    "The Factorio wiki has thousands of pages filled with in-depth guides to help you optimize your factory.",
 | 
				
			||||||
 | 
					    "Try taking a break by building a giant statue out of stone bricks. It’s a good stress reliever.",
 | 
				
			||||||
 | 
					    "Taking breaks isn’t just for your health, it’s for your factory’s success. Don’t burn out!"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local announcement_interval_ticks = 30 * 60 * 60 -- 30 minutes = 108,000 ticks
 | 
				
			||||||
 | 
					local next_announcement_tick = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Initialize next_announcement_tick to a valid value
 | 
				
			||||||
 | 
					script.on_init(function()
 | 
				
			||||||
 | 
					    next_announcement_tick = game.tick + announcement_interval_ticks
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Event handler for on_tick
 | 
				
			||||||
 | 
					script.on_event(defines.events.on_tick, function(event)
 | 
				
			||||||
 | 
					    -- Ensure next_announcement_tick is a valid number before using it
 | 
				
			||||||
 | 
					    if next_announcement_tick and game.tick >= next_announcement_tick then
 | 
				
			||||||
 | 
					        -- Pick a random announcement from fun facts
 | 
				
			||||||
 | 
					        local message = fun_facts[math.random(#fun_facts)]
 | 
				
			||||||
 | 
					        -- Send it to all players
 | 
				
			||||||
 | 
					        game.print("[Fun Fact]: " .. message)
 | 
				
			||||||
 | 
					        -- Set the next announcement time
 | 
				
			||||||
 | 
					        next_announcement_tick = game.tick + announcement_interval_ticks
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Register the /funfact command
 | 
				
			||||||
 | 
					commands.add_command("funfact", "Get a random fun fact", function(event)
 | 
				
			||||||
 | 
					    local player = game.get_player(event.player_index)
 | 
				
			||||||
 | 
					    if player then
 | 
				
			||||||
 | 
					        local random_fact = fun_facts[math.random(#fun_facts)]
 | 
				
			||||||
 | 
					        player.print("[Server]: " .. random_fact)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Register the /discord command
 | 
				
			||||||
 | 
					commands.add_command("discord", "Get the Discord link", function(event)
 | 
				
			||||||
 | 
					    local player = game.get_player(event.player_index)
 | 
				
			||||||
 | 
					    if player then
 | 
				
			||||||
 | 
					        player.print("Join our Discord at: http://Discord.Claytonia.net")
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue