diff --git a/locale/ExpGaming-Core/ExpGaming - Command Maker.lua b/locale/ExpGaming-Core/ExpGaming - Command Maker.lua new file mode 100644 index 00000000..f9f3d982 --- /dev/null +++ b/locale/ExpGaming-Core/ExpGaming - Command Maker.lua @@ -0,0 +1,81 @@ +--[[ +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='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----------------------------------------------------------- +local Exp_commands = {} +--used mainly by the code to convert the inputs into a string +function command_inputs_to_string(command) + local str_inputs = '' + for _,input in pairs(command[3]) do + if input == true then break end + str_inputs = str_inputs..'<'..input..'> ' + end + return str_inputs +end +--can be used to ensure the right number of inputs are given +function get_command_args(event,command) + local player = game.players[event.player_index] + if not event.parameter then player.print('Invaild Input, /'..command[1]..' '..command_inputs_to_string(command)) if #command[3] > 0 then return 'Invaild' else return end end + local args = {} + for word in event.parameter:gmatch('%S+') do table.insert(args,word) end + if command[3][#command[3]] == true then + if #args < #command[3]-1 then player.print('Invaild Input, /'..command[1]..' '..command_inputs_to_string(command)) return 'Invaild' end + else + if #args ~= #command[3] then player.print('Invaild Input, /'..command[1]..' '..command_inputs_to_string(command)) return 'Invaild' end + end return args +end +--name is what is used in /command +--help is the help infor given +--inputs is a list ie {'name','message',true} the last value being true apossed to a string allows a varible number of words for the last input ie message can be mutilple words long +--restriction is the minium rank that can use the caommand +--event(player,event,args) if the function that will be ran on the command use +function define_command(name,help,inputs,restriction,event) + if not name then error('Command requires a name') end + local help = help or 'No Help Given' + local inputs = inputs or {true} + local restriction = restriction or 0 + if not event or type(event) ~= 'function' then error('Command requires a function') end + table.insert(Exp_commands,{name,help,inputs,restriction,event}) +end +--the magic for the commnads it is a hard bit of code so GL; but it will call the command event have some satatisaion of the input +function load_command(command) + if commands.commands[command[1]] then return end + commands.add_command(command[1],command_inputs_to_string(command)..command[2],function(event) + local command_data = nil + for _,command_d in pairs(Exp_commands) do if event.name == command_d[1] then command_data = command_d break end end + if event.player_index then + local player = game.players[event.player_index] + local temp_restriction = nil + if type(command[4]) == 'number' then temp_restriction = command[4] end + local restriction = temp_restriction or string_to_rank(command[4]).power or 0 + if get_rank(player).power > restriction then player.print('401 - Unauthorized: Access is denied due to invalid credentials') return end + local args = get_command_args(event,command) + if args == 'Invaild' then return end + command[5](player,event,args) + else + local args = get_command_args(event,command) + if args == 'Invaild' then return end + command[5]('',event) + end + end) +end + +Event.register(defines.events.on_player_joined_game,function() for _,command in pairs(Exp_commands) do load_command(command) end end) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua index 40b8cb68..6790326b 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -50,7 +50,7 @@ function rank_print(msg, rank, inv) end else if rankPower <= rank.power then - if rank.shortHand ~= '' then player.print(('['..(rank.shortHand)..']: '..msg)) else player.print(('[Everyone]: '..msg)) end + if rank.short_hand ~= '' then player.print(('['..(rank.short_hand)..']: '..msg)) else player.print(('[Everyone]: '..msg)) end end end end @@ -68,9 +68,8 @@ function give_rank(player,rank,by_player) else rank_print(player.name..' was '..message..' to '..rank.name..' by ','Guest') end - player.print('You Have Been Given The '..rank.name..' Rank!') - --if for some reason the tag is diffrent to the deafult - if player.tag ~= old_rank.tag then player.print('Your Tag Was Reset Due To A Rank Change') end + if rank.name ~= 'Guest' then player.print('You Have Been Given The '..rank.name..' Rank!') end + if player.tag ~= old_rank.tag and player.tag ~= '' then player.print('Your Tag Was Reset Due To A Rank Change') end --rank change player.permission_group = game.permissions.get_group(rank.name) player.tag = get_rank(player).tag @@ -117,7 +116,7 @@ function find_new_rank(player) end end --lose ends - if get_rank(player).power <= 3 and not player.admin then rank_print(player.name..' needs to be promoted.') end + if get_rank(player).power <= string_to_rank('mod').power and not player.admin then rank_print(player.name..' needs to be promoted.') end if old_rank.name ~= get_rank(player).name then global.old_ranks[player.index]=old_rank.name end end --event handlers diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua index b7ab0a59..0f38bbfe 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua @@ -19,15 +19,13 @@ local credits = {{ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- --[[ -Rank Powers: -0: root -1: no restrictions - management ranks -2: unable to use scripting commands - must be with sudo() -3: able to jail people - must use /promote to be able to ban -4: highest user power -5: people who are trusted -6: default power level -7: full restrictions +Name is what will be used in the scripts and is offten the best chose for display in text. +short_hand is what can be used when short on space but the rank still need to be displayed. +tag is the tag the player will gain when moved to the rank, it can be nil. +time is used for auto rank feature where you are moved to the rank after a certain play time in minutes. +colour is the rgb value that can be used to emphaise gui elelemts based on rank. +power is not in the list below as it is auto defined but allows compairison between ranks. +disallow is a list containing input acttion that the user can not preform. For disallow add to the list the end part of the input action Example: defines.input_action.drop_item -> 'drop_item' @@ -35,33 +33,29 @@ http://lua-api.factorio.com/latest/defines.html#defines.input_action --]] local ranks = { {name='Owner', - shortHand='Owner', + short_hand='Owner', tag='[Owner]', - power=0, time=nil, colour={r=170,g=0,b=0}, disallow={}}, {name='Community Manager', - shortHand='Com Mngr', + short_hand='Com Mngr', tag='[Com Mngr]', - power=1, time=nil, colour={r=150,g=68,b=161}, disallow={}}, {name='Developer', - shortHand='Dev', + short_hand='Dev', tag='[Dev]', - power=1, time=nil, colour={r=179,g=125,b=46}, disallow={}}, {name='Admin', - shortHand='Admin', + short_hand='Admin', tag='[Admin]', - power=2, time=nil, colour={r=233,g=63,b=233}, disallow={ @@ -72,9 +66,8 @@ local ranks = { }, {name='Mod', - shortHand='Mod', + short_hand='Mod', tag='[Mod]', - power=3, time=nil, colour={r=0,g=170,b=0}, disallow={ @@ -82,33 +75,29 @@ local ranks = { }, {name='Donator', - shortHand='P2W', + short_hand='P2W', tag='[P2W]', - power=4, time=nil, colour={r=233,g=63,b=233}, disallow={}}, {name='Veteran', - shortHand='Vet', + short_hand='Vet', tag='[Veteran]', - power=4, time=600, colour={r=140,g=120,b=200}, disallow={}}, {name='Member', - shortHand='Mem', + short_hand='Mem', tag='[Member]', - power=5, time=nil, colour={r=24,g=172,b=188}, disallow={}}, {name='Regular', - shortHand='Reg', + short_hand='Reg', tag='[Regular]', - power=5, time=180, colour={r=24,g=172,b=188}, disallow={ @@ -119,9 +108,8 @@ local ranks = { }, {name='Guest', - shortHand='', + short_hand='', tag='[Guest]', - power=6, time=nil, colour={r=255,g=159,b=27}, disallow={ @@ -132,9 +120,8 @@ local ranks = { }, {name='Jail', - shortHand='Jail', + short_hand='Jail', tag='[Jail]', - power=7, time=nil, colour={r=50,g=50,b=50}, disallow={ @@ -146,6 +133,7 @@ local ranks = { } -- This For Loop cauess the disallows of each rank to be feed into the one below its self for n,rank in pairs(ranks) do + rank.power = n if ranks[n-1] then for _,disallow in pairs(ranks[n-1].disallow) do table.insert(rank.disallow,disallow) diff --git a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua index 506a9851..987b2538 100644 --- a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua +++ b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua @@ -19,23 +19,16 @@ local credits = {{ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- --this command is just a way or using loadstring from in game while keeping achevements -Event.register(defines.events.on_player_joined_game,function() - if commands.commands['server-interface'] then return end - commands.add_command('server-interface',' #2#',function(event) - if event.player_index then - local by_player = game.players[event.player_index] - if get_rank(by_player).power > 2 then by_player.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if event.parameter then else by_player.print('Invaid Input, /server-interface ') return end - local returned,value = pcall(loadstring(event.parameter)) - if type(value) == 'table' then game.write_file('log.txt', '\n Ran by: '..by_player.name..'\n Code: '..event.parameter..'\n $£$ '..table.to_string(value), true, 0) by_player.print(table.to_string(value)) - else game.write_file('log.txt', '\n Ran by: '..by_player.name..'\n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) by_player.print(value) end - else - if event.parameter then else print('Invaid Input, /server-interface ') return end - local returned,value = pcall(loadstring(event.parameter)) - if type(value) == 'table' then game.write_file('log.txt', '\n Ran by: \n Code: '..event.parameter..'\n $£$ '..table.to_string(value), true, 0) print(table.to_string(value)) - else game.write_file('log.txt', '\n Ran by: \n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) print(value) end - end - end) +define_command('server-interface','For use of the highest staff only',{'command',true},'admin',function(player,event,args) + if player == '' then + local returned,value = pcall(loadstring(event.parameter)) + if type(value) == 'table' then game.write_file('log.txt', '\n Ran by: \n Code: '..event.parameter..'\n $£$ '..table.to_string(value), true, 0) print(table.to_string(value)) + else game.write_file('log.txt', '\n Ran by: \n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) print(value) end + else + local returned,value = pcall(loadstring(event.parameter)) + if type(value) == 'table' then game.write_file('log.txt', '\n Ran by: '..player.name..'\n Code: '..event.parameter..'\n $£$ '..table.to_string(value), true, 0) player.print(table.to_string(value)) + else game.write_file('log.txt', '\n Ran by: '..player.name..'\n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) player.print(value) end + end end) --this is used when changing permsion groups when the person does not have permsion to function sudo(command,args) table.insert(global.sudo,{fun=command,var=args}) end diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua index 90bdc298..4fde1e24 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua @@ -111,7 +111,7 @@ function player_table_functions.draw(player,frame,filters,input_location) then player_table.add{name=p.name.."status", type="label", caption="Online"} else player_table.add{name=p.name.."s", type="label", caption="Offline"} end player_table.add{name=p.name.."online_time", type="label", caption=(tick_to_hour(p.online_time)..'H '..(tick_to_min(p.online_time)-60*tick_to_hour(p.online_time))..'M')} - player_table.add{name=p.name.."rank", type="label", caption=get_rank(p).shortHand} + player_table.add{name=p.name.."rank", type="label", caption=get_rank(p).short_hand} end end end diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua index 90f5d309..e52ae2f3 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -33,7 +33,10 @@ function toolbar.draw(player) toolbar_frame.clear() for _,btn in pairs(toolbar.buttons) do local rank = get_rank(player) - if btn[2] >= rank.power then + local temp_restriction = nil + if type(btn[2]) == 'number' then temp_restriction = btn[2] end + local restriction = temp_restriction or string_to_rank(btn[2]).power or 0 + if restriction >= rank.power then ExpGui.add_input.draw_button(toolbar_frame,btn[1]) end end diff --git a/locale/ExpGaming-Core/file-header.lua b/locale/ExpGaming-Core/file-header.lua index c6953436..275144b0 100644 --- a/locale/ExpGaming-Core/file-header.lua +++ b/locale/ExpGaming-Core/file-header.lua @@ -24,6 +24,7 @@ credit_loop(require("ExpGaming - Rank Table")) credit_loop(require("ExpGaming - Rank Presets")) credit_loop(require("ExpGaming - Rank Control")) credit_loop(require("GUI/file-header")) +credit_loop(require("ExpGaming - Command Maker")) credit_loop(require("ExpGaming - Server Interface")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file