From cab1207a853aa66b05172fc1d378b3cdde00fb61 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 8 Dec 2017 16:31:32 +0000 Subject: [PATCH] First command added, fix commad errors --- ExpLib.lua | 6 +++++- control.lua | 4 ++-- locale/ExpCore/commands.lua | 16 ++++++++-------- locale/ExpCore/load.lua | 2 +- locale/ExpCore/server.lua | 6 +++++- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ExpLib.lua b/ExpLib.lua index 8a004503..49abe4d5 100644 --- a/ExpLib.lua +++ b/ExpLib.lua @@ -39,7 +39,11 @@ end -- @param rtn the value to return function ExpLib.player_return(rtn) if game.player then - if is_type(rtn,'table') then game.player.print(table.to_string(rtn)) + if is_type(rtn,'table') then + -- test if its a localised string + if is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then game.player.print(rtn) + else game.player.print(table.to_string(rtn)) + end elseif is_type(rtn,'function') then game.player.print('Cant Display Functions') elseif is_type(rtn,'userdata') then game.player.print('Cant Display Userdata') else game.player.print(tostring(rtn)) diff --git a/control.lua b/control.lua index dfe86488..ffb1dcce 100644 --- a/control.lua +++ b/control.lua @@ -24,7 +24,7 @@ error = function(err) end -- loads the stdlib and allows Core Game and Event -local Color, Game, Event = require('/locale/StdLib/load'){'Color','Game','Event'} +Color, Game, Event = require('/locale/StdLib/load'){'Color','Game','Event'} -- loads the ExpLib, functions are plased into the lua global local ExpLib = require 'ExpLib' @@ -32,4 +32,4 @@ ExpLib._unpack_to_G(ExpLib) --_G.discord_emit = function(...) return false end -- un-comment this line if you are not using the json.data -- loads the ExpCore files these are need in order to run the other addons -local Ranking, Server, Gui = require('/locale/ExpCore/load'){'Ranking','Server','Gui'} \ No newline at end of file +Ranking, Server, Gui = require('/locale/ExpCore/load'){'Ranking','Server','Gui'} \ No newline at end of file diff --git a/locale/ExpCore/commands.lua b/locale/ExpCore/commands.lua index f6c522ef..fa3fa827 100644 --- a/locale/ExpCore/commands.lua +++ b/locale/ExpCore/commands.lua @@ -76,13 +76,12 @@ end --- Used to call the custom commands -- @usage You dont its an internal command --- @tparam defines.events.on_console_command event the event rasied by the command -commands._add_command = commands.add_command +-- @tparam defines.events.on_console_command event the event rasied by the command= local function run_custom_command(command) local command_data = command_data[command.name] local player_name = Game.get_player(commnd) and Game.get_player(commnd).name or 'server' -- is the player allowed to use this command - if not Ranking.rank_allowed(Ranking.get_rank(command.player_index),command.name) then + if is_type(Ranking,'table') and not Ranking.rank_allowed(Ranking.get_rank(command.player_index),command.name) then player_return{'commands.unauthorized'} game.write_file('commands.log','\n'..game.tick ..' Player: '..player_name @@ -94,25 +93,26 @@ local function run_custom_command(command) -- gets the args for the command local args, valid = command_args(command,command_data) if not valid then - player_return{'commands.invalid-inputs',command.name,command_args(command)} + player_return{'commands.invalid-inputs',command.name,command_inputs(command_data)} game.write_file('commands.log','\n'..game.tick - ..' Player: '..player.name + ..' Player: '..player_name ..' Failed to use command (Invalid Args): '..command.name ..' With args of: '..table.to_string(args) , true, 0) return end -- runs the command - local status, err = pcall(command_calls[command.name],event,args) + local success, err = pcall(command_calls[command.name],event,args) if err then error(err) end player_return{'commands.command-ran'} game.write_file('commands.log','\n'..game.tick - ..' Player: '..player.name + ..' Player: '..player_name ..' Used command: '..command.name ..' With args of: '..table.to_string(args) , true, 0) end +commands._add_command = commands.add_command --- Used to define commands -- @usage inputs = {'player','reason',true} -- commands.add_command('ban','bans a player',inputs,function() return end) @@ -132,5 +132,5 @@ commands.add_command = function(name, description, inputs, event) inputs=inputs } command_calls[name] = event - _add_command(name,description,run_custom_command) + commands._add_command(name,command_inputs(command_data[name])..description,run_custom_command) end \ No newline at end of file diff --git a/locale/ExpCore/load.lua b/locale/ExpCore/load.lua index 9be0fb9f..1c72953a 100644 --- a/locale/ExpCore/load.lua +++ b/locale/ExpCore/load.lua @@ -17,8 +17,8 @@ Pass a table with the names of the objects you want and it will be return in tha local StdExpCoreLib = {} -StdExpCoreLib.Server = require '/server' require '/commands' +StdExpCoreLib.Server = require '/server' --[[StdExpCoreLib.Ranking = require '/ranking' require '/ranks' StdExpCoreLib.Gui = require '/gui' diff --git a/locale/ExpCore/server.lua b/locale/ExpCore/server.lua index 1b1eb97b..992daf7c 100644 --- a/locale/ExpCore/server.lua +++ b/locale/ExpCore/server.lua @@ -124,7 +124,11 @@ function Server.interface(callback,thread,...) end end - +commands.add_command('server-interface', 'Runs the given input from the script', {'code',true}, function(event,args) + local callback = args.code + local success, err = Server.interface(callback) + player_return(err) +end) -- thread allows you to run fuinction async to the main game local thread = {}