4 function exec_command(player)
5 if not player.admin then
6 player.print('You are not an admin. You may not use this mod. :(')
12 if player.gui.screen.some_luaconsole then
13 cmd = player.gui.screen.some_luaconsole.input.text
16 cmd = cmd:gsub('game%.player([^s])', 'game.players['..player.index..']%1')
18 f, err = loadstring(cmd)
20 cmd = 'game.players['..player.index..'].print('..cmd..')'
21 f, err = loadstring(cmd)
27 player.print(err:sub(1, err:find('\n')))
32 function toggleGui (player)
33 if player.gui.screen.some_luaconsole then
34 cmd = player.gui.screen.some_luaconsole.input.text
35 player.gui.screen.some_luaconsole.destroy()
37 frame = player.gui.screen.add{type = 'frame',
38 name = 'some_luaconsole',
39 direction = 'vertical',
40 caption = {'some_luaconsole.title'}
43 frame.add{type = 'label', caption = {'some_luaconsole.inputlabel'}}
44 input = frame.add{type = 'text-box',
46 style='some_luaconsole_input_textbox'
48 input.word_wrap = true
49 input.style.maximal_height = (player.display_resolution.height/player.display_scale*0.6)
52 horizontal_flow = frame.add{type='flow', direction='horizontal'}
53 horizontal_flow.add{type = 'button',
54 name = 'some_luaconsole_close',
56 caption = {'some_luaconsole.close'},
57 tooltip = {'some_luaconsole.close_tooltip'}
59 horizontal_flow.add{type = 'button',
60 name = 'some_luaconsole_exec',
61 style='confirm_button',
62 caption = {'some_luaconsole.exec'},
63 tooltip = {'some_luaconsole.exec_tooltip'}
66 if not player.admin then
67 player.gui.screen.some_luaconsole.input.text = 'You are not an admin. You may not use this mod. :('
68 player.gui.screen.some_luaconsole.input.enabled = false
70 frame.force_auto_center()
75 script.on_event(defines.events.on_gui_click, function(event)
76 if event.element.name == 'some_luaconsole_exec' then
77 exec_command(game.players[event.player_index])
78 elseif event.element.name == 'some_luaconsole_close' then
79 toggleGui(game.players[event.player_index])
84 script.on_event('some_luaconsole_toggle', function(event)
85 toggleGui(game.players[event.player_index])
87 script.on_event('some_luaconsole_exec', function(event)
88 exec_command(game.players[event.player_index])