function exec_command(player) if not player.admin then player.print('You are not an admin. You may not use this mod. :(') return end local f, lserr, pcs, pcerr, cmd if player.gui.screen.some_luaconsole then storage.cmd = player.gui.screen.some_luaconsole.input.text end cmd = storage.cmd or "" cmd = cmd:gsub('game%.player([^s])', 'game.players['..player.index..']%1') f, lserr = loadstring('local ipcs,ipcr ipcs,ipcr=pcall(function() '..cmd..' end) if not ipcs then game.players['..player.index..'].print(ipcr) end') if not f then -- player.print("loadstring1 failed (this may be ok)") f, lserr = loadstring('game.players['..player.index..'].print('..cmd..')') end if f then pcs, pcerr = pcall(f) if not pcs then -- player.print("pcall failed") player.print(pcerr:sub(1, pcerr:find('\n'))) end else -- player.print("syntax error2") player.print(lserr:sub(1, lserr:find('\n'))) end end function toggleGui (player) if player.gui.screen.some_luaconsole then storage.cmd = player.gui.screen.some_luaconsole.input.text player.gui.screen.some_luaconsole.destroy() else frame = player.gui.screen.add{type = 'frame', name = 'some_luaconsole', direction = 'vertical', caption = {'some_luaconsole.title'} } frame.add{type = 'label', caption = {'some_luaconsole.inputlabel'}} input = frame.add{type = 'text-box', name = 'input', style='some_luaconsole_input_textbox' } input.word_wrap = true input.style.maximal_height = (player.display_resolution.height/player.display_scale*0.6) input.text = storage.cmd or "" horizontal_flow = frame.add{type='flow', direction='horizontal'} horizontal_flow.add{type = 'button', name = 'some_luaconsole_close', style='back_button', caption = {'some_luaconsole.close'}, tooltip = {'some_luaconsole.close_tooltip'} } horizontal_flow.add{type = 'button', name = 'some_luaconsole_exec', style='confirm_button', caption = {'some_luaconsole.exec'}, tooltip = {'some_luaconsole.exec_tooltip'} } if not player.admin then player.gui.screen.some_luaconsole.input.text = 'You are not an admin. You may not use this mod. :(' player.gui.screen.some_luaconsole.input.enabled = false end frame.force_auto_center() end end script.on_event(defines.events.on_gui_click, function(event) if event.element.name == 'some_luaconsole_exec' then exec_command(game.players[event.player_index]) elseif event.element.name == 'some_luaconsole_close' then toggleGui(game.players[event.player_index]) end end) script.on_event('some_luaconsole_toggle', function(event) toggleGui(game.players[event.player_index]) end) script.on_event('some_luaconsole_exec', function(event) exec_command(game.players[event.player_index]) end)