mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Command maker clean
This commit is contained in:
@@ -9,7 +9,7 @@ Discord: https://discord.gg/XSsBV6b
|
|||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||||
--set up to run other code and events
|
--set up to run other code and events
|
||||||
require("mod-gui")
|
require("mod-gui")
|
||||||
require("locale/StdLib/event")
|
Event = require("locale/StdLib/event")
|
||||||
--this is the main code that starts the softmod
|
--this is the main code that starts the softmod
|
||||||
Event.soft_init = script.generate_event_name()
|
Event.soft_init = script.generate_event_name()
|
||||||
local function init() if not global.soft_init then script.raise_event(Event.soft_init,{tick=game.tick}) global.soft_init = true end end
|
local function init() if not global.soft_init then script.raise_event(Event.soft_init,{tick=game.tick}) global.soft_init = true end end
|
||||||
@@ -31,5 +31,8 @@ Event.register(defines.events.on_tick, function(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
--loads core files
|
||||||
|
ranking,ExpGui,server = require("locale/ExpGaming-Core/file-header")
|
||||||
--loads all the other scripts
|
--loads all the other scripts
|
||||||
require("locale/file-header")
|
require("locale/Stand-Alone/file-header")
|
||||||
|
require("locale/ExpGaming-Addons/file-header")
|
||||||
@@ -5,22 +5,11 @@ This file can be used with permission but this and the credit below must remain
|
|||||||
Contact a member of management on our discord to seek permission to use our code.
|
Contact a member of management on our discord to seek permission to use our code.
|
||||||
Any changes that you may make to the code are yours but that does not make the script yours.
|
Any changes that you may make to the code are yours but that does not make the script yours.
|
||||||
Discord: https://discord.gg/XSsBV6b
|
Discord: https://discord.gg/XSsBV6b
|
||||||
|
|
||||||
The credit below may be used by another script do not remove.
|
|
||||||
]]
|
]]
|
||||||
local credits = {{
|
|
||||||
name='Explosive Gaming Custom Commands',
|
|
||||||
owner='Explosive Gaming',
|
|
||||||
dev='Cooldude2606',
|
|
||||||
description='Allows ease to making custom commands in game',
|
|
||||||
factorio_version='0.15.23',
|
|
||||||
show=true
|
|
||||||
}}
|
|
||||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
|
||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||||
local Exp_commands = {}
|
local Exp_commands = {}
|
||||||
--Used mainly by the code to convert the inputs into a string
|
--Used mainly by the code to convert the inputs into a string
|
||||||
function command_inputs_to_string(command)
|
local function command_inputs_to_string(command)
|
||||||
local str_inputs = ''
|
local str_inputs = ''
|
||||||
for _,input in pairs(command.inputs) do
|
for _,input in pairs(command.inputs) do
|
||||||
if input == true then break end
|
if input == true then break end
|
||||||
@@ -29,7 +18,7 @@ function command_inputs_to_string(command)
|
|||||||
return str_inputs
|
return str_inputs
|
||||||
end
|
end
|
||||||
--Can be used to ensure the right number of inputs are given
|
--Can be used to ensure the right number of inputs are given
|
||||||
function get_command_args(event,command,allow_invaild)
|
local function get_command_args(event,command,allow_invaild)
|
||||||
local args = {}
|
local args = {}
|
||||||
if not event.parameter then
|
if not event.parameter then
|
||||||
if #command.inputs > 0 then
|
if #command.inputs > 0 then
|
||||||
@@ -52,44 +41,53 @@ end
|
|||||||
--event(player,event,args) if the function that will be ran on the command use
|
--event(player,event,args) if the function that will be ran on the command use
|
||||||
function define_command(name,help,inputs,event)
|
function define_command(name,help,inputs,event)
|
||||||
if not name then error('Command requires a name') end
|
if not name then error('Command requires a name') end
|
||||||
local help = help or 'No Help Given'
|
local help = help or {'commands.no-help'}
|
||||||
local inputs = inputs or {true}
|
local inputs = inputs or {true}
|
||||||
if not event or type(event) ~= 'function' then error('Command requires a function') end
|
if not event or type(event) ~= 'function' then error('Command requires a function') end
|
||||||
table.insert(Exp_commands,{name=name,help=help,inputs=inputs,event=event})
|
Exp_commands[name]={name=name,help=help,inputs=inputs,event=event}
|
||||||
end
|
end
|
||||||
--The magic for the commands. It is a hard bit of code so GL; but it will call the command event have some sanitisaion of the input
|
--The magic for the commands. It is a hard bit of code so GL; but it will call the command event have some sanitisaion of the input
|
||||||
function load_command(command)
|
local function load_command(command)
|
||||||
|
--is the command all ready loaded
|
||||||
if commands.commands[command.name] then return end
|
if commands.commands[command.name] then return end
|
||||||
|
--start loading command
|
||||||
|
global.exp_core.commands[command.name] = command
|
||||||
debug_write({'COMMAND','LOAD'},command.name)
|
debug_write({'COMMAND','LOAD'},command.name)
|
||||||
game.write_file('commands.log','\n'..game.tick..' Loaded Command: '..command.name, true, 0)
|
--add command to game
|
||||||
commands.add_command(command.name,command_inputs_to_string(command)..command.help,function(event)
|
commands.add_command(command.name,{command.help,command_inputs_to_string(command)},function(event)
|
||||||
local command_data = nil
|
--gets the command data
|
||||||
for _,command_d in pairs(Exp_commands) do if event.name == command_d[1] then command_data = command_d break end end
|
local command_data = global.exp_core.commands[event.name]
|
||||||
debug_write({'COMMAND','RUN','START'},command.name)
|
debug_write({'COMMAND','RUN','START'},command.name)
|
||||||
debug_write({'COMMAND','RUN','PLAYER-INDEX'},event.player_index)
|
debug_write({'COMMAND','RUN','PLAYER-INDEX'},event.player_index)
|
||||||
if event.player_index then
|
if event.player_index then
|
||||||
|
--player ran command so authoriz it
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
if not ranking.rank_allowed(ranking.get_player_rank(player),command.name) then
|
if not ranking.rank_allowed(ranking.get_player_rank(player),command.name) then
|
||||||
debug_write({'COMMAND','RUN','ALLOWED'},false)
|
debug_write({'COMMAND','RUN','ALLOWED'},false)
|
||||||
player.print('401 - Unauthorized: Access is denied due to invalid credentials')
|
player.print({'commands.unauthorized'})
|
||||||
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
|
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
--start prossessing command inputs, check if valid
|
||||||
debug_write({'COMMAND','RUN','ALLOWED'},true)
|
debug_write({'COMMAND','RUN','ALLOWED'},true)
|
||||||
local args = get_command_args(event,command)
|
local args = get_command_args(event,command)
|
||||||
debug_write({'COMMAND','RUN','ARGS'},args)
|
debug_write({'COMMAND','RUN','ARGS'},args)
|
||||||
if args == 'Invalid' then
|
if args == 'Invalid' then
|
||||||
player.print('Invalid Input, /'..command.name..' '..command_inputs_to_string(command)) return
|
player.print({'commands.invalid-inputs',command.name,command_inputs_to_string(command)})
|
||||||
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Invalid Args): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
|
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Invalid Args): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
--run the callback function of the command
|
||||||
debug_write({'COMMAND','RUN','FUNCTION'},command.name)
|
debug_write({'COMMAND','RUN','FUNCTION'},command.name)
|
||||||
command.event(player,event,args)
|
command.event(player,event,args)
|
||||||
player.print('Command Complete')
|
player.print({'commands.command-ran'})
|
||||||
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Used command: '..command.name..' With args of: '..table.tostring(args), true, 0)
|
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Used command: '..command.name..' With args of: '..table.tostring(args), true, 0)
|
||||||
else
|
else
|
||||||
|
--server ran command so skip authorizion
|
||||||
local args = get_command_args(event,command)
|
local args = get_command_args(event,command)
|
||||||
if args == 'Invalid' then print('Invalid Input, /'..command.name..' '..command_inputs_to_string(command)) return end
|
if args == 'Invalid' then print('Invalid Input, /'..command.name..' '..command_inputs_to_string(command)) return end
|
||||||
debug_write({'COMMAND','RUN','ARGS'},args)
|
debug_write({'COMMAND','RUN','ARGS'},args)
|
||||||
|
--run the callback function of the command
|
||||||
debug_write({'COMMAND','RUN','FUNCTION'},command.name)
|
debug_write({'COMMAND','RUN','FUNCTION'},command.name)
|
||||||
command.event('<server>',event,args)
|
command.event('<server>',event,args)
|
||||||
print('Command Complete')
|
print('Command Complete')
|
||||||
@@ -102,12 +100,11 @@ end
|
|||||||
function get_commands(rank)
|
function get_commands(rank)
|
||||||
local rank = rank or 'Owner'
|
local rank = rank or 'Owner'
|
||||||
local to_return = {}
|
local to_return = {}
|
||||||
for _,command in pairs(global.exp_core.commands) do
|
for command_name,command in pairs(global.exp_core.commands) do
|
||||||
if ranking.rank_allowed(ranking.string_to_rank(rank),command.name) then table.insert(to_return,command) end
|
if ranking.rank_allowed(ranking.string_to_rank(rank),command_name) then table.insert(to_return,command) end
|
||||||
end
|
end
|
||||||
return to_return
|
return to_return
|
||||||
end
|
end
|
||||||
Event.register(Event.soft_init,function() global.exp_core.commands = Exp_commands for _,command in pairs(Exp_commands) do load_command(command) end end)
|
Event.register(Event.soft_init,function() for command_name,command in pairs(Exp_commands) do load_command(command) end end)
|
||||||
Event.register(defines.events.on_player_joined_game,function() for _,command in pairs(Exp_commands) do load_command(command) end end)
|
--######TEST#####TEST#####TEST###### un comment below
|
||||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
--Event.register(defines.events.on_player_joined_game,function() for command_name,command in pairs(Exp_commands) do load_command(command) end end)
|
||||||
return credits
|
|
||||||
@@ -5,24 +5,13 @@ This file can be used with permission but this and the credit below must remain
|
|||||||
Contact a member of management on our discord to seek permission to use our code.
|
Contact a member of management on our discord to seek permission to use our code.
|
||||||
Any changes that you may make to the code are yours but that does not make the script yours.
|
Any changes that you may make to the code are yours but that does not make the script yours.
|
||||||
Discord: https://discord.gg/XSsBV6b
|
Discord: https://discord.gg/XSsBV6b
|
||||||
|
|
||||||
The credit below may be used by another script do not remove.
|
|
||||||
]]
|
]]
|
||||||
local credits = {{
|
|
||||||
name='File Header - Stand-Alone',
|
|
||||||
owner='Explosive Gaming',
|
|
||||||
dev='Cooldude2606',
|
|
||||||
description='Just A File Header To Organise Code',
|
|
||||||
factorio_version='0.15.23',
|
|
||||||
show=false
|
|
||||||
}}
|
|
||||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
|
||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||||
--As this is the core file, the order in which the files are loaded does matter. Do not change!
|
--As this is the core file, the order in which the files are loaded does matter. Do not change!
|
||||||
credit_loop(require("ExpGaming - Lib"))
|
require("ExpGaming - Lib")
|
||||||
credit_loop(require("ExpGaming - Rank Control"))
|
ranking = require("ExpGaming - Rank Control")
|
||||||
credit_loop(require("GUI/file-header"))
|
ExpGui = require("GUI/file-header")
|
||||||
credit_loop(require("ExpGaming - Command Maker"))
|
require("ExpGaming - Command Maker")
|
||||||
credit_loop(require("ExpGaming - Server Interface"))
|
server = require("ExpGaming - Server Interface")
|
||||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
--Please Only Edit Above This Line-----------------------------------------------------------
|
||||||
return credits
|
return ranking,ExpGui,server
|
||||||
@@ -5,20 +5,10 @@
|
|||||||
-- @module Event
|
-- @module Event
|
||||||
-- @usage require('stdlib/event/event')
|
-- @usage require('stdlib/event/event')
|
||||||
|
|
||||||
local credits = {{
|
|
||||||
name='Factorio StdLib',
|
|
||||||
owner='Afforess',
|
|
||||||
dev='Afforess',
|
|
||||||
description='The Factorio StdLib used here for the event handler',
|
|
||||||
factorio_version='0.15.23',
|
|
||||||
show=true
|
|
||||||
}}
|
|
||||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
|
||||||
|
|
||||||
local fail_if_missing = require 'core'['fail_if_missing']
|
local fail_if_missing = require 'core'['fail_if_missing']
|
||||||
local Game = require 'game'
|
local Game = require 'game'
|
||||||
|
|
||||||
Event = { --luacheck: allow defined top
|
local Event = { --luacheck: allow defined top
|
||||||
_registry = {},
|
_registry = {},
|
||||||
core_events = {
|
core_events = {
|
||||||
init = -1,
|
init = -1,
|
||||||
@@ -168,4 +158,4 @@ function Event.remove(event, handler)
|
|||||||
return Event
|
return Event
|
||||||
end
|
end
|
||||||
|
|
||||||
return credits, Event
|
return Event
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
--[[
|
|
||||||
Explosive Gaming
|
|
||||||
|
|
||||||
This file can be used with permission but this and the credit below must remain in the file.
|
|
||||||
Contact a member of management on our discord to seek permission to use our code.
|
|
||||||
Any changes that you may make to the code are yours but that does not make the script yours.
|
|
||||||
Discord: https://discord.gg/XSsBV6b
|
|
||||||
|
|
||||||
The credit below may be used by another script do not remove.
|
|
||||||
]]
|
|
||||||
local credits = {{
|
|
||||||
name='File Header - Stand-Alone',
|
|
||||||
owner='Explosive Gaming',
|
|
||||||
dev='Cooldude2606',
|
|
||||||
description='Just A File Header To Organise Code',
|
|
||||||
factorio_version='0.15.23',
|
|
||||||
show=false
|
|
||||||
}}
|
|
||||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
|
||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
|
||||||
credit_loop(require("Stand-Alone/file-header"))
|
|
||||||
credit_loop(require("ExpGaming-Core/file-header"))
|
|
||||||
credit_loop(require("ExpGaming-Addons/file-header"))
|
|
||||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
|
||||||
return credits
|
|
||||||
Reference in New Issue
Block a user