Added moduole: ExpGamingCore.Server

This commit is contained in:
Cooldude2606
2018-06-01 16:12:39 +01:00
parent 22d3efc4a1
commit 5eb8600411
9 changed files with 302 additions and 204 deletions

View File

@@ -0,0 +1,31 @@
--- Description - A small description that will be displayed on the doc
-- @submodule ExpGamingCore.Server
-- @alias Server
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
--- This file will be loaded when ExpGamingCore.Commands is present
-- @function _comment
commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args)
local callback = args.code
-- looks for spaces, if non the it will prefix the command with return
if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end
-- sets up an env for the command to run in
local env = {_env=true,}
if game.player then
env.player = game.player
env.surface = game.player.surface
env.force = game.player.force
env.position = game.player.position
env.entity = game.player.selected
env.tile = game.player.surface.get_tile(game.player.position)
if Ranking and Ranking.get_rank then env.rank = Ranking.get_rank(game.player) end
end
-- runs the function
local success, err = Server.interface(callback,false,env)
-- if there is an error then it will remove the stacktrace and return the error
if not success and is_type(err,'string') then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end
-- if there is a value returned that is not nill then it will return that value
if err or err == false then player_return(err) end
end)