First command added, fix commad errors

This commit is contained in:
Cooldude2606
2017-12-08 16:31:32 +00:00
parent 1e1fabd565
commit cab1207a85
5 changed files with 21 additions and 13 deletions

View File

@@ -39,7 +39,11 @@ end
-- @param rtn the value to return -- @param rtn the value to return
function ExpLib.player_return(rtn) function ExpLib.player_return(rtn)
if game.player then 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,'function') then game.player.print('Cant Display Functions')
elseif is_type(rtn,'userdata') then game.player.print('Cant Display Userdata') elseif is_type(rtn,'userdata') then game.player.print('Cant Display Userdata')
else game.player.print(tostring(rtn)) else game.player.print(tostring(rtn))

View File

@@ -24,7 +24,7 @@ error = function(err)
end end
-- loads the stdlib and allows Core Game and Event -- 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 -- loads the ExpLib, functions are plased into the lua global
local ExpLib = require 'ExpLib' 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 --_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 -- 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'} Ranking, Server, Gui = require('/locale/ExpCore/load'){'Ranking','Server','Gui'}

View File

@@ -76,13 +76,12 @@ end
--- Used to call the custom commands --- Used to call the custom commands
-- @usage You dont its an internal command -- @usage You dont its an internal command
-- @tparam defines.events.on_console_command event the event rasied by the command -- @tparam defines.events.on_console_command event the event rasied by the command=
commands._add_command = commands.add_command
local function run_custom_command(command) local function run_custom_command(command)
local command_data = command_data[command.name] local command_data = command_data[command.name]
local player_name = Game.get_player(commnd) and Game.get_player(commnd).name or 'server' local player_name = Game.get_player(commnd) and Game.get_player(commnd).name or 'server'
-- is the player allowed to use this command -- 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'} player_return{'commands.unauthorized'}
game.write_file('commands.log','\n'..game.tick game.write_file('commands.log','\n'..game.tick
..' Player: '..player_name ..' Player: '..player_name
@@ -94,25 +93,26 @@ local function run_custom_command(command)
-- gets the args for the command -- gets the args for the command
local args, valid = command_args(command,command_data) local args, valid = command_args(command,command_data)
if not valid then 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 game.write_file('commands.log','\n'..game.tick
..' Player: '..player.name ..' Player: '..player_name
..' Failed to use command (Invalid Args): '..command.name ..' Failed to use command (Invalid Args): '..command.name
..' With args of: '..table.to_string(args) ..' With args of: '..table.to_string(args)
, true, 0) , true, 0)
return return
end end
-- runs the command -- 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 if err then error(err) end
player_return{'commands.command-ran'} player_return{'commands.command-ran'}
game.write_file('commands.log','\n'..game.tick game.write_file('commands.log','\n'..game.tick
..' Player: '..player.name ..' Player: '..player_name
..' Used command: '..command.name ..' Used command: '..command.name
..' With args of: '..table.to_string(args) ..' With args of: '..table.to_string(args)
, true, 0) , true, 0)
end end
commands._add_command = commands.add_command
--- Used to define commands --- Used to define commands
-- @usage inputs = {'player','reason',true} -- @usage inputs = {'player','reason',true}
-- commands.add_command('ban','bans a player',inputs,function() return end) -- 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 inputs=inputs
} }
command_calls[name] = event 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 end

View File

@@ -17,8 +17,8 @@ Pass a table with the names of the objects you want and it will be return in tha
local StdExpCoreLib = {} local StdExpCoreLib = {}
StdExpCoreLib.Server = require '/server'
require '/commands' require '/commands'
StdExpCoreLib.Server = require '/server'
--[[StdExpCoreLib.Ranking = require '/ranking' --[[StdExpCoreLib.Ranking = require '/ranking'
require '/ranks' require '/ranks'
StdExpCoreLib.Gui = require '/gui' StdExpCoreLib.Gui = require '/gui'

View File

@@ -124,7 +124,11 @@ function Server.interface(callback,thread,...)
end end
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 -- thread allows you to run fuinction async to the main game
local thread = {} local thread = {}