Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script.on_init(function()
- for _, player in pairs(game.players) do
- gui_initialize(player)
- end
- end)
- script.on_event(defines.events.on_player_created, function(event)
- gui_initialize(game.players[event.player_index])
- end)
- script.on_event(defines.events.on_gui_click, function(event)
- if event.element.name == "rt_minimize_button" then
- gui_functions(game.players[event.player_index])
- --gui_initialize(game.players[event.player_index])
- elseif event.element.name == "train_rename_button" then
- train_rename(game.players[event.player_index])
- end
- end)
- script.on_event("train-rename", function(event)
- if game.players[event.player_index].selected then
- train_rename(game.players[event.player_index])
- end
- end)
- --create the minimize button when the game starts or when joining a server
- function gui_initialize(player)
- if player.gui.top.rt_minimize_button then
- player.gui.top.rt_minimize_button.destroy()
- end
- if (not player.gui.top.rt_minimize_button) then
- player.gui.top.add{type = "button", name = "rt_minimize_button", caption = "RT", style = "rt_minimize_button_style"}
- end
- end
- --minimize or maximize the rename GUI
- function gui_functions(player)
- if player.gui.left.train_rename_frame then
- player.gui.left.train_rename_frame.destroy()
- else
- frame = player.gui.left.add{type ="frame", name ="train_rename_frame"}
- frame.add{type = "label", name = "train_rename_label", caption = "Train name:"}
- frame.add{type = "textfield", name = "train_rename_textbox"}
- frame.add{type = "button", name = "train_rename_button", caption = "Set"}
- end
- end
- --rename train or building depending on open gui
- function train_rename(player)
- -- local entity_with_open_gui = player.opened
- local entity_with_open_gui = player.selected
- if player.gui.left.train_rename_frame then
- local new_name = player.gui.left.train_rename_frame.train_rename_textbox.text
- if entity_with_open_gui == nil then
- player.print("You must open a locomotive or cargo wagon then press this button.")
- --rename all locomotives in a train if a locomotive or cargo wagon is open and display a confirmation message
- elseif (entity_with_open_gui.type == "locomotive") or (entity_with_open_gui.type == "cargo-wagon") then
- for _, renameme in pairs(entity_with_open_gui.train.locomotives.front_movers) do
- renameme.backer_name = new_name
- end
- for _, renameme in pairs(entity_with_open_gui.train.locomotives.back_movers) do
- renameme.backer_name = new_name
- end
- player.print("All locomotives in this train were renamed: " .. new_name)
- --rename assemling machine, furnace, rocket silo, lab, train stop or roboport if any is open and display a confirmation message
- elseif (entity_with_open_gui.type == "assembling-machine") or (entity_with_open_gui.type == "furnace") or (entity_with_open_gui.type == "rocket-silo") or (entity_with_open_gui.type == "radar") or (entity_with_open_gui.type == "lab") or (entity_with_open_gui.type == "train-stop") or (entity_with_open_gui.type == "roboport") then
- entity_with_open_gui.backer_name = new_name
- player.print("Building renamed: " .. new_name)
- else
- player.print("You must open a locomotive or cargo wagon then press this button.")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement