This commit is contained in:
Cooldude2606
2017-11-29 19:42:24 +00:00
parent 6538459e82
commit 023c25ba2f
20 changed files with 471 additions and 1601 deletions

View File

@@ -7,35 +7,3 @@ Any changes that you may make to the code are yours but that does not make the s
Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
--set up to run other code and events
require("mod-gui")
Event = require("locale/StdLib/event")
--this is the main code that starts the softmod
Event.soft_init = script.generate_event_name()
local function init() if not global.soft_init then global.exp_core = {} script.raise_event(Event.soft_init,{tick=game.tick}) global.soft_init = true end end
Event.register(defines.events.on_player_joined_game,init)
Event.register(defines.events.on_tick,init)
Event.register(-1,init)
--below 'game.tick/(3600*game.speed)) % 15 == 0' raises the gui_update event every 15 minutes - feel free to change the update time
Event.gui_update = script.generate_event_name()
Event.register(defines.events.on_tick, function(event)
if (event.tick/(3600*game.speed)) % 15 == 0 then
-- updates the guis for every player (if gui is linked to gui_update)
local online_players = #game.connected_players
for i,player in pairs(game.connected_players) do
script.raise_event(Event.gui_update,{tick=event.tick,player=player,player_loop_index=i,players_online=online_players})
end
elseif ((event.tick/(3600*game.speed))+(15/2))% 15 == 0 then
-- this is the system to auto rank players
for i,player in pairs(game.connected_players) do
server.queue_callback(ranking.find_new_rank,{player,event.tick})
end
end
end)
--loads core files
ranking,ExpGui,server = unpack(require("locale/ExpGaming-Core/file-header"))
--loads all the other scripts
require("locale/Stand-Alone/file-header")
require("locale/ExpGaming-Addons/file-header")
--call from command maker
load_commands()

View File

@@ -1,124 +0,0 @@
# Functions added in core
See code for more details. (may not be upto date as im lazy)
## GUI
### Defining
* ExpGui.add_frame.center(name,default_display,default_tooltip,tabs,event)
* tabs (opt) = {{name},{...},...}
* event (opt) = on draw -> function(player,frame)
* ExpGui.add_frame.tab(name,default_display,default_tooltip,frame,event)
* frame = 'frame name'
* event = on draw -> function(player,frame)
* ExpGui.add_frame.left(name,default_display,default_tooltip,vis,event)
* vis = player on join -> true/false
* event = on draw -> function(player,frame)
* ExpGui.add_frame.popup(style,default_display,default_tooltip,on_click,event)
* on_click = on draw for toolbar -> function(player,element)
* event = on draw for popup -> function(player,frame,args)
* ExpGui.toolbar.add_button(name,default_display,default_tooltip,event)
* event = on click -> function(player,element)
* ExpGui.add_input.button(name,default_display,default_tooltip,event)
* event = on click -> function(player,element)
* ExpGui.add_input.text(name,default_display,event)
* event = on text change -> function(player,element)
### Drawing
* ExpGui.toggle_visible(frame)
* Toggles the visibility of a frame
* ExpGui.player_table.draw_filters(player,frame,filters)
* filters = {filter-name,...}
* ExpGui.player_table.draw(player,frame,filters,input_location)
* filters = {{'filter name',value},{'filter name'},{...},...}
* input_location = GUI element -> draw_filters frame
* ExpGui.draw_frame.left(player,element,update)
* element = 'frame name'
* update = true
* ExpGui.draw_frame.popup(style,args)
* style = 'style name'
* args = {...}
* ExpGui.add_input.draw_button(frame,name,display,tooltip)
* display (opt)
* tooltip (opt)
* ExpGui.add_input.draw_text(frame,name,display)
* display (opt)
## Ranks
* ranking.get_player_rank(player)
* Get the players rank
* ranking.string_to_rank(string)
* Convert a rank name to the rank object
* ranking.rank_print(msg, rank, inv)
* rank = 'rank name'
* inv = lower ranks rather than higher -> true/false/nil
* ranking.give_rank(player,rank,by_player)
* rank = 'rank name'
* by_player = player or nil
* ranking.revert_rank(player,by_player)
* by_player = player or nil
* ranking.find_new_rank(player)
* Looks in presets if play time under 5 minutes
* Otherwise looks at play time
* Event.rank_change
* event is raised upon rank change -> event = {player,by_player,new_rank,old_rank}
## Lib
* Factorio StdLib game, event and core
* tick_to_display_format(tick)
* output -> 0H 0M or 0.00M when less than 10
* tick_to_hour (tick)
* Convert ticks to hours based on game speed
* tick_to_min (tick)
* Convert ticks to minutes based on game speed
* table.tostring(tbl)
* We stole this but we don't know from where, just google it
* output -> table as a string
## Get Commands
* server.get_uuid_data(uuid)
* uuid = value retured by callback
* returnd the data stored here
* server.get_callback_queue_info(string)
* return either a list or string based on the string boliean
* ranking.get_ranks(part)
* returns a list of all the ranks
* part (opt) = part of the rank you want to return ie name
* ranking.get_player_rank_presets(rank)
* returns the current rank presets
* rank (opt) = rank name if only one rank is needed
* ranking.get_ranked_players(rank)
* returns the ranks and online time of every player
* rank (opt) = limits it to only this rank
* get_commands(rank)
* returns all commands that are useable
* rank (opt) = rank name to limt it to what that rank can use
## Server
* server.queue_callback(command,args,uuid)
* Ask server to run a script function at a diffrent time
* command = function to be ran
* args (as function needs) = {...}
* uuid (opt) = the uuid that it will return (use with get_uuid_data)
* returns the uuid
* server.add_callback(callback,uuid)
* Sets a function in memory
* used with /socket to run
* callbacl = function to save to memory
* uuid = sting for a custom uuid
* server.refresh_uuid(uuid,value,offset)
* uuid = location of the data to be refreshed
* value (opt) = new value if making a new temp varible
* offset (opt) = if the base time is too short, for very big commands
* server.get_uuid(string)
* returns the same value that queue_callback would when given a custom return name
* will return the same as callback but cant be used to get the value of a previous callback
* server.emit(code, callback)
* you dont see this i was just asked to add it
## Other
* server.clear_callbacks()
* resets the callback system
* define_command(name,help,inputs,event)
* Add game commands in a way it does not cause crashes
* name = 'test' -> /test
* help = 'help message'
* inputs = {'input name',...,true/nil} last value being true means no cap on the length
* event = on command -> function(player,event,args)
* command: /server-interface
* Run loadstring on lua code given like /c but does not break achievements
* command: /debug
* same as server-interface but runs in debug mode
* command: /socket
* its just magic ok, its for server sync

View File

@@ -1,111 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local Exp_commands = {}
--Used mainly by the code to convert the inputs into a string
local function command_inputs_to_string(command)
local str_inputs = ''
for _,input in pairs(command.inputs) 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
local function get_command_args(event,command,allow_invaild)
local args = {}
if not event.parameter then
if #command.inputs > 0 then
if allow_invaild then return args end
return 'Invalid'
end
return args
end
for word in event.parameter:gmatch('%S+') do table.insert(args,word) end
if allow_invaild then return args end
if command.inputs[#command.inputs] == true then
if #args < #command.inputs-1 then return 'Invalid' end
else
if #args ~= #command.inputs then return 'Invalid' end
end return args
end
--name is what is used in /command
--help is the help info given
--inputs is a list i.e. {'name','message',true} the last value being true opposed to a string allows a variable number of words for the last input i.e. message can be multiple words long
--event(player,event,args) if the function that will be ran on the command use
function define_command(name,help,inputs,event)
if not name then error('Command requires a name') end
local help = help or {'commands.no-help'}
local inputs = inputs or {true}
if not event or type(event) ~= 'function' then error('Command requires a function') end
Exp_commands[name]={name=name,help=help,inputs=inputs,event=event}
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
local function load_command(command_data)
--is the command all ready loaded
if commands.commands[command_data.name] then return end
--start loading command
debug_write({'COMMAND','LOAD'},command_data.name)
--add command to game
debug_write({'COMMAND','LOAD'},command_data)
commands.add_command(command_data.name,{'commands.help-format',command_inputs_to_string(command_data),command_data.help},function(event)
--gets the command data
local command = Exp_commands[event.name]
debug_write({'COMMAND','RUN','START'},command.name)
debug_write({'COMMAND','RUN','PLAYER-INDEX'},event.player_index)
if event.player_index then
--player ran command so authoriz it
local player = game.players[event.player_index]
if not ranking.rank_allowed(ranking.get_player_rank(player),command.name) then
debug_write({'COMMAND','RUN','ALLOWED'},false)
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)
return
end
--start prossessing command inputs, check if valid
debug_write({'COMMAND','RUN','ALLOWED'},true)
local args = get_command_args(event,command)
debug_write({'COMMAND','RUN','ARGS'},args)
if args == 'Invalid' then
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)
return
end
--run the callback function of the command
debug_write({'COMMAND','RUN','FUNCTION'},command.name)
command.event(player,event,args)
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)
else
--server ran command so skip authorizion
local args = get_command_args(event,command)
if args == 'Invalid' then print('Invalid Input, /'..command.name..' '..command_inputs_to_string(command)) return end
debug_write({'COMMAND','RUN','ARGS'},args)
--run the callback function of the command
debug_write({'COMMAND','RUN','FUNCTION'},command.name)
command.event('<server>',event,args)
print('Command Complete')
game.write_file('commands.log','\n'..game.tick..' Player: <server> Used command: '..command.name..' With args of: '..table.tostring(args), true, 0)
end
debug_write({'COMMAND','RUN','END'},command.name,true)
end)
end
-- returns all the commands in a certain rank restriction
function get_commands(rank)
local rank = rank or 'Owner'
local to_return = {}
for command_name,command in pairs(Exp_commands) do
if ranking.rank_allowed(ranking.string_to_rank(rank),command_name) then table.insert(to_return,command) end
end
return to_return
end
-- loads all the commands, call once all script have been loaded
function load_commands()
for command_name,command in pairs(Exp_commands) do load_command(command) end
end

View File

@@ -1,121 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
--Convert ticks to 12H 34M format or 8.97M when less than 10
function tick_to_display_format(tick)
if tick_to_min(tick) < 10 then
return string.format('%.2f M',tick/(3600*game.speed))
else
return string.format('%d H %d M',tick_to_hour(tick),tick_to_min(tick)-60*tick_to_hour(tick))
end
end
--Convert ticks into hours based on game speed
function tick_to_hour (tick)
return math.floor(tick/(216000*game.speed))
end
--Convert ticks into minutes based on game speed
function tick_to_min (tick)
return math.floor(tick/(3600*game.speed))
end
--used to make uuids but may be useful else where
function string.tohex(str)
return (str:gsub('.', function (c)
return string.format('%02X', string.byte(c))
end))
end
--I stole this from somewhere a long time ago but this and the other two functions convert a table into a string
function table.val_to_str ( v )
if "string" == type( v ) then
v = string.gsub( v, "\n", "\\n" )
if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
return "'" .. v .. "'"
end
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
else
return "table" == type( v ) and table.tostring( v ) or
"function" == type( v ) and '"cant-display-function"' or
"userdata" == type( v ) and '"cant-display-userdata"' or
tostring( v )
end
end
function table.key_to_str ( k )
if "string" == type( k ) and string.match( k, "^[_%player][_%player%d]*$" ) then
return k
else
return "[" .. table.val_to_str( k ) .. "]"
end
end
function table.tostring( tbl )
local result, done = {}, {}
for k, v in ipairs( tbl ) do
table.insert( result, table.val_to_str( v ) )
done[ k ] = true
end
for k, v in pairs( tbl ) do
if not done[ k ] then
table.insert( result,
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
end
end
return "{" .. table.concat( result, "," ) .. "}"
end
-- converts a table to json and logs it to a file
function json_log(lua_table,no_log)
local result, done, only_indexs = {}, {}, true
for key,value in ipairs(lua_table) do
done[key] = true
if type(value) == 'table' then table.insert(result,json_log(value,true))
elseif type(value) == 'string' then table.insert(result,'"'..value..'"')
elseif type(value) == 'number' then table.insert(result,value)
elseif type(value) == 'boolean' then table.insert(result,tostring(value))
else table.insert(result,'null') end
end
for key,value in pairs(lua_table) do
if not done[key] then
only_indexs = false
if type(value) == 'table' then table.insert(result,'"'..key..'":'..json_log(value,true))
elseif type(value) == 'string' then table.insert(result,'"'..key..'":"'..value..'"')
elseif type(value) == 'number' then table.insert(result,'"'..key..'":'..value)
elseif type(value) == 'boolean' then table.insert(result,'"'..key..'":'..tostring(value))
else table.insert(result,'"'..key..'":null') end
end
end
if only_indexs then
if no_log then return "["..table.concat(result,",").."]"
else game.write_file('json.data',"["..table.concat(result,",").."]\n",true,0) end
else
if no_log then return "{"..table.concat(result,",").."}"
else game.write_file('json.data',"{"..table.concat(result,",").."}\n",true,0) end
end
end
--this will long the value of all varibles in script - will most lickely lag - useful for fixing desyncs
function log_G()
local index = 0
for k,v in pairs(_G) do
index = index + 1
if index ~= 26 and index ~= 1 then
if type(v) == 'table' then log(k..' '..table.tostring(v))
elseif type(v) == 'function' then log(k..' function')
else log(k..' '..tostring(v)) end
end
end
end
-- allows a simple way to debug code; idenitys = {'string1','string2'}; string will be writen to file; no_trigger dissables the trigger useful for on_tick events
function debug_write(idenitys,string,no_trigger)
if global.exp_core and global.exp_core.debug.state then
if type(string) == 'table' then string = table.tostring(string)
elseif type(string) ~= 'string' then string = tostring(string) end
if not no_trigger or global.exp_core.debug.triggered then game.write_file('debug.log', '\n['..table.concat(idenitys, " " )..'] '..string, true, 0) end
if not no_trigger then global.exp_core.debug.triggered = true end
end
end
Event.register(defines.events.on_tick,function() debug_write({'NEW TICK'},game.tick,true) end)
Event.register(Event.soft_init,function() global.exp_core.debug={state=false,triggered=false,force=false} end)

View File

@@ -1,205 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ranking = {}
ranking.get_ranks,ranking.get_rank_groups = unpack(require("ExpGaming - Rank Table"))
--Return the rank of a given player
function ranking.get_player_rank(player)
if player then
debug_write({'RANK','PLAYER-GET'},player.name)
for _,rank in pairs(ranking.get_ranks()) do
if player.permission_group == game.permissions.get_group(rank.name) then return rank end
end
return ranking.string_to_rank_group('User').lowest_rank
end
end
--Convert the name of a rank into the rank object
function ranking.string_to_rank(string)
if type(string) == 'string' then
local found_ranks={}
for _,rank in pairs(ranking.get_ranks()) do
if rank.name:lower() == string:lower() then return rank end
if rank.name:lower():find(string:lower()) then table.insert(found_ranks,rank) end
end
if #found_ranks == 1 then return found_ranks[1] end
end
end
--converts the name of a group to the group object
function ranking.string_to_rank_group(string)
if type(string) == 'string' then
local found_groups={}
for _,group in pairs(ranking.get_rank_groups()) do
if group.name:lower() == string:lower() then return group end
if group.name:lower():find(string:lower()) then table.insert(found_groups,group) end
end
if #found_groups == 1 then return found_groups[1] end
end
end
-- surches the rank for a certain allow command
function ranking.rank_allowed(rank,is_allowed)
for _,allow in pairs(rank.allow) do
if allow == is_allowed then return true end
end
return false
end
--Send a message to all members of this rank and above, if no rank given default is mod
--inv sends message to all lower ranks rather than higher
function ranking.rank_print(msg, rank, inv)
local rank = ranking.string_to_rank(rank) or ranking.string_to_rank_group('Moderation').lowest_rank -- default mod or higher
local inv = inv or false
debug_write({'RANK','PRINT'},rank.name..': '..tostring(msg))
for _, player in pairs(game.players) do
--this part uses sudo to soread it other many ticks
local player_rank_power = ranking.get_player_rank(player).power
if inv then
server.queue_callback(function(player_rank_power,rank)
if player_rank_power >= rank.power then player.print({'ranking.all-rank-print',msg}) end
end,{player_rank_power,rank})
else
server.queue_callback(function(player_rank_power,rank)
if player_rank_power <= rank.power then
if rank.short_hand ~= '' then player.print{'ranking.rank-print',rank.short_hand,msg} else player.print{'ranking.all-rank-print',msg} end
end
end,{player_rank_power,rank})
end
end
end
--Give the user their new rank and raise the Event.rank_change event
function ranking.give_rank(player,rank,by_player,tick)
if not player or not player.valid then return end
local tick = tick or game.tick
local by_player = by_player or 'server'
local rank = ranking.string_to_rank(rank) or rank or ranking.string_to_rank_group('User').lowest_rank
local old_rank = ranking.get_player_rank(player)
-- to reducse lag if the ranks are all ready given it does not cheak
if old_rank == rank then return end
--messaging
local message = 'ranking.rank-down'
if rank.power <= old_rank.power then message = 'ranking.rank-up' end
if by_player.name then
debug_write({'RANK','GIVE'},'player: '..player.name..' by player: '..by_player.name..' new rank: '..rank.name..' old rank: '..old_rank.name)
ranking.rank_print({message,player.name,rank.name,by_player.name},'Guest')
else
debug_write({'RANK','GIVE'},'player: '..player.name..' by player: <server> new rank: '..rank.name..' old rank: '..old_rank.name)
ranking.rank_print({message,player.name,rank.name,'<server>'},'Guest')
end
if rank.name ~= ranking.string_to_rank_group('User').lowest_rank.name then player.print({'ranking.rank-given',rank.name}) end
if player.tag ~= old_rank.tag and player.tag ~= '' then player.print({'ranking.tag-reset'}) end
--rank change
player.permission_group = game.permissions.get_group(rank.name)
player.tag = ranking.get_player_rank(player).tag
if old_rank.name ~= 'Jail' then global.exp_core.old_ranks[player.index]=old_rank.name end
script.raise_event(Event.rank_change, {tick=tick, player=player, by_player=by_player, new_rank=rank, old_rank=old_rank})
end
--Revert the user's rank to what it was before the lastest change
function ranking.revert_rank(player,by_player)
local rank = ranking.string_to_rank(global.exp_core.old_ranks[player.index])
ranking.give_rank(player,rank,by_player)
end
--Give the player a new rank based on playtime and/or preset ranks
function ranking.find_new_rank(player,tick)
debug_write({'RANK','NEW-RANK','START'},player.name)
local function loop_preset_rank(players,rank)
debug_write({'RANK','NEW-RANK','LOOP-PRESET'},rank)
for _,p in pairs(players) do
if player.name:lower() == p:lower() then return rank end
end
end
local tick = tick or game.tick
local player_rank = ranking.get_player_rank(player)
local possible_ranks = {player_rank}
--Loop through preset ranks only if playtime is less than 5 minutes
debug_write({'RANK','NEW-RANK','PRESET-CHEAK'},tick_to_min(player.online_time))
if tick_to_min(player.online_time) < 5 then
debug_write({'RANK','NEW-RANK','PRESET-START'},player.name)
for rank,players in pairs(ranking.get_player_rank_presets()) do
local found_rank = loop_preset_rank(players, rank)
if found_rank then debug_write({'RANK','NEW-RANK','ADD'},found_rank) table.insert(possible_ranks,ranking.string_to_rank(found_rank)) break end
end
end
-- to reduce lag if the player is already higher than any time rank then it does not cheak
-- also there play time must be higher than the lowest required for a rank
debug_write({'RANK','NEW-RANK','TIME-CHEAK'},tick_to_min(player.online_time))
if player_rank.power > global.exp_core.ranks.highest_timed_rank.power and tick_to_min(player.online_time) >= global.exp_core.ranks.lowest_timed_rank.time then
debug_write({'RANK','NEW-RANK','TIME-START'},player.name)
--Loop through rank times
for _,rank in pairs(ranking.get_ranks()) do
if rank.time then debug_write({'RANK','NEW-RANK','START'},rank.name..' '..rank.time) end
if rank.time and tick_to_min(player.online_time) >= rank.time then debug_write({'RANK','NEW-RANK','ADD'},rank.name) table.insert(possible_ranks,rank) end
end
end
--Loop through possible ranks
debug_write({'RANK','NEW-RANK','JAIL-CHEAK'},player_rank.name)
if player_rank.name ~='Jail' then
debug_write({'RANK','NEW-RANK','GIVE','START'},possible_ranks)
local highest_rank = possible_ranks[1]
for _,rank in pairs(possible_ranks) do
debug_write({'RANK','NEW-RANK','GIVE','POSSIBLE-CHEAK'},rank.name)
if rank.power < highest_rank.power then highest_rank = rank end
end
debug_write({'RANK','NEW-RANK','GIVE','HIGHEST'},highest_rank.name)
--Give player new rank if availble
if highest_rank.name == ranking.string_to_rank_group('User').lowest_rank.name then
-- to avoid spam in chat
debug_write({'RANK','NEW-RANK','GIVE','VIA-SERVER'},player.name..' '..highest_rank.name)
player.tag = highest_rank.tag
player.permission_group=game.permissions.get_group('Guest')
ExpGui.toolbar.draw(player)
else
debug_write({'RANK','NEW-RANK','GIVE','VIA-GIVE-RANK'},player.name..' '..highest_rank.name)
if highest_rank ~= player_rank then ranking.give_rank(player,highest_rank,nil,tick) end
end
debug_write({'RANK','NEW-RANK','GIVE','END'},player.name)
end
--Lose ends
if ranking.get_player_rank(player).power <= ranking.string_to_rank_group('Moderation').lowest_rank.power and not player.admin then ranking.rank_print(player.name..' needs to be promoted.') end
if player_rank.name ~= ranking.get_player_rank(player).name then global.exp_core.old_ranks[player.index]=player_rank.name end
debug_write({'RANK','NEW-RANK','END'},player.name)
end
-- returns a list with every players current rank, or just the players of the rank given, includes online time
function ranking.get_ranked_players(rank)
local to_return = {}
for _,player in pairs(game.players) do
if not rank or rank == ranking.get_player_rank(player).name then
table.insert(to_return,{player.name,tick_to_display_format(player.online_time),ranking.get_player_rank(player).name})
end
end
return to_return
end
--Event handlers
Event.rank_change = script.generate_event_name()
Event.register(Event.rank_change,function(event)
debug_write({'RANK','EVENT'},event)
if event.new_rank.name == event.old_rank.name then return end
if not event.by_player == 'server' then
game.write_file('rank-change.log','\n'..game.tick..' Player: '..event.player.name..' Was given rank: '..event.new_rank.name..' By: '..event.by_player.name..' Their rank was: '..event.old_rank.name, true, 0)
end
if event.new_rank.name == 'Jail' then
local by_name = ''; if event.by_player == 'server' then by_name = '<server>' else by_name = event.by_player.name end
if global.temp_bans and global.temp_bans[event.player.name] then else
json_log({type='JAIL',colour='#ff5400',tick=game.tick,online=#game.connected_players,onlineMods=online_mods,username=event.player.name,by=by_name})
end
end
end)
Event.register(Event.soft_init,function()
debug_write({'RANK','SETUP'},'start')
global.exp_core.old_ranks = {}
global.exp_core.preset_ranks = {}
for _,rank in pairs(ranking.get_ranks()) do
debug_write({'RANK','SETUP'},'added: '..rank.name)
game.permissions.create_group(rank.name)
for _,toRemove in pairs(rank.disallow) do
debug_write({'RANK','SETUP'},'blocked: '..toRemove)
game.permissions.get_group(rank.name).set_allows_action(defines.input_action[toRemove],false)
end
end
end)
Event.register(defines.events.on_player_joined_game,function(event) ranking.find_new_rank(game.players[event.player_index]) end)
return ranking

View File

@@ -1,279 +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/r6dC2uK
--Please Only Edit Below This Line-----------------------------------------------------------
How to use groups:
name the name that you can use to refence it.
colour if present then all ranks in this group will have this colour.
disallow if present then all ranks in this group will have this added to their disallow.
allow if present then all ranks in this group will have this added to their allow.
highest_rank is asigned by the script to show the highest rank in this group.
lowest_rank is asigned by the script to show the lowest rank in this group.
How to add ranks:
Name is what will be used in the scripts and is often the best choice 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 emphasise GUI elements based on rank.
power is not in the list below as it is auto-defined by index but allows comparison between ranks.
group is the groups that this rank is apart of can be nil, group allow and disallow are non-inheritable.
disallow is a list containing input actions that the user can not perform.
allow is a list of custom commands and effects that that rank can use, all defined in the sctips.
For disallow, add to the list the end part of the input action
Example: defines.input_action.drop_item -> 'drop_item'
http://lua-api.factorio.com/latest/defines.html#defines.input_action
--]]
local ranks = {
--these are asigned during the rank set up
highest_timed_rank=nil,
lowest_timed_rank=nil,
number_of_ranks=0,
groups={
--note dont remove these groups but you may add more
--all but the management group is used to indentiy ranks by the script
{name='Management',
allow={'cheat-mode','debug'}
},
{name='Moderation',
disallow={
'set_allow_commands',
'edit_permission_group',
'delete_permission_group',
'add_permission_group'},
allow={
'temp-ban',
'rank_changer',
'clear-reports',
'limitless_tags',
'map-changes'}
},
{name='User',
allow={
'kill',
'tag',
'report',
'task_list',
'science_list',
'rocket_list',
'player_list',
'readme',
'rules_tab',
'chat_tab',
'commands_tab',
'players_tab',
'info',
'links_tab',
'servers_tab',
'warp-points'}
},
{name='Jail',
disallow={
'open_character_gui',
'begin_mining',
'start_walking',
'player_leave_game',
'rotate_entity',
'reverse_rotate_entity',
'select_gun',
'open_technology_gui',
'start_research',
'open_blueprint_library_gui',
'open_trains_gui',
'open_train_station_gui',
'use_item',
'build_item'}
}
},
ranks={
{name='Owner',
short_hand='Owner',
tag='[Owner]',
time=nil,
colour={r=170,g=0,b=0},
group='Management',
disallow={},
allow={}},
{name='Community Manager',
short_hand='Com Mngr',
tag='[Com Mngr]',
time=nil,
colour={r=150,g=68,b=161},
group='Management',
disallow={},
allow={}},
{name='Developer',
short_hand='Dev',
tag='[Dev]',
time=nil,
colour={r=179,g=125,b=46},
group='Management',
disallow={},
allow={'cheat-mode'}
},
{name='Admin',
short_hand='Admin',
tag='[Admin]',
time=nil,
colour={r=233,g=63,b=233},
group='Moderation',
disallow={},
allow={
'server-interface',
'tp-all',
'announcement',
'admin',
'force_modifiers_tab',
'player_modifiers_tab',
'adv_repair',
'free-warp'}
},
{name='Mod',
short_hand='Mod',
tag='[Mod]',
time=nil,
colour={r=0,g=170,b=0},
group='Moderation',
disallow={'server_command'},
allow={}
},
{name='Donator',
short_hand='P2W',
tag='[P2W]',
time=nil,
colour={r=233,g=63,b=233},
group='User',
disallow={},
allow={
'tp',
'repair',
'tree_remover',
'report_protection'}
},
{name='Veteran',
short_hand='Vet',
tag='[Veteran]',
time=600,
colour={r=140,g=120,b=200},
group='User',
disallow={},
allow={}},
{name='Member',
short_hand='Mem',
tag='[Member]',
time=nil,
colour={r=24,g=172,b=188},
group='User',
disallow={},
allow={'trusted_reporter','warp-point'}},
{name='Regular',
short_hand='Reg',
tag='[Regular]',
time=180,
colour={r=24,g=172,b=188},
group='User',
disallow={
'set_auto_launch_rocket',
'change_programmable_speaker_alert_parameters',
'drop_item'},
allow={'decon','edit_tasks'}
},
{name='Guest',
short_hand='',
tag='',
time=nil,
colour={r=255,g=159,b=27},
group='User',
disallow={
'build_terrain',
'remove_cables',
'launch_rocket',
'reset_assembling_machine',
'cancel_research'},
allow={}
},
{name='Jail',
short_hand='Jail',
tag='[Jail]',
time=nil,
colour={r=50,g=50,b=50},
group='Jail',
disallow={},
allow={}
}
}
}
-- rank table setup
-- group setup
for n,rank in pairs(ranks.ranks) do
local group = nil; for _,g in pairs(ranks.groups) do if g.name == rank.group then group = g break end end
if group and not group.highest_rank then group.highest_rank=rank end
if group then group.lowest_rank=rank end
if group and group.colour then rank.colour = group.colour end
end
-- group to rank setup
for n,group in pairs(ranks.groups) do
if group.allow and group.lowest_rank then
for _,allow in pairs(group.allow) do table.insert(group.lowest_rank.allow,allow) end
end
if group.disallow and group.highest_rank then
for _,disallow in pairs(group.disallow) do table.insert(group.highest_rank.disallow,disallow) end
end
end
-- rank setup
for n,rank in pairs(ranks.ranks) do
rank.power = n
if ranks.ranks[n-1] then
for _,disallow in pairs(ranks.ranks[n-1].disallow) do
table.insert(rank.disallow,disallow)
end
end
if rank.time and not ranks.highest_timed_rank then ranks.highest_timed_rank=rank end
if rank.time then ranks.lowest_timed_rank=rank end
ranks.number_of_ranks=ranks.number_of_ranks+1
end
for n = #ranks.ranks, 1, -1 do
local rank = ranks.ranks[n]
if ranks.ranks[n+1] then
for _,allow in pairs(ranks.ranks[n+1].allow) do
table.insert(rank.allow,allow)
end
end
end
-- returns a list off all the ranks, return only one part if given
local function get_ranks(part)
local to_return = {}
if part then
for _,rank in pairs(global.exp_core.ranks.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.exp_core.ranks.ranks end
return to_return
end
-- returns a list off all the groups, return only one part if given
local function get_rank_groups(part)
local to_return = {}
if part then
for _,group in pairs(global.exp_core.ranks.groups) do table.insert(to_return,group[part]) end
else to_return = global.exp_core.ranks.groups end
return to_return
end
-- Move the ranks to the global array
Event.register(Event.soft_init,function() global.exp_core.ranks = ranks end)
return {get_ranks, get_rank_groups}

View File

@@ -1,142 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local server = {}
--this command is just a way or using loadstring from in game while keeping achievements
define_command('server-interface',{'server.server-command-help'},{'command',true},function(player,event,args)
if player == '<server>' then
local returned,value = pcall(loadstring(event.parameter))
if type(value) == 'table' then game.write_file('server-interface.log', '\n'..game.tick..' Ran by: <server> Code: '..event.parameter..'\n Returned: '..table.tostring(value), true, 0) print(table.tostring(value))
else game.write_file('server-interface.log', '\n'..game.tick..' Ran by: <server> Code: '..event.parameter..'\nReturned: '..tostring(value), true, 0) print(value) end
else
local returned,value = pcall(loadstring(event.parameter))
if type(value) == 'table' then game.write_file('server-interface-players.log', '\n'..game.tick..' Ran by: '..player.name..' Code: '..event.parameter..'\n Returned: '..table.tostring(value), true, 0) player.print(table.tostring(value))
else game.write_file('server-interface-players.log', '\n'..game.tick..' Ran by: '..player.name..' Code: '..event.parameter..'\nReturned: '..tostring(value), true, 0) player.print(tostring(value)) end
end
end)
--runs a server interface command with debug on and does not return any values to the user
define_command('debug',{'server.debug-command-help'},{'command',true},function(player,event,args)
global.exp_core.debug.state = true
debug_write({'START'},game.tick..' '..event.parameter)
global.exp_core.debug.triggered = false
local returned,value = pcall(loadstring(event.parameter))
if global.exp_core.debug.triggered and #global.exp_core.server.callback_queue == 0 then debug_write({'END'},game.tick) global.exp_core.debug.state = false end
end)
--runs the preset callback with the uuid
define_command('socket',{'server.socket-command-help'},{'uuid','args'},function(player,event,args)
if global.exp_core.server.callbacks[args[1]] then
server.queue_callback(global.exp_core.server.callbacks[args[1]].fun,{unpack(args,2)},args[1])
end
end)
--this is used when changing permission groups when the person does not have permsion to, can also be used to split a large event accross multiple ticks
local commands_per_iteration = 50 --number of callback commands ran every callback iteration
local ticks_per_iteration = 1 --the number of ticks break before the next callback iteration
local temp_var_time = 1000/commands_per_iteration*ticks_per_iteration --temp vars allow callback funnctions to share data
--adds a callback and saves code to a file
function server.emit(code, callback)
if type(callback) == 'function' then
local uuid = server.add_callback(callback)
json_log({type='JS',id=uuid,code=code})
end
end
--adds a call back that can be ran with a command
function server.add_callback(callback,uuid)
if type(callback) == 'function' then
local args = args or {}
local uuid = uuid or server.get_uuid(callback)
debug_write({'callback','ADD'},uuid)
global.exp_core.server.callbacks[uuid]={fun=callback,uuid=uuid}
server.refresh_uuid(uuid)
return uuid
end
end
--adds a call back function to the queue uuid can be provided
function server.queue_callback(callback,args,uuid)
if type(callback) == 'function' then
local args = args or {}
local uuid = uuid or server.get_uuid(callback)
debug_write({'CALLBACK','QUEUE'},uuid)
table.insert(global.exp_core.server.callback_queue,{fun=callback,args=args,uuid=uuid})
server.refresh_uuid(uuid)
return uuid
end
end
-- clears all temp values and call backs in queue
function server.clear_callbacks()
global.exp_core.server = {callback_queue={},callbacks={},temp_varibles={}}
end
-- converts any value into the uuid the script will use
function server.get_uuid(var)
local uuid = nil
if type(var) == 'string' then uuid = var
else uuid = tostring(global.exp_core.uuids()) end
uuid = string.tohex('uuid'..uuid)
server.refresh_uuid(uuid)
return uuid
end
--update the time on a temp var or add it as a new one
function server.refresh_uuid(uuid,data,offset)
local offset = offset or temp_var_time
if global.exp_core.server.temp_varibles[uuid] and not data then
global.exp_core.server.temp_varibles[uuid].remove_time = game.tick+offset
else
local data = data or 'temp-var-temp-value'
global.exp_core.server.temp_varibles[uuid] = {data=data,remove_time=game.tick+offset}
end
end
-- gets the data stored in a temp varible
function server.get_uuid_data(uuid)
if global.exp_core.server.temp_varibles[uuid] then
server.refresh_uuid(uuid)
debug_write({'CALLBACK','TEMP-VAR'},uuid)
if global.exp_core.server.temp_varibles[uuid].data == 'temp-var-temp-value' then return nil end
return global.exp_core.server.temp_varibles[uuid].data
end return nil
end
-- returns the lenth of the temp varible list and command queue, is string is true then it is retured as a string
function server.get_callback_queue_info(string)
local lenth = 0
for _,v in pairs(global.exp_core.server.temp_varibles) do lenth = lenth + 1 end
if string then return {'server.callback-info',game.tick,#global.exp_core.server.callback_queue,lenth}
else return {tick=game.tick,commands=#global.exp_core.server.callback_queue,temp_varibles=#global.exp_core.server.temp_varibles} end
end
--callback main loop
Event.register(defines.events.on_tick, function(event)
--used with debug command will stop debuging once atleast one message is send to file and there are no commands in callback
if global.exp_core.debug.state and global.exp_core.debug.triggered and #global.exp_core.server.callback_queue == 0 then debug_write({'END'},game.tick) global.exp_core.debug.state = global.exp_core.debug.focre end
-- runs the commands in callback
debug_write({'CALLBACK'},server.get_callback_queue_info(),true)
if game.tick % ticks_per_iteration == 0 and global.exp_core.server.callback_queue and #global.exp_core.server.callback_queue > 0 then
-- gets the number of call backs to run
local length = nil
if #global.exp_core.server.callback_queue > commands_per_iteration then length = commands_per_iteration else length = #global.exp_core.server.callback_queue end
-- runs the right number of commands as set
for i = 1,length do
local callback=table.remove(global.exp_core.server.callback_queue,1)
if callback and callback.fun and type(callback.fun) == 'function' then
local args = {}
-- retrives any temp varibles
for n,value in pairs(callback.args) do
if type(value) == 'string' and global.exp_core.server.temp_varibles[value]
then args[n] = server.get_uuid_data(value)
else args[n] = value end
end
-- makes new temp value and runs command
local returns = callback.fun(unpack(args)) or {}
server.refresh_uuid(callback.uuid,returns)
end
end
end
-- removes old temp varibles
for uuid,data in pairs(global.exp_core.server.temp_varibles) do
if data.remove_time <= game.tick then global.exp_core.server.temp_varibles[uuid] = nil end
end
end)
Event.register(Event.soft_init,function() global.exp_core.server = {callback_queue={},callbacks={},temp_varibles={}} global.exp_core.uuids = game.create_random_generator() end)
return server

View File

@@ -1,82 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ExpGui = require("ExpGaming - Module Setup")
local add_frame = ExpGui.add_frame
local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame
--Add a frame in the center
--tabs {{name},{...}} is a list that can contain already defined tabs
--event(player,element) is an option to have a custom GUI in the center
function add_frame.center(name,default_display,default_tooltip,tabs,event)
if not name then error('Frame requires a name') end
local tabs = tabs or {}
frames.center[name] = {name=name,display=default_display,tabs=tabs,event=event}
ExpGui.toolbar.add_button(name,default_display,default_tooltip,draw_frame.center)
end
--Define a tab; frame is needed as every tab must be used once; event(player,tab) is the draw function
function add_frame.tab(name,default_display,default_tooltip,frame,event)
if not name then error('Tab requires a name') end
if not frame then error('Tab requires a frame') end
frames.tabs[name] = {name=name,display=default_display,frame=frame,event=event}
table.insert(frames.center[frame].tabs,name)
ExpGui.add_input.button(name,default_display,default_tooltip,draw_frame.tab)
end
--Draw the center GUI for the player; do not call manually, must use other functions to call
ExpGui.add_input.button('close_center',{'expgui.close-button'},{'expgui.close-button-tooltip'},function(player,element) element.parent.parent.parent.destroy() end)
function draw_frame.center(player,element)
local frame_data = frames.center[element.name]
debug_write({'GUI','CENTER'},player.name..' '..frame_data.name)
--setup so nothing will break (name is set as caption if display a sprite)
if player.gui.is_valid_sprite_path(frame_data.display) then frame_data.display = frame_data.name end
if player.gui.center[frame_data.name] then player.gui.center.clear() return else player.gui.center.clear() end
-- start drawing
local frame = player.gui.center.add{name=frame_data.name,type='frame',caption=frame_data.display,direction='vertical',style=mod_gui.frame_style}
if frame_data.event and type(frame_data.event) == 'function' then frame_data.event(player,frame) return end
-- if a custom draw is not set then it will do the default
local tab_bar_scroll = frame.add{type = "scroll-pane", name= "tab_bar_scroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"}
local tab_bar = tab_bar_scroll.add{type='flow',direction='horizontal',name='tab_bar'}
local tab = frame.add{type = "scroll-pane", name= "tab", vertical_scroll_policy="auto", horizontal_scroll_policy="never"}
-- draw tabs buttons for allowed tabs
local first_tab = nil
for n,tab_name in pairs(frame_data.tabs) do
if ranking.rank_allowed(ranking.get_player_rank(player),tab_name..'_tab') then
first_tab = first_tab or tab_name
debug_write({'GUI','CENTER','ADD'},tab_name)
ExpGui.add_input.draw_button(tab_bar,tab_name)
end
end
draw_frame.tab(player,tab_bar[first_tab])
ExpGui.add_input.draw_button(tab_bar,'close_center')
--sets the size of the gui
tab.style.minimal_height = 300
tab.style.maximal_height = 300
tab.style.minimal_width = 500
tab.style.maximal_width = 500
tab_bar_scroll.style.minimal_height = 60
tab_bar_scroll.style.maximal_height = 60
tab_bar_scroll.style.minimal_width = 500
tab_bar_scroll.style.maximal_width = 500
player.gui.center.add{type='frame',name='temp'}.destroy()--recenter the GUI
end
--Draw the tab into the center GUI for the player; do not call manually, must use other functions to call
function draw_frame.tab(player,element)
debug_write({'GUI','CENTER','OPEN-TAB'},element.name)
for _,btn in pairs(element.parent.children) do if btn.name == 'close_center' or btn.name == element.name then
btn.style.font_color = {r = 255, g = 255, b = 255,a=255}
else
btn.style.font_color = {r = 100, g = 100, b = 100,a=255}
end end
element.parent.parent.parent.tab.clear()
frames.tabs[element.name].event(player,element.parent.parent.parent.tab)
end
Event.register(Event.rank_change,function(event) event.player.gui.center.clear() end)
return ExpGui

View File

@@ -1,74 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ExpGui = require("ExpGaming - Module Setup")
local add_input = ExpGui.add_input
local inputs = ExpGui.inputs
--allows defining of new buttons;;name how to call button;;default_display what is shown on the button;;default_tooltip the tooltip display;;event function(player,element) that runs on click
function add_input.button(name,default_display,default_tooltip,event)
if not name then error('Button requires a name') end
inputs.buttons[name] = {name=name,display=default_display,tooltip=default_tooltip,event=event}
end
--allows defining of text box inputs;;name how to call button;;default_display what is shown on the button;;event function(player,element) that runs on text change
function add_input.text(name,default_display,event)
if not name then error('Text Filed requires a name') end
inputs.text[name] = {name=name,display=default_display,event=event}
end
--draws the button into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overrides the default;;tooltip(opptinal) overrides the default
function add_input.draw_button(frame,name,display,tooltip)
if not frame or not frame.valid then error('No frame to draw to') end
if not name then error('No button to draw') end
debug_write({'GUI','INPUT'},name)
if inputs.buttons[name] then
local button = inputs.buttons[name]
local display = display or button.display or {'expgui.button-no-display'}
local tooltip = tooltip or button.tooltip or {'expgui.button-no-tooltip'}
if type(display) == 'string' and frame.gui.is_valid_sprite_path(display) then
frame.add{name=name, type = "sprite-button", sprite=display, tooltip=tooltip, style = mod_gui.button_style}
else
frame.add{name=name, type = "button", caption=display, tooltip=tooltip, style = mod_gui.button_style}
end return
end
error('No Button by the name of '..name)
end
--draws the text into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overrides the default;;tooltip(opptinal) overrides the default
function add_input.draw_text(frame,name,display)
if not frame or not frame.valid then error('No frame to draw to') end
if not name then error('No text filed to draw') end
debug_write({'GUI','INPUT'},name)
if inputs.text[name] then
local text = inputs.text[name]
local display = display or text.display or {'expgui.text-no-display'}
frame.add{name=name, type='textfield'}
frame[name].caption=display
return
end
error('No Text by the name of '..name)
end
--the magic behind the buttons
Event.register(defines.events.on_gui_click, function(event)
local player = game.players[event.player_index]
if event.element.type == 'button' or event.element.type == 'sprite-button' then
if inputs.buttons[event.element.name] then
local button = inputs.buttons[event.element.name]
if button.event then button.event(player,event.element)
else ranking.rank_print('Button without Function '..button.name,'Mod') end
end
end
end)
--the magic behind the text inputs
Event.register(defines.events.on_gui_text_changed, function(event)
local player = game.players[event.player_index]
if inputs.text[event.element.name] then
local text = inputs.text[event.element.name]
if text.event then text.event(player,event.element) end
end
end)
return ExpGui

View File

@@ -1,67 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ExpGui = require("ExpGaming - Module Setup")
local add_frame = ExpGui.add_frame
local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame
--left GUIs are always present and only have their visibility toggled
--Add a frame to the left bar; event(player,frame) must be present for left GUIs as there is no default
--vis should be true or false based on the player join game state of the GUI
function add_frame.left(name,default_display,default_tooltip,vis,event)
if not name then error('Frame requires a name') end
if not event or type(event) ~= 'function' then error('Frame requires a draw function') end
local vis = vis or false
frames.left[name] = {name=name,display=default_display,event=event,vis=vis}
ExpGui.toolbar.add_button(name,default_display,default_tooltip,draw_frame.left)
end
--draw the left GUI for the player; called via script, only call manually when update is true and element is the name of the GUI
function draw_frame.left(player,element,update)
debug_write({'GUI','LEFT'},player.name)
local frame = nil
local frame_data = nil
local left = mod_gui.get_frame_flow(player)
debug_write({'GUI','LEFT','UPDATE'},update)
if not update then
-- either toggels visabilty or makes the gui
frame_data = frames.left[element.name]
if left[frame_data.name] then ExpGui.toggle_visible(left[frame_data.name]) return end
frame = left.add{name=frame_data.name,type='frame',caption=frame_data.display,direction='vertical',style=mod_gui.frame_style}
frame.style.visible = frame_data.vis
else
-- only clears the gui
frame_data = frames.left[element]
frame = left[frame_data.name]
end
-- draws the gui elements
if frame then frame.clear() frame_data.event(player,frame) end
end
--used to load all left GUIs
Event.register(defines.events.on_player_joined_game,function(event)
local player = game.players[event.player_index]
for _,frame_data in pairs(frames.left) do
local left = mod_gui.get_frame_flow(player)
if left[frame_data.name] then
-- if it has been made already then it updates it
ExpGui.draw_frame.left(player,frame_data.name,true)
else
-- makes the gui if its not made
ExpGui.draw_frame.left(player,{name=frame_data.name})
end
end
end)
--resets visabilty of guis on rank change
Event.register(Event.rank_change,function(event)
for _,frame_data in pairs(frames.left) do
local left = mod_gui.get_frame_flow(event.player)
if left[frame_data.name] then left[frame_data.name].style.visible = frame_data.vis end
end
end)
return ExpGui

View File

@@ -1,64 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
-- Mainly used as a plan for how the gui is stored also as a header for the credit
local ExpGui = {
add_frame={
--center
--tab
--left
--popup
},
draw_frame={
--center
--tab
--left
--popup
},
add_input={
--button
--text
--draw_button
--draw_text
},
toolbar={
buttons={}
--draw
--add_button
},
player_table={
filters={}
--draw
--draw_filters
--get_filters
--player_match
},
inputs={
buttons={},
text={}
},
frames={
center={},
tabs={},
left={},
popup={}
}
}
--simple function to toggle the visibility of a frame
function ExpGui.toggle_visible(frame)
if frame then
if frame.style.visible == nil then
frame.style.visible = false
else
frame.style.visible = not frame.style.visible
end
end
end
--Please Only Edit Above This Line-----------------------------------------------------------
return ExpGui

View File

@@ -1,114 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ExpGui = require("ExpGaming - Module Setup")
local player_table_functions = ExpGui.player_table
--filters that are used. Feel free to add more
player_table_functions.filters = {
--{name,is_text,function(player,input) return true/false end}
{name='is_admin',is_text=false,test=function(player) return player.admin end},
{name='player_name',is_text=true,test=function(player,input) if input and player.name:lower():find(input:lower()) then return true end end},
{name='online',is_text=false,test=function(player) return player.connected end},
{name='offline',is_text=false,test=function(player) return not player.connected end},
{name='online_time',is_text=true,test=function(player,input) if input and tonumber(input) and tonumber(input) < tick_to_min(player.online_time) then return true elseif not input or not tonumber(input) then return true end end},
{name='rank',is_text=true,test=function(player,input) if input and ranking.string_to_rank(input) and ranking.get_player_rank(player).power <= ranking.string_to_rank(input).power then return true elseif not input or not ranking.string_to_rank(input) then return true end end}
}
--set up all the text inputs
for _,filter in pairs(player_table_functions.filters) do
if filter.is_text then
ExpGui.add_input.text(filter.name,{'expgui.player-table-enter',filter.name:gsub('_',' ')},function(player,element) ExpGui.player_table.redraw(player,element) end)
end
end
--used to draw filters from the list above
function player_table_functions.draw_filters(player,frame,filters)
debug_write({'GUI','PLAYER-TABLE','DRAW-FILTERS'},player.name)
local input_bar = frame.add{type='flow',name='input_bar',direction='horizontal'}
for _,name in pairs(filters) do
local filter_data = nil
for _,filter in pairs(player_table_functions.filters) do if filter.name == name then filter_data = filter break end end
if filter_data and filter_data[2] then
ExpGui.add_input.draw_text(input_bar,name)
end
end
end
--used by script to get the values for the any inputs given by the user
function player_table_functions.get_filters(frame)
local filters = {}
for _,filter in pairs(player_table_functions.filters) do
if frame.input_bar[filter.name] then
if frame.input_bar[filter.name].text:find('%S') then
table.insert(filters,{filter.name,frame.input_bar[filter.name].text})
end
end
end
return filters
end
--used to test if a player matches filter criteria
function player_table_functions.player_match(player,filter,input)
for _,f in pairs(player_table_functions.filters) do
if filter == f or filter == f[1] then if filter == f[1] then filter = f break end end
end
if filter.test and type(filter.test) == 'function' then return filter.test(player,input) end
end
--used by script on filter texts
function player_table_functions.redraw(player,element)
local frame = global.exp_core.current_filters[player.index][2]
local filters = global.exp_core.current_filters[player.index][1]
player_table_functions.draw(player,frame,filters,element.parent.parent)
end
--used to draw the player table with filter that you want
--filter = {{'is_admin',true},{'offline',true},{'player_name'}} ; if the length is 2 then it will not attempt to get a user input
function player_table_functions.draw(player,frame,filters,input_location)
debug_write({'GUI','PLAYER-TABLE','START'},player.name)
global.exp_core.current_filters[player.index] = {filters,frame}
--setup the table
if frame.player_table then frame.player_table.destroy() end
local player_table = frame.add{name='player_table', type="table", colspan=5}
player_table.style.minimal_width = 500
player_table.style.maximal_width = 500
player_table.style.horizontal_spacing = 10
player_table.add{name="id", type="label", caption={"expgui.player-table-id"}}
player_table.add{name="player_name", type="label", caption={"expgui.player-table-name"}}
player_table.add{name="status", type="label", caption={"expgui.player-table-status"}}
player_table.add{name="online_time", type="label", caption={"expgui.player-table-online-time"}}
player_table.add{name="rank", type="label", caption={"expgui.player-table-rank"}}
for i,p in pairs(game.players) do
--filter cheaking
local add=true
for _,filter in pairs(filters) do
if #filter == 2 and add then
debug_write({'GUI','PLAYER-TABLE','CHEAK'},p.name..' '..fliter.name)
local result = player_table_functions.player_match(p,filter.name,filter.is_text)
if not result and filter.is_text == true then result = filter.is_text end
add = result or false
end
end
for _,filter in pairs(player_table_functions.get_filters(input_location)) do
if add then
debug_write({'GUI','PLAYER-TABLE','CHEAK'},p.name..' '..fliter.name)
add = player_table_functions.player_match(p,filter.name,filter.is_text) or false
end
end
--add the player
if add and not player_table[p.name.."_id"] then
debug_write({'GUI','PLAYER-TABLE','ADD'},p.name)
player_table.add{name=p.name.."_id", type="label", caption=i}
player_table.add{name=p.name..'_name', type="label", caption=p.name}
if p.connected == true
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_display_format(p.online_time)}
player_table.add{name=p.name.."rank", type="label", caption=ranking.get_player_rank(p).short_hand}
end
end
end
Event.register(Event.soft_init,function() global.exp_core.current_filters = {} end)
return ExpGui

View File

@@ -1,71 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ExpGui = require("ExpGaming - Module Setup")
local add_frame = ExpGui.add_frame
local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame
--used to draw the next popup frame
ExpGui.add_input.button('close_popup','X',{'expgui.popup-close-tooltip'},function(player,element) element.parent.destroy() end)
local function get_next_popup(popups,name)
if name then
local flow = popups.add{type='frame',name=name..'_on_click',direction='horizontal',style=mod_gui.frame_style}
local frame = flow.add{name='popup_frame',type='flow',direction='vertical'}
ExpGui.add_input.draw_button(flow,'close_popup') return frame
end
local current = 0
while true do if popups['popup'..current] then current = current+1 else break end end
local flow = popups.add{type='frame',name='popup'..current,direction='horizontal',style=mod_gui.frame_style}
local frame = flow.add{name='popup_frame',type='flow',direction='vertical'}
ExpGui.add_input.draw_button(flow,'close_popup')
return frame
end
--adds a frame to the popup flow
--on_click(player,element) is what is called when button is clicked if nil no button is made
--event(player,frame,args)
--frame is where it will be drawn to; args is any info you want to pass in
function add_frame.popup(style,default_display,default_tooltip,on_click,event)
if not style then error('Popup style requires a name') end
if not event or type(event) ~= 'function' then error('Popup style requires a draw function') end
frames.popup[style] = {style=style,display=default_display,on_click=on_click,event=event}
if on_click and type(on_click) == 'function' then
ExpGui.toolbar.add_button(style,default_display,default_tooltip,draw_frame.popup_button)
end
end
--draw the popup on_click GUI for the player; do not call manually must use other functions to call
function draw_frame.popup_button(player,element)
debug_write({'GUI','POPUP-BUTTON'},player.name)
local frame_data = frames.popup[element.name]
local popups = mod_gui.get_frame_flow(player).popups
if popups[frame_data.style..'_on_click'] then popups[frame_data.style..'_on_click'].destroy() return end
local frame = get_next_popup(popups,frame_data.style)
frame_data.on_click(player,frame)
end
--used to draw a popup style can be called at any time; can not be called from a button directly
function draw_frame.popup(style,args)
local args = args or {}
local frame_data = frames.popup[style]
debug_write({'GUI','POPUP','STYLE'},style)
debug_write({'GUI','POPUP','ARGS'},args)
game.write_file('popups.log','\n'..game.tick..' Popup Style: '..style..' Was made with args of: '..table.tostring(args), true, 0)
for _,player in pairs(game.connected_players) do
debug_write({'GUI','POPUP','PLAYERS'},player.name)
local popups = mod_gui.get_frame_flow(player).popups
local frame = get_next_popup(popups)
frame_data.event(player,frame,args)
end
end
--used to make the popup area
Event.register(defines.events.on_player_joined_game,function(event)
if not mod_gui.get_frame_flow(game.players[event.player_index]).popups then
mod_gui.get_frame_flow(game.players[event.player_index]).add{name='popups',type='flow',direction='vertical'}
end
end)
return ExpGui

View File

@@ -1,35 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local ExpGui = require("ExpGaming - Module Setup")
local toolbar = ExpGui.toolbar
--similar to ExpGui.add_input.button but it also accepts a restriction and button is drawn to the toolbar
function toolbar.add_button(name,default_display,default_tooltip,event)
if not name then error('Button requires a name') end
table.insert(toolbar.buttons,name)
ExpGui.add_input.button(name,default_display,default_tooltip,event)
end
--draw the toolbar to the player only showing buttons within their restriction
function toolbar.draw(player)
debug_write({'GUI','TOOLBAR'},player.name)
if not player then error('Need a player to draw to') end
local toolbar_frame = mod_gui.get_button_flow(player)
toolbar_frame.clear()
for _,button in pairs(toolbar.buttons) do
local rank = ranking.get_player_rank(player)
if ranking.rank_allowed(ranking.get_player_rank(player),button) then
debug_write({'GUI','TOOLBAR','ADD'},button)
ExpGui.add_input.draw_button(toolbar_frame,button)
end
end
end
--auto-redraw toolbar after new rank is given
Event.register(Event.rank_change,function(event) toolbar.draw(event.player) end)
return ExpGui

View File

@@ -1,18 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local function merge(first_table,second_table) for k,v in pairs(second_table) do first_table[k] = v end end
local ExpGui = require("ExpGaming - Module Setup")
merge(ExpGui,require("ExpGaming - Inputs"))
merge(ExpGui,require("ExpGaming - Toolbar"))
merge(ExpGui,require("ExpGaming - Center Gui"))
merge(ExpGui,require("ExpGaming - Left Gui"))
merge(ExpGui,require("ExpGaming - Popup"))
merge(ExpGui,require("ExpGaming - Player Table"))
return ExpGui

View File

@@ -1,17 +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/r6dC2uK
]]
--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!
require("ExpGaming - Lib")
local ranking = require("ExpGaming - Rank Control")
local ExpGui = require("GUI/file-header")
require("ExpGaming - Command Maker")
local server = require("ExpGaming - Server Interface")
--Please Only Edit Above This Line-----------------------------------------------------------
return {ranking,ExpGui,server}

View File

@@ -1,9 +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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------

View File

@@ -6,4 +6,19 @@ 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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
--[[
StdLib
This file allow you to only require this one file to return the diffent libarys.
The array returned contains the stdlib modules so there can be decleared after the file require
]]
local StdLib = {}
require 'core'
require 'game'
require 'table'
StdLib.Event = require 'event'
return StdLib

455
locale/StdLib/table.lua Normal file
View File

@@ -0,0 +1,455 @@
--- Extends Lua 5.2 table.
-- @module table
-- @see table
-- luacheck: globals table (Allow mutating global table)
--- Given a mapping function, creates a transformed copy of the table
--- by calling the function for each element in the table, and using
--- the result as the new value for the key. Passes the index as second argument to the function.
--- @usage a= { 1, 2, 3, 4, 5}
---table.map(a, function(v) return v * 10 end) --produces: { 10, 20, 30, 40, 50 }
--- @usage a = {1, 2, 3, 4, 5}
---table.map(a, function(v, k, x) return v * k + x end, 100) --produces { 101, 104, 109, 116, 125}
-- @tparam table tbl the table to be mapped to the transform
-- @tparam function func the function to transform values
-- @param[opt] ... additional arguments passed to the function
-- @treturn table a new table containing the keys and mapped values
function table.map(tbl, func, ...)
local newtbl = {}
for i, v in pairs(tbl) do
newtbl[i] = func(v, i, ...)
end
return newtbl
end
--- Given a filter function, creates a filtered copy of the table
--- by calling the function for each element in the table, and
--- filtering out any key-value pairs for non-true results. Passes the index as second argument to the function.
--- @usage a= { 1, 2, 3, 4, 5}
---table.filter(a, function(v) return v % 2 == 0 end) --produces: { 2, 4 }
--- @usage a = {1, 2, 3, 4, 5}
---table.filter(a, function(v, k, x) return k % 2 == 1 end) --produces: { 1, 3, 5 }
-- @tparam table tbl the table to be filtered
-- @tparam function func the function to filter values
-- @param[opt] ... additional arguments passed to the function
-- @treturn table a new table containing the filtered key-value pairs
function table.filter(tbl, func, ...)
local newtbl = {}
local insert = #tbl > 0
for k, v in pairs(tbl) do
if func(v, k, ...) then
if insert then table.insert(newtbl, v)
else newtbl[k] = v end
end
end
return newtbl
end
--- Given a candidate search function, iterates over the table, calling the function
--- for each element in the table, and returns the first element the search function returned true.
--- Passes the index as second argument to the function.
--- @usage a= { 1, 2, 3, 4, 5}
---table.find(a, function(v) return v % 2 == 0 end) --produces: 2
--- @usage a = {1, 2, 3, 4, 5}
---table.find(a, function(v, k, x) return k % 2 == 1 end) --produces: 1
-- @tparam table tbl the table to be searched
-- @tparam function func the function to use to search for any matching element
-- @param[opt] ... additional arguments passed to the function
-- @treturn ?|nil|Mixed the first found value, or nil if none was found
function table.find(tbl, func, ...)
for k, v in pairs(tbl) do
if func(v, k, ...) then
return v, k
end
end
return nil
end
--- Given a candidate search function, iterates over the table, calling the function
-- for each element in the table, and returns true if search function returned true.
-- Passes the index as second argument to the function.
-- @see table.find
--- @usage a= { 1, 2, 3, 4, 5}
---table.any(a, function(v) return v % 2 == 0 end) --produces: true
--- @usage a = {1, 2, 3, 4, 5}
---table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true
-- @tparam table tbl the table to be searched
-- @tparam function func the function to use to search for any matching element
-- @param[opt] ... additional arguments passed to the function
-- @treturn boolean true if an element was found, false if none was found
function table.any(tbl, func, ...)
return table.find(tbl, func, ...) ~= nil
end
--- Given a function, apply it to each element in the table.
-- Passes the index as the second argument to the function.
-- <p>Iteration is aborted if the applied function returns true for any element during iteration.
-- @usage
-- a = {10, 20, 30, 40}
-- table.each(a, function(v) game.print(v) end) --prints 10, 20, 30, 40, 50
-- @tparam table tbl the table to be iterated
-- @tparam function func the function to apply to elements
-- @param[opt] ... additional arguments passed to the function
-- @treturn table the table where the given function has been applied to its elements
function table.each(tbl, func, ...)
for k, v in pairs(tbl) do
if func(v, k, ...) then
break
end
end
return tbl
end
--- Returns a new array that is a one-dimensional recursive flattening of the given array.
-- For every element that is an array, extract its elements into the new array.
-- <p>The optional level argument determines the level of recursion to flatten.
--> This function flattens an integer-indexed array, but not an associative array.
-- @tparam array tbl the array to be flattened
-- @tparam[opt] uint level recursive levels, or no limit to recursion if not supplied
-- @treturn array a new array that represents the flattened contents of the given array
function table.flatten(tbl, level)
local flattened = {}
table.each(tbl,
function(value)
if type(value) == "table" and #value > 0 then
if level then
if level > 0 then
table.merge(flattened, table.flatten(value, level - 1), true)
else
table.insert(flattened, value)
end
else
table.merge(flattened, table.flatten(value), true)
end
else
table.insert(flattened, value)
end
end
)
return flattened
end
--- Given an array, returns the first element or nil if no element exists.
-- @tparam array tbl the array
-- @treturn ?|nil|Mixed the first element
function table.first(tbl)
return tbl[1]
end
--- Given an array, returns the last element or nil if no elements exist.
-- @tparam array tbl the array
-- @treturn ?|nil|Mixed the last element or nil
function table.last(tbl)
local size = #tbl
if size == 0 then return nil end
return tbl[size]
end
--- Given an array of only numeric values, returns the minimum or nil if no element exists.
-- @tparam {number,...} tbl the array with only numeric values
-- @treturn ?|nil|number the minimum value
function table.min(tbl)
if #tbl == 0 then return nil end
local min = tbl[1]
for _, num in pairs(tbl) do
min = num < min and num or min
end
return min
end
---Given an array of only numeric values, returns the maximum or nil if no element exists.
-- @tparam {number,...} tbl the array with only numeric values
-- @treturn ?|nil|number the maximum value
function table.max(tbl)
if #tbl == 0 then return nil end
local max = tbl[1]
for _, num in pairs(tbl) do
max = num > max and num or max
end
return max
end
--- Given an array of only numeric values, return the sum of all values, or 0 for empty arrays.
-- @tparam {number,...} tbl the array with only numeric values
-- @treturn number the sum of the numbers or zero if the given array was empty
function table.sum(tbl)
local sum = 0
for _, num in pairs(tbl) do
sum = sum + num
end
return sum
end
--- Given an array of only numeric values, returns the average or nil if no element exists.
-- @tparam {number,...} tbl the array with only numeric values
-- @treturn ?|nil|number the average value
function table.avg(tbl)
local cnt = #tbl
return cnt ~= 0 and table.sum(tbl) / cnt or nil
end
--- Merges two tables &mdash; values from first get overwritten by the second.
--- @usage
-- function some_func(x, y, args)
-- args = table.merge({option1=false}, args)
-- if opts.option1 == true then return x else return y end
-- end
-- some_func(1,2) -- returns 2
-- some_func(1,2,{option1=true}) -- returns 1
-- @tparam table tblA first table
-- @tparam table tblB second table
-- @tparam[opt=false] boolean array_merge set to true to merge the tables as an array or false for an associative array
-- @treturn array|table an array or an associated array where tblA and tblB have been merged
function table.merge(tblA, tblB, array_merge)
if not tblB then
return tblA
end
if array_merge then
for _, v in pairs(tblB) do
table.insert(tblA, v)
end
else
for k, v in pairs(tblB) do
tblA[k] = v
end
end
return tblA
end
-- copied from factorio/data/core/luablib/util.lua
--- Creates a deep copy of table without copying Factorio objects.
-- @usage local copy = table.deepcopy[data.raw.["stone-furnace"]["stone-furnace"]] -- returns a copy of the stone furnace entity
-- @tparam table object the table to copy
-- @treturn table a copy of the table
function table.deepcopy(object)
local lookup_table = {}
local function _copy(this_object)
if type(this_object) ~= "table" then
return this_object
elseif this_object.__self then
return this_object
elseif lookup_table[this_object] then
return lookup_table[this_object]
end
local new_table = {}
lookup_table[this_object] = new_table
for index, value in pairs(this_object) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(this_object))
end
return _copy(object)
end
--- Returns a copy of all of the values in the table.
-- @tparam table tbl the table to copy the keys from, or an empty table if tbl is nil
-- @tparam[opt] boolean sorted whether to sort the keys (slower) or keep the random order from pairs()
-- @tparam[opt] boolean as_string whether to try and parse the values as strings, or leave them as their existing type
-- @treturn array an array with a copy of all the values in the table
function table.values(tbl, sorted, as_string)
if not tbl then return {} end
local valueset = {}
local n = 0
if as_string then --checking as_string /before/ looping is faster
for _, v in pairs(tbl) do
n = n + 1
valueset[n] = tostring(v)
end
else
for _, v in pairs(tbl) do
n = n + 1
valueset[n] = v
end
end
if sorted then
table.sort(valueset,
function(x, y) --sorts tables with mixed index types.
local tx = type(x) == 'number'
local ty = type(y) == 'number'
if tx == ty then
return x < y and true or false --similar type can be compared
elseif tx == true then
return true --only x is a number and goes first
else
return false --only y is a number and goes first
end
end
)
end
return valueset
end
--- Returns a copy of all of the keys in the table.
-- @tparam table tbl the table to copy the keys from, or an empty table if tbl is nil
-- @tparam[opt] boolean sorted whether to sort the keys (slower) or keep the random order from pairs()
-- @tparam[opt] boolean as_string whether to try and parse the keys as strings, or leave them as their existing type
-- @treturn array an array with a copy of all the keys in the table
function table.keys(tbl, sorted, as_string)
if not tbl then return {} end
local keyset = {}
local n = 0
if as_string then --checking as_string /before/ looping is faster
for k, _ in pairs(tbl) do
n = n + 1
keyset[n] = tostring(k)
end
else
for k, _ in pairs(tbl) do
n = n + 1
keyset[n] = k
end
end
if sorted then
table.sort(keyset,
function(x, y) --sorts tables with mixed index types.
local tx = type(x) == 'number'
local ty = type(y) == 'number'
if tx == ty then
return x < y and true or false --similar type can be compared
elseif tx == true then
return true --only x is a number and goes first
else
return false --only y is a number and goes first
end
end
)
end
return keyset
end
--- Removes keys from a table by setting the values associated with the keys to nil.
-- @usage local a = {1, 2, 3, 4}
--table.remove_keys(a, {1,3}) --returns {nil, 2, nil, 4}
-- @usage local b = {k1 = 1, k2 = 'foo', old_key = 'bar'}
--table.remove_keys(b, {'old_key'}) --returns {k1 = 1, k2 = 'foo'}
-- @tparam table tbl the table to remove the keys from
-- @tparam {Mixed,...} keys an array of keys that exist in the given table
-- @treturn table tbl without the specified keys
function table.remove_keys(tbl, keys)
for i = 1, #keys do
tbl[keys[i]] = nil
end
return tbl
end
--- Returns the number of keys in a table, if func is passed only count keys when the function is true.
-- @tparam table tbl to count keys
-- @tparam[opt] function func to incremement counter
-- @param[optchain] ... additional arguments passed to the function
-- @treturn number The number of keys matching the function or the number of all keys if func isn't passed
-- @treturn number The total number of keys
-- @usage local a = { 1, 2, 3, 4, 5}
-- table.count_keys(a) -- produces: 5, 5
-- @usage local a = {1, 2, 3, 4, 5}
-- table.count_keys(a, function(v, k) return k % 2 == 1 end) -- produces: 3, 5
function table.count_keys(tbl, func, ...)
if type(tbl) ~= 'table' then return 0, 0 end
local count, total = 0, 0
for k, v in pairs(tbl) do
total = total + 1
if func then
if func(v, k, ...) then
count = count + 1
end
else
count = count + 1
end
end
return count, total
end
--- Returns an inverted (***{[value] = key,...}***) copy of the given table. If the values are not unique, the assigned key depends on the order of pairs().
-- @usage local a = {k1 = 'foo', k2 = 'bar'}
--table.invert(a) --returns {'foo' = k1, 'bar' = k2}
-- @usage local b = {k1 = 'foo', k2 = 'bar', k3 = 'bar'}
--table.invert(b) --returns {'foo' = k1, 'bar' = ?}
-- @tparam table tbl the table to invert
-- @treturn table a new table with inverted mapping
function table.invert(tbl)
local inverted = {}
for k, v in pairs(tbl) do
inverted[v] = k
end
return inverted
end
--- Return the size of a table using built in table_size function
-- @function size
-- @tparam table table to use
-- @treturn int size of the table
table.size = table_size
--- For all string or number values in an array map them to a key = true table
-- @usage local a = {"v1", "v2"}
-- table.array_to_dict_bool(a) -- return {["v1"] = true, ["v2"]= true}
-- @tparam table tbl the table to convert
-- @treturn table the converted table
function table.arr_to_bool(tbl)
local newtbl = {}
for _, v in pairs(tbl) do
if type(v) == "string" or type(v) == "number" then
newtbl[v] = true
end
end
return newtbl
end
-- Any thing below here i (cooldude2606) have added and was not here by default
--- Returns a value in a form able to be read as a value
-- @usage local a = 'value'
-- table.val_to_str(a) -- return '"value"'
-- @param v value to convert
-- @treturn string the converted value
function table.val_to_str(v)
if "string" == type( v ) then
v = string.gsub(v,"\n","\\n")
if string.match(string.gsub(v,"[^'\"]",""),'^"+$') then
return "'"..v.."'"
end
return '"'..string.gsub(v,'"', '\\"' )..'"'
else
return "table" == type( v) and table.tostring(v) or
"function" == type(v) and '"cant-display-function"' or
"userdata" == type(v) and '"cant-display-userdata"' or
tostring(v)
end
end
--- Returns a value in a form able to be read as a key
-- @usage local a = 'key'
-- table.key_to_str(a) -- return '["key"]'
-- @param k key to convert
-- @treturn string the converted key
function table.key_to_str (k)
if "string" == type(k) and string.match(k,"^[_%player][_%player%d]*$") then
return k
else
return "["..table.val_to_str(k).."]"
end
end
--- Returns a table in a form able to be read as a table
-- @usage local a = {k1='foo',k2='bar'}
-- table.tostring(a) -- return '"value"'
-- @param tbl table to convert
-- @treturn string the converted table
function table.to_string(tbl)
local result, done = {}, {}
for k, v in ipairs(tbl) do
table.insert(result,table.val_to_str(v))
done[k] = true
end
for k, v in pairs(tbl) do
if not done[k] then
table.insert(result,
table.key_to_str(k).."="..table.val_to_str(v))
end
end
return "{"..table.concat(result,",") .."}"
end

View File

@@ -1,35 +0,0 @@
[ranking]
all-rank-print=[Everyone]: __1__
rank-print=[__1__]: __2__
rank-up=__1__ was promoted to __2__ by __3__
rank-down=__1__ was demoted to __2__ by __3__
rank-given=You have been given the __1__ Rank!
tag-reset=Your Tag was reset due to a Rank change
[commands]
no-help=No Help Given
help-format= __1__ __2__
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
invalid-inputs=Invalid Input, /__1__ __2__
command-ran=Command Complete
[server]
server-command-help=For use of the highest staff only
debug-command-help=For use of the highest staff only, this will lag A LOT
socket-command-help=For use out side of factorio to run predefinded functions
callback-info=At game tick: __1__ Queue Lenth: __2__ Number of temp vars: __3__
[expgui]
button-no-display=No name
button-no-tooltip=Ask some one what this does
text-no-display=BLANK
close-button=Close
close-button-tooltip=Close this GUI
popup-close-tooltip=Close this Popup
player-table-enter=Enter __1__
player-table-id=ID
player-table-name=Name
player-table-status=Status
player-table-online-time=Online Time
player-table-rank=Rank