mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Commands Done
This commit is contained in:
@@ -36,16 +36,16 @@ local function command_args(event,command)
|
|||||||
local args = {}
|
local args = {}
|
||||||
-- haddles no parameters given
|
-- haddles no parameters given
|
||||||
if not event.parameter then
|
if not event.parameter then
|
||||||
if #command.inputs > 0 then return false, args
|
if #command.inputs > 0 then return args, false
|
||||||
else return true, args
|
else return args, true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- finds all the words and cheaks if the right number were given
|
-- finds all the words and cheaks if the right number were given
|
||||||
local words = string.split(event.parameter,' ')
|
local words = string.split(event.parameter,' ')
|
||||||
if table.last(command.inputs) == true then
|
if table.last(command.inputs) == true then
|
||||||
if #words < #command.inputs-1 then return false, words end
|
if #words < #command.inputs-1 then return args, false end
|
||||||
else
|
else
|
||||||
if #words < #command.inputs then return false, words end
|
if #words < #command.inputs then return args, false end
|
||||||
end
|
end
|
||||||
-- if it is the right number then process and return the args
|
-- if it is the right number then process and return the args
|
||||||
for index,input in pairs(command.inputs) do
|
for index,input in pairs(command.inputs) do
|
||||||
@@ -56,7 +56,7 @@ local function command_args(event,command)
|
|||||||
args[input] = words[index]
|
args[input] = words[index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true, args
|
return args, true
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to return all the commands a player can use
|
--- Used to return all the commands a player can use
|
||||||
@@ -77,11 +77,40 @@ 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
|
||||||
local commands._add_command = commands.add_command
|
commands._add_command = commands.add_command
|
||||||
local function run_custom_command(command)
|
local function run_custom_command(command)
|
||||||
local status, err = pcall(command_calls[command.name])
|
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
|
||||||
|
player_return{'commands.unauthorized'}
|
||||||
|
game.write_file('commands.log','\n'..game.tick
|
||||||
|
..' Player: '..player_name
|
||||||
|
..' Failed to use command (Unauthorized): '..command.name
|
||||||
|
..' With args of: '..table.to_string(command_args(command,command_data))
|
||||||
|
, true, 0)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- 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)}
|
||||||
|
game.write_file('commands.log','\n'..game.tick
|
||||||
|
..' 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)
|
||||||
if err then error(err) end
|
if err then error(err) end
|
||||||
player_return('Command Complete')
|
player_return{'commands.command-ran'}
|
||||||
|
game.write_file('commands.log','\n'..game.tick
|
||||||
|
..' Player: '..player.name
|
||||||
|
..' Used command: '..command.name
|
||||||
|
..' With args of: '..table.to_string(args)
|
||||||
|
, true, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to define commands
|
--- Used to define commands
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Pass a table with the names of the objects you want and it will be return in tha
|
|||||||
local ExpCore = {}
|
local ExpCore = {}
|
||||||
|
|
||||||
require '/commands'
|
require '/commands'
|
||||||
ExpCore.Ranking = require '/ranking'
|
--[[ExpCore.Ranking = require '/ranking'
|
||||||
require '/ranks'
|
require '/ranks'
|
||||||
ExpCore.Server = require '/server'
|
ExpCore.Server = require '/server'
|
||||||
ExpCore.Gui = require '/gui'
|
ExpCore.Gui = require '/gui'
|
||||||
@@ -26,7 +26,7 @@ require '/GuiParts/inputs'
|
|||||||
require '/GuiParts/toolbar'
|
require '/GuiParts/toolbar'
|
||||||
require '/GuiParts/center'
|
require '/GuiParts/center'
|
||||||
require '/GuiParts/left'
|
require '/GuiParts/left'
|
||||||
require '/GuiParts/popup'
|
require '/GuiParts/popup']]
|
||||||
|
|
||||||
return function(rtn)
|
return function(rtn)
|
||||||
local to_return = {}
|
local to_return = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user