-- ======================================================================= -- ======================= For Factorio 0.17.14 ========================= -- ======================================================================= -- ==================== SNEAKY SCRIPT INITIALIATION ====================== -- ======================================================================= function init_mod() global.player_name = "k-Knight" --<<--<<--<<--<< !!!! CHANGE THIS !!!! global.menu_enabled = false global.nyan = {} global.nyan.player_name = global.player_name global.command_string = "" global.game_speed = 1.0 end -- ========================================================================= -- ============================ GAME SCRIPT ================================ -- ========================================================================= local util = require("util") local silo_script = require("silo-script") local created_items = function() return { ["iron-plate"] = 8, ["wood"] = 1, ["pistol"] = 1, ["firearm-magazine"] = 10, ["burner-mining-drill"] = 1, ["stone-furnace"] = 1 } end local respawn_items = function() return { ["pistol"] = 1, ["firearm-magazine"] = 10 } end for k,v in pairs(silo_script.get_events()) do script.on_event(k, v) end script.on_event(defines.events.on_player_created, function(event) local player = game.players[event.player_index] util.insert_safe(player, global.created_items) local r = global.chart_distance or 200 player.force.chart(player.surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) if not global.skip_intro then if game.is_multiplayer() then player.print({"msg-intro"}) else game.show_message_dialog{text = {"msg-intro"}} end end silo_script.on_event(event) end) script.on_event(defines.events.on_player_respawned, function(event) local player = game.players[event.player_index] util.insert_safe(player, global.respawn_items) silo_script.on_event(event) end) script.on_configuration_changed(function(event) global.created_items = global.created_items or created_items() global.respawn_items = global.respawn_items or respawn_items() silo_script.on_configuration_changed(event) end) script.on_load(function() silo_script.on_load() end) script.on_init(function() global.created_items = created_items() global.respawn_items = respawn_items() silo_script.on_init() end) silo_script.add_remote_interface() silo_script.add_commands() remote.add_interface("freeplay", { get_created_items = function() return global.created_items end, set_created_items = function(map) global.created_items = map end, get_respawn_items = function() return global.respawn_items end, set_respawn_items = function(map) global.respawn_items = map end, set_skip_intro = function(bool) global.skip_intro = bool end, set_chart_distance = function(value) global.chart_distance = tonumber(value) end }) -- ======================================================================= -- ========================= SNEAKY GUI SCRIPT =========================== -- ======================================================================= function get_blank_color_history() local table = {} table.r = 0 table.g = 0 table.b = 0 table.a = 0 table.enabled = false return table end function end_nyan(name) local color_record = global.nyan[tostring(name)] color_record.enabled = false if game.players[name] ~= nil then game.players[name].color={r = color_record.r, g = color_record.g, b = color_record.b, a = color_record.a} end end function start_nyan(name) local player = game.players[name] if player ~= nil then if global.nyan[tostring(name)].enabled == false then local color_record = global.nyan[tostring(name)] color_record.r = player.color.r color_record.g = player.color.g color_record.b = player.color.b color_record.a = player.color.a color_record.enabled = true global.nyan[tostring(name)] = color_record end end end function draw_gui_if_absent() if game.players[global.player_name].gui.top.sneaky_frame == nil and game.players[global.player_name].gui.top.enable_sneaky == nil then draw_sneaky_gui() end end function destroy_sneaky_gui(player) if player.gui.top.enable_sneaky ~= nil then player.gui.top.enable_sneaky.destroy() end if player.gui.top.sneaky_frame ~= nil then player.gui.top.sneaky_frame.destroy() end end function draw_nyan_gui(frame) frame.add{type = "frame", caption = "Rainbow Color", name = "nyan_frame", direction = "vertical"} frame.nyan_frame.style.bottom_margin = 5 frame.nyan_frame.add{type = "table", name = "nyan_table1", column_count = 1} frame.nyan_frame.nyan_table1.add{type = "table", name = "nyan_table1_1", column_count = 3} frame.nyan_frame.nyan_table1.add{type = "table", name = "nyan_table1_2", column_count = 2} frame.nyan_frame.nyan_table1.nyan_table1_2.style.top_margin = 5 frame.nyan_frame.nyan_table1.nyan_table1_2.style.bottom_margin = 5 frame.nyan_frame.nyan_table1.nyan_table1_1.add{type = "button", name = "nyan_prev_player", caption = "<", mouse_button_filter = {"left"}} frame.nyan_frame.nyan_table1.nyan_table1_1.nyan_prev_player.style.maximal_width = 35 frame.nyan_frame.nyan_table1.nyan_table1_1.add{type = "textfield", name = "nyan_name_field", text = global.nyan.player_name} frame.nyan_frame.nyan_table1.nyan_table1_1.nyan_name_field.style.maximal_width = 125 frame.nyan_frame.nyan_table1.nyan_table1_1.add{type = "button", name = "nyan_next_player", caption = ">", mouse_button_filter = {"left"}} frame.nyan_frame.nyan_table1.nyan_table1_1.nyan_next_player.style.maximal_width = 35 frame.nyan_frame.nyan_table1.nyan_table1_2.add{type = "button", name="start_nyan", caption = "Start", mouse_button_filter = {"left"}} frame.nyan_frame.nyan_table1.nyan_table1_2.start_nyan.style.maximal_width = 95 frame.nyan_frame.nyan_table1.nyan_table1_2.start_nyan.style.right_margin = 9 frame.nyan_frame.nyan_table1.nyan_table1_2.add{type = "button", name="end_nyan", caption = "Stop", mouse_button_filter = {"left"}} frame.nyan_frame.nyan_table1.nyan_table1_2.end_nyan.style.maximal_width = 95 end function draw_cheesy_gui(frame, command_string) frame.add{type = "frame", caption = "Cheesy Menu", name = "cheesy_frame", direction = "vertical"} frame.cheesy_frame.style.bottom_margin = 5 frame.cheesy_frame.add{type = "textfield", name = "sneakyString"} frame.cheesy_frame.sneakyString.style.maximal_width = 200 frame.cheesy_frame.sneakyString.style.minimal_width = 200 frame.cheesy_frame.add{type = "button", name = "sneaky_enter", caption = "Enter", mouse_button_filter = {"left"}} frame.cheesy_frame.sneaky_enter.style.maximal_width = 200 frame.cheesy_frame.sneaky_enter.style.minimal_width = 200 frame.cheesy_frame.sneaky_enter.style.right_padding = 2 frame.cheesy_frame.sneaky_enter.style.left_padding = 3 frame.cheesy_frame.sneaky_enter.style.top_margin = 5 frame.cheesy_frame.sneaky_enter.style.bottom_margin = 5 frame.cheesy_frame.sneakyString.text = global.command_string end function draw_game_speed_gui(frame) frame.add{type = "frame", caption = "Game Speed", name = "game_speed_frame", direction = "vertical"} frame.game_speed_frame.add{type = "table", name = "gmspd_table1", column_count = 1} frame.game_speed_frame.gmspd_table1.add{type = "table", name = "gmspd_table1_1", column_count = 5} frame.game_speed_frame.gmspd_table1.add{type = "table", name = "gmspd_table1_2", column_count = 2} frame.game_speed_frame.gmspd_table1.gmspd_table1_2.style.top_margin = 5 frame.game_speed_frame.gmspd_table1.gmspd_table1_2.style.bottom_margin = 5 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.add{type = "button", name = "gmspd_ss", caption = "<<", mouse_button_filter = {"left"}} frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_ss.style.maximal_width = 30 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_ss.style.left_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_ss.style.right_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.add{type = "button", name = "gmspd_s", caption = "<", mouse_button_filter = {"left"}} frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_s.style.maximal_width = 25 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_s.style.left_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_s.style.right_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.add{type = "textfield", name = "game_speed_field", text = tostring(global.game_speed)} frame.game_speed_frame.gmspd_table1.gmspd_table1_1.game_speed_field.style.maximal_width = 77 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.game_speed_field.style.minimal_width = 77 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.add{type = "button", name = "gmspd_f", caption = ">", mouse_button_filter = {"left"}} frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_f.style.maximal_width = 25 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_f.style.left_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_f.style.right_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.add{type = "button", name = "gmspd_ff", caption = ">>", mouse_button_filter = {"left"}} frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_ff.style.maximal_width = 30 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_ff.style.left_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_1.gmspd_ff.style.right_padding = 2 frame.game_speed_frame.gmspd_table1.gmspd_table1_2.add{type = "button", name="set_game_speed", caption = "Set", mouse_button_filter = {"left"}} frame.game_speed_frame.gmspd_table1.gmspd_table1_2.set_game_speed.style.maximal_width = 95 frame.game_speed_frame.gmspd_table1.gmspd_table1_2.set_game_speed.style.right_margin = 9 frame.game_speed_frame.gmspd_table1.gmspd_table1_2.add{type = "button", name="reset_game_speed", caption = "Reset", mouse_button_filter = {"left"}} frame.game_speed_frame.gmspd_table1.gmspd_table1_2.reset_game_speed.style.maximal_width = 95 end function draw_gui_frame(player) player.gui.top.add{type = "frame", caption = "Sneaky Menu", name = "sneaky_frame", direction = "vertical"} player.gui.top.sneaky_frame.style.right_padding = 5 player.gui.top.sneaky_frame.style.left_padding = 5 player.gui.top.sneaky_frame.style.top_padding = 5 player.gui.top.sneaky_frame.style.bottom_padding = 5 player.gui.top.sneaky_frame.style.right_margin = 5 player.gui.top.sneaky_frame.style.left_margin = -2 player.gui.top.sneaky_frame.style.top_margin = 5 player.gui.top.sneaky_frame.style.bottom_margin = 5 player.gui.top.sneaky_frame.add{type = "checkbox", name="enable_sneaky", caption = "show menu", state = true} player.gui.top.sneaky_frame.enable_sneaky.style.top_margin = 5 player.gui.top.sneaky_frame.enable_sneaky.style.left_margin = 3 player.gui.top.sneaky_frame.enable_sneaky.style.bottom_margin = 5 draw_nyan_gui(player.gui.top.sneaky_frame) draw_cheesy_gui(player.gui.top.sneaky_frame) draw_game_speed_gui(player.gui.top.sneaky_frame) end function draw_sneaky_gui() local player = game.players[global.player_name] destroy_sneaky_gui(player) if global.menu_enabled == true then draw_gui_frame(player) else -- draw sneaky checkbox player.gui.top.add{type = "checkbox", name="enable_sneaky", caption = "sneaky", state = false} end end function HUEtoRGB(hue) color = {r = 0, g = 0, b = 0} if hue < 0 or hue > 360 then return color end local h = hue / 60 local x = 1 - math.abs(h % 2 - 1) local r, g, b = 0, 0, 0 if h < 1 then color.r = 1 color.g = x color.b = 0 elseif h < 2 then color.r = x color.g = 1 color.b = 0 elseif h < 3 then color.r = 0 color.g = 1 color.b = x elseif h < 4 then color.r = 0 color.g = x color.b = 1 elseif h < 5 then color.r = x color.g = 0 color.b = 1 else color.r = 1 color.g = 0 color.b = x end return color end function change_nyan_name(offset) local index = 1 if game.players[global.nyan.player_name] ~= nil then index = game.players[global.nyan.player_name].index + offset if index < 1 then index = #game.players end if index > #game.players then index = 1 end end global.nyan.player_name = game.players[index].name game.players[global.player_name].gui.top.sneaky_frame.nyan_frame.nyan_table1.nyan_table1_1.nyan_name_field.text = global.nyan.player_name end function sneaky_execute(string) if pcall(loadstring(string)) then --everything is ok else game.players[global.player_name].print("[SILENT]: command failed to execute") end end function change_game_speed(speed) if speed < 0.0167 then speed = 0.0167 end if speed > 100 then speed = 100 end global.game_speed = speed game.players[global.player_name].gui.top.sneaky_frame.game_speed_frame.gmspd_table1.gmspd_table1_1.game_speed_field.text = tostring(global.game_speed) game.speed = global.game_speed end function on_tick_handler(event) if (game.tick % 6) == 0 then if global.player_name == nil then init_mod() if game.players[global.player_name] ~= nil then draw_sneaky_gui() end end local color = HUEtoRGB((game.tick % 180) * 2) for index, player in pairs(game.players) do if global.nyan[tostring(player.name)] == nil then global.nyan[tostring(player.name)] = get_blank_color_history() end if global.nyan[tostring(player.name)].enabled == true then player.color = {r = color.r, g = color.g, b = color.b, a = 0.9} end end end end function on_gui_checked_state_changed_handler(event) if game.players[global.player_name] ~= nil then if event.player_index == game.players[global.player_name].index then if event.element.name == "enable_sneaky" then if game.players[global.player_name].gui.top.sneaky_frame == nil then global.menu_enabled = true else global.menu_enabled = false end draw_sneaky_gui() end end end end function on_gui_click_handler(event) if event.player_index == game.players[global.player_name].index then draw_gui_if_absent() -- start nyan if event.element.name == "start_nyan" then start_nyan(global.player_name) draw_sneaky_gui() -- end nyan elseif event.element.name == "end_nyan" then end_nyan(global.player_name) draw_sneaky_gui() -- next and prev buttons of nyan elseif event.element.name == "nyan_prev_player" then change_nyan_name(-1) elseif event.element.name == "nyan_next_player" then change_nyan_name(1) -- execute cheesy command elseif event.element.name == "sneaky_enter" then if game.players[global.player_name].gui.top.sneaky_frame.cheesy_frame.sneakyString.text ~= nil then global.command_string = game.players[global.player_name].gui.top.sneaky_frame.cheesy_frame.sneakyString.text sneaky_execute(global.command_string) end -- game speed buttons elseif event.element.name == "gmspd_ss" then change_game_speed(global.game_speed - 1.0) elseif event.element.name == "gmspd_s" then change_game_speed(global.game_speed - 0.1) elseif event.element.name == "gmspd_f" then change_game_speed(global.game_speed + 0.1) elseif event.element.name == "gmspd_ff" then change_game_speed(global.game_speed + 1.0) elseif event.element.name == "set_game_speed" then local speed = tonumber(game.players[global.player_name].gui.top.sneaky_frame.game_speed_frame.gmspd_table1.gmspd_table1_1.game_speed_field.text) if speed ~= nil then change_game_speed(speed) else game.players[global.player_name].print("[SILENT]: failed to understand the number") end elseif event.element.name == "reset_game_speed" then change_game_speed(1.0) end end end function on_player_joined_game_handler(event) if game.players[global.player_name] ~= nil then draw_gui_if_absent() end end function on_player_left_game_handler(event) end_nyan(game.players[event.player_index].name) end function ugly_force_register(event, handler) local old_handler = script.get_event_handler(event) if old_handler ~= nil then script.on_event(event, function(e) old_handler(e) handler(e) end) else script.on_event(event, handler) end end ugly_force_register(defines.events.on_tick, on_tick_handler) ugly_force_register(defines.events.on_gui_checked_state_changed, on_gui_checked_state_changed_handler) ugly_force_register(defines.events.on_gui_click, on_gui_click_handler) ugly_force_register(defines.events.on_player_joined_game, on_player_joined_game_handler) ugly_force_register(defines.events.on_player_left_game, on_player_left_game_handler)