1 function exec_command(player)
2 if not player.admin then
3 player.print('You are not an admin. You may not use this mod. :(')
9 if player.gui.screen.some_luaconsole then
10 storage.cmd = player.gui.screen.some_luaconsole.input.text
13 cmd = storage.cmd or ""
14 cmd = cmd:gsub('game%.player([^s])', 'game.players['..player.index..']%1')
16 f, err = loadstring(cmd)
18 cmd = 'game.players['..player.index..'].print('..cmd..')'
19 f, err = loadstring(cmd)
25 player.print(err:sub(1, err:find('\n')))
30 function toggleGui (player)
31 if player.gui.screen.some_luaconsole then
32 storage.cmd = player.gui.screen.some_luaconsole.input.text
33 player.gui.screen.some_luaconsole.destroy()
35 frame = player.gui.screen.add{type = 'frame',
36 name = 'some_luaconsole',
37 direction = 'vertical',
38 caption = {'some_luaconsole.title'}
41 frame.add{type = 'label', caption = {'some_luaconsole.inputlabel'}}
42 input = frame.add{type = 'text-box',
44 style='some_luaconsole_input_textbox'
46 input.word_wrap = true
47 input.style.maximal_height = (player.display_resolution.height/player.display_scale*0.6)
48 input.text = storage.cmd or ""
50 horizontal_flow = frame.add{type='flow', direction='horizontal'}
51 horizontal_flow.add{type = 'button',
52 name = 'some_luaconsole_close',
54 caption = {'some_luaconsole.close'},
55 tooltip = {'some_luaconsole.close_tooltip'}
57 horizontal_flow.add{type = 'button',
58 name = 'some_luaconsole_exec',
59 style='confirm_button',
60 caption = {'some_luaconsole.exec'},
61 tooltip = {'some_luaconsole.exec_tooltip'}
64 if not player.admin then
65 player.gui.screen.some_luaconsole.input.text = 'You are not an admin. You may not use this mod. :('
66 player.gui.screen.some_luaconsole.input.enabled = false
68 frame.force_auto_center()
74 script.on_event(defines.events.on_gui_click, function(event)
75 if event.element.name == 'some_luaconsole_exec' then
76 exec_command(game.players[event.player_index])
77 elseif event.element.name == 'some_luaconsole_close' then
78 toggleGui(game.players[event.player_index])
83 script.on_event('some_luaconsole_toggle', function(event)
84 toggleGui(game.players[event.player_index])
86 script.on_event('some_luaconsole_exec', function(event)
87 exec_command(game.players[event.player_index])