From cb65c63d20ca336334301f117d9777c2a780aca4 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 23 Jun 2017 16:05:48 +0100 Subject: [PATCH 01/20] Fixed Auto Rank Again --- control.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/control.lua b/control.lua index 6a373993..fbf6f137 100644 --- a/control.lua +++ b/control.lua @@ -139,8 +139,8 @@ function autoRank(player) if Break then break end end if playerAutoRank == nil then - if ticktominutes(player.online_time) >= timeForVeteran then playerAutoRank = stringToRank('Veteran') end - if ticktominutes(player.online_time) >= timeForRegular then playerAutoRank = stringToRank('Regular') end + if ticktominutes(player.online_time) >= timeForVeteran then playerAutoRank = stringToRank('Veteran') + elseif ticktominutes(player.online_time) >= timeForRegular then playerAutoRank = stringToRank('Regular') end playerAutoRank = playerAutoRank or stringToRank('Guest') end if currentRank.name ~='Jail' and currentRank.power > playerAutoRank.power or currentRank.name == 'Guest' then From 6e2695ff949ab2cf88a658ce6d2c10fcbd0713a5 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 24 Jun 2017 22:26:40 +0100 Subject: [PATCH 02/20] /revive-entiies changed to /repair and it now heals entitys --- control.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/control.lua b/control.lua index fbf6f137..8b667872 100644 --- a/control.lua +++ b/control.lua @@ -563,24 +563,28 @@ function commandInit() print('Command Complete') end end) - --revive-entities - commands.add_command('revive-entities',' Reives all entitys in this range. Admins can use all as range #4#',function(event) + --repair + commands.add_command('repair',' Reives all entitys in this range. Admins can use all as range #4#',function(event) if event.player_index then local byPlayer = game.players[event.player_index] - if event.parameter then else byPlayer.print('Invaild Input, /revive-entities ') return end + if event.parameter then else byPlayer.print('Invaild Input, /repair ') return end local pos = byPlayer.position if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else byPlayer.print('Invaild Input, /revive-entities ') return end + if #args == 1 then else byPlayer.print('Invaild Input, /repair ') return end local range = tonumber(args[1]) if range or args[1] == 'all' then else byPlayer.print('Invaild Range, must be number below 50') return end if args[1] == 'all' then if getRank(byPlayer).power > 2 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end return + for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end + for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end return elseif range < 50 and range > 0 then else byPlayer.print('Invaild Range, must be number below 50') return end for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive() + for key, entity in pairs(game.surfaces[1].find_entities({{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}})) do if entity.health then entity.health = 10000 end return end else - for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end print('Command Complete') + for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end + for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end + print('Command Complete') end end) -- tp From 9a0d195ab1a8b1bb39c7c540ff72ac7bfde14e64 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Mon, 26 Jun 2017 17:01:34 +0100 Subject: [PATCH 03/20] Quick Fix --- control.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control.lua b/control.lua index 8b667872..fda2d12d 100644 --- a/control.lua +++ b/control.lua @@ -576,7 +576,7 @@ function commandInit() if args[1] == 'all' then if getRank(byPlayer).power > 2 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end - for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end return + for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end end return elseif range < 50 and range > 0 then else byPlayer.print('Invaild Range, must be number below 50') return end for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive() for key, entity in pairs(game.surfaces[1].find_entities({{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}})) do if entity.health then entity.health = 10000 end return From c509ce6baac29a4afeb24a541d74023081a7ca81 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Mon, 26 Jun 2017 17:16:00 +0100 Subject: [PATCH 04/20] Fixed repair --- control.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/control.lua b/control.lua index fda2d12d..fe9e9130 100644 --- a/control.lua +++ b/control.lua @@ -577,13 +577,13 @@ function commandInit() if getRank(byPlayer).power > 2 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end end return - elseif range < 50 and range > 0 then else byPlayer.print('Invaild Range, must be number below 50') return end - for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive() - for key, entity in pairs(game.surfaces[1].find_entities({{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}})) do if entity.health then entity.health = 10000 end return - end + elseif range < 50 and range > 0 then + for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive() end + for key, entity in pairs(game.surfaces[1].find_entities({{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}})) do if entity.health then entity.health = 10000 end end return + else byPlayer.print('Invaild Range, must be number below 50') return end else for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end - for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end + for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end end print('Command Complete') end end) From 28197d5373179e74d370ba3cc7267b8693160c3f Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Mon, 26 Jun 2017 17:24:46 +0100 Subject: [PATCH 05/20] Updated help message --- control.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control.lua b/control.lua index fe9e9130..785b99f0 100644 --- a/control.lua +++ b/control.lua @@ -564,7 +564,7 @@ function commandInit() end end) --repair - commands.add_command('repair',' Reives all entitys in this range. Admins can use all as range #4#',function(event) + commands.add_command('repair',' Reives and heals all entitys in this range. Admins can use all as range #4#',function(event) if event.player_index then local byPlayer = game.players[event.player_index] if event.parameter then else byPlayer.print('Invaild Input, /repair ') return end From 0425d56fcc055feb44865fd4e351db4a401fca51 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 30 Jun 2017 15:47:18 +0100 Subject: [PATCH 06/20] Quick Fix --- control.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/control.lua b/control.lua index 785b99f0..93f2ebdb 100644 --- a/control.lua +++ b/control.lua @@ -27,8 +27,9 @@ defaults = { ['Community Manager']={'arty714'}, Developer={'Cooldude2606'}, Admin={'eissturm','PropangasEddy','Smou'}, - Mod={'Alanore','Aquaday','cafeslacker','CrashKonijn','Drahc_pro','FlipHalfling90','freek16','Hobbitkicker','hud','Koroto','mark9064','Matthias60','MeDDish','Mindxt20','MottledPetrel','Mr_Happy_212','NextIdea','Phoenix27833','samy115','Sand3r205','scarbvis','steentje77','tophatgaming123','VR29'}, + Mod={'Alanore','Aquaday','cafeslacker','CrashKonijn','Drahc_pro','FlipHalfling90','freek16','Hobbitkicker','hud','Koroto','mark9064','Matthias60','MeDDish','Mindxt20','MottledPetrel','Mr_Happy_212','NextIdea','Phoenix27833','samy115','Sand3r205','scarbvis','steentje77','tophatgaming123','VR29','xenocyber'}, Donator={'M74132','Splicer'}, + Veteran={}, Member={}, Regular={}, Guest={}, From c96c7e85d8e7c3dcc189ded5e1f7ae016fc8e6bd Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 30 Jun 2017 17:30:50 +0100 Subject: [PATCH 07/20] Basic File System Done --- control.lua | 912 +----------------------- locale/ExpGaming-Addons/file-header.lua | 23 + locale/ExpGaming-Core/file-header.lua | 23 + locale/Stand-Alone/file-header.lua | 23 + locale/file-header.lua | 25 + 5 files changed, 116 insertions(+), 890 deletions(-) create mode 100644 locale/ExpGaming-Addons/file-header.lua create mode 100644 locale/ExpGaming-Core/file-header.lua create mode 100644 locale/Stand-Alone/file-header.lua create mode 100644 locale/file-header.lua diff --git a/control.lua b/control.lua index 93f2ebdb..d74ca81d 100644 --- a/control.lua +++ b/control.lua @@ -1,193 +1,31 @@ -require("silo-script") --do not remove part of factorio default control -require "mod-gui" -local version = 1 --do not remove part of factorio default control -entityRemoved = {} -entityCache = {} -guis = {frames={},buttons={}} ---this is a list of what will be put into the default list -defaults = { - --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 - ranks={ - {name='Owner',shortHand='Owner',tag='[Owner]',power=0,colour={r=170,g=0,b=0},disallow={}}, - {name='Community Manager',shortHand='Com Mngr',tag='[Com Mngr]',power=1,colour={r=150,g=68,b=161},disallow={}}, - {name='Developer',shortHand='Dev',tag='[Dev]',power=1,colour={r=179,g=125,b=46},disallow={}}, - {name='Admin',shortHand='Admin',tag='[Admin]',power=2,colour={r=233,g=63,b=233},disallow={'set_allow_commands','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Mod',shortHand='Mod',tag='[Mod]',power=3,colour={r=0,g=170,b=0},disallow={'set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Donator',shortHand='P2W',tag='[P2W]',power=4,colour={r=233,g=63,b=233},disallow={'set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Veteran',shortHand='Vet',tag='[Veteran]',power=4,colour={r=140,g=120,b=200},disallow={'set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Member',shortHand='Mem',tag='[Member]',power=5,colour={r=24,g=172,b=188},disallow={'set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Regular',shortHand='Reg',tag='[Regular]',power=5,colour={r=24,g=172,b=188},disallow={'set_auto_launch_rocket','change_programmable_speaker_alert_parameters','reset_assembling_machine','drop_item','set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Guest',shortHand='',tag='[Guest]',power=6,colour={r=255,g=159,b=27},disallow={'build_terrain','remove_cables','launch_rocket','cancel_research','set_auto_launch_rocket','change_programmable_speaker_alert_parameters','reset_assembling_machine','drop_item','set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}}, - {name='Jail',shortHand='Jail',tag='[Jail]',power=7,colour={r=50,g=50,b=50},disallow={'open_character_gui','begin_mining','start_walking','player_leave_game','build_terrain','remove_cables','launch_rocket','cancel_research','set_auto_launch_rocket','change_programmable_speaker_alert_parameters','reset_assembling_machine','drop_item','set_allow_commands','server_command','edit_permission_group','delete_permission_group','add_permission_group'}} - }, - autoRanks={ - Owner={'badgamernl'}, - ['Community Manager']={'arty714'}, - Developer={'Cooldude2606'}, - Admin={'eissturm','PropangasEddy','Smou'}, - Mod={'Alanore','Aquaday','cafeslacker','CrashKonijn','Drahc_pro','FlipHalfling90','freek16','Hobbitkicker','hud','Koroto','mark9064','Matthias60','MeDDish','Mindxt20','MottledPetrel','Mr_Happy_212','NextIdea','Phoenix27833','samy115','Sand3r205','scarbvis','steentje77','tophatgaming123','VR29','xenocyber'}, - Donator={'M74132','Splicer'}, - Veteran={}, - Member={}, - Regular={}, - Guest={}, - Jail={} - }, - selected={}, - oldRanks={}, - queue={} -} +--[[ +Explosive Gaming -warningAllowed = nil -timeForRegular = 180 -timeForVeteran = 600 -CHUNK_SIZE = 32 ----------------------------------------------------------------------------------------- ----------------------------Factorio Code Do Not Remove---------------------------------- ----------------------------------------------------------------------------------------- -script.on_init(function() - global.version = version - silo_script.init() -end) +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 -script.on_event(defines.events.on_rocket_launched, function(event) - silo_script.on_rocket_launched(event) -end) +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='Control', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Core Factorio File', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +credit_loop(require("locale/file-header")) -script.on_configuration_changed(function(event) - if global.version ~= version then - global.version = version - end - silo_script.on_configuration_changed(event) -end) +script.on_init(function() global.credits = credits end) -silo_script.add_remote_interface() ----------------------------------------------------------------------------------------- ----------------------------Rank functions----------------------------------------------- ----------------------------------------------------------------------------------------- -function getRank(player) - if player then - for _,rank in pairs(global.ranks) do - if player.permission_group == game.permissions.get_group(rank.name) then return rank end - end - return stringToRank('Guest') - end -end -function stringToRank(string) - if type(string) == 'string' then - local Foundranks={} - for _,rank in pairs(global.ranks) do - if rank.name:lower() == string:lower() then return rank end - if rank.name:lower():find(string:lower()) then table.insert(Foundranks,rank) end - end - if #Foundranks == 1 then return Foundranks[1] end - end -end -function callRank(msg, rank, inv) - local rank = stringToRank(rank) or stringToRank('Mod') -- default mod or higher - local inv = inv or false - for _, player in pairs(game.players) do - rankPower = getRank(player).power - if inv then - if rankPower >= rank.power then - player.print(('[Everyone]: '..msg)) - end - else - if rankPower <= rank.power then - if rank.shortHand ~= '' then player.print(('['..(rank.shortHand)..']: '..msg)) else player.print(('[Everyone]: '..msg)) end - end - end - end -end - -function giveRank(player,rank,byPlayer) - local byPlayer = byPlayer or 'system' - local rank = stringToRank(rank) or rank or stringToRank('Guest') - local oldRank = getRank(player) - local message = 'demoted' - if rank.power <= oldRank.power then message = 'promoted' end - if byPlayer.name then - callRank(player.name..' was '..message..' to '..rank.name..' by '..byPlayer.name,'Guest') - else - callRank(player.name..' was '..message..' to '..rank.name..' by ','Guest') - end - player.permission_group = game.permissions.get_group(rank.name) - if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end - player.tag = getRank(player).tag - drawToolbar(player) - drawPlayerList() - if oldRank.name ~= 'Jail' then global.oldRanks[player.index]=oldRank.name end -end - -function revertRank(player,byPlayer) - local rank = stringToRank(global.oldRanks[player.index]) - giveRank(player,rank,byPlayer) -end - -function autoRank(player) - local currentRank = getRank(player) - local playerAutoRank = nil - local oldRank = getRank(player) - for rank,players in pairs(global.autoRanks) do - local Break = false - for _,p in pairs(players) do - if player.name:lower() == p:lower() then playerAutoRank = stringToRank(rank) Break = true break end - end - if Break then break end - end - if playerAutoRank == nil then - if ticktominutes(player.online_time) >= timeForVeteran then playerAutoRank = stringToRank('Veteran') - elseif ticktominutes(player.online_time) >= timeForRegular then playerAutoRank = stringToRank('Regular') end - playerAutoRank = playerAutoRank or stringToRank('Guest') - end - if currentRank.name ~='Jail' and currentRank.power > playerAutoRank.power or currentRank.name == 'Guest' then - if playerAutoRank.name == 'Guest' then - player.permission_group=game.permissions.get_group('Guest') - else - giveRank(player,playerAutoRank) - end - end - if getRank(player).power <= 3 and not player.admin then callRank(player.name..' needs to be promoted.') end - if oldRank.name ~= getRank(player).name then global.oldRanks[player.index]=oldRank.name end -end ----------------------------------------------------------------------------------------- ----------------------------Common use functions----------------------------------------- ----------------------------------------------------------------------------------------- -function ticktohour (tick) - local hour = tostring(math.floor(tick/(216000*game.speed))) - return hour -end - -function ticktominutes (tick) - local minutes = math.floor(tick/(3600*game.speed)) - return minutes -end - -function clearSelection(player) - global.selected[player.index] = {} -end - -function sudo(command,args) - table.insert(global.queue,{fun=command,var=args}) -end - -function autoMessage() - local lrank = 'Regular' - local hrank = 'Mod' - callRank('There are '..#game.connected_players..' players online',hrank,true) - callRank('This map has been on for '..ticktohour(game.tick)..' Hours and '..(ticktominutes(game.tick)-60*ticktohour(game.tick))..' Minutes',hrank,true) - callRank('Please join us on:',lrank,true) - callRank('Discord: https://discord.gg/RPCxzgt',lrank,true) - callRank('Forum: explosivegaming.nl',lrank,true) - callRank('Steam: http://steamcommunity.com/groups/tntexplosivegaming',lrank,true) - callRank('To see these links again goto: Readme > Server Info',lrank,true) - for _,player in pairs(game.connected_players) do autoRank(player) end -end +----TEMP------------------------------------------------------------------------------------- function table.val_to_str ( v ) if "string" == type( v ) then v = string.gsub( v, "\n", "\\n" ) @@ -222,710 +60,4 @@ function table.tostring( tbl ) end end return "{" .. table.concat( result, "," ) .. "}" -end ----------------------------------------------------------------------------------------- ----------------------------Gui Functions------------------------------------------------ ----------------------------------------------------------------------------------------- -function addFrame(frame,rank,open,caption,tooltip,sprite) - guis.frames[frame] = {{require=rank,caption=caption,tooltip=tooltip,sprite=sprite}} - addButton('close', function(player,element) element.parent.parent.parent.destroy() end) - addButton('btn_'..frame, function(player,element) if player.gui.center[frame] then player.gui.center[frame].destroy() else drawFrame(player,frame,open) end end) -end - -function addTab(frame, tabName, describtion, drawTab) - guis.frames[frame][tabName] = {tabName, describtion, drawTab} - addButton(tabName, function(player, element) openTab(player, element.parent.parent.parent.name, element.parent.parent.parent.tab, element.name) end) -end - -function addButton(btnName, onClick) - guis.buttons[btnName] = {btnName, onClick} -end - -function drawButton(frame, btnName, caption, describtion, sprite) - if sprite then - frame.add{name=btnName, type = "sprite-button", sprite=sprite, tooltip=describtion, style = mod_gui.button_style} - else - frame.add{name=btnName, type = "button", caption=caption, tooltip=describtion, style = mod_gui.button_style} - end -end - -function openTab(player, frameName, tab, tabName) - local tabBar = player.gui.center[frameName].tabBarScroll.tabBar - for _,t in pairs(guis.frames[frameName]) do - if _ ~= 1 then - if t[1] == tabName then - tabBar[t[1]].style.font_color = {r = 255, g = 255, b = 255, player = 255} - tab.clear() - t[3](player, tab) - else - tabBar[t[1]].style.font_color = {r = 100, g = 100, b = 100, player = 255} - end - end - end -end - -function drawFrame(player, frameName, tabName) - if getRank(player).power <= guis.frames[frameName][1].require then - player.gui.center.clear() - local frame = player.gui.center.add{name=frameName,type='frame',caption=frameName,direction='vertical',style=mod_gui.frame_style} - local tabBarScroll = frame.add{type = "scroll-pane", name= "tabBarScroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"} - local tabBar = tabBarScroll.add{type='flow',direction='horizontal',name='tabBar'} - local tab = frame.add{type = "scroll-pane", name= "tab", vertical_scroll_policy="auto", horizontal_scroll_policy="never"} - for _,t in pairs(guis.frames[frameName]) do - if _ ~= 1 then drawButton(tabBar, t[1], t[1], t[2]) end - end - openTab(player, frameName, tab, tabName) - drawButton(tabBar, 'close', 'Close', 'Close this window') - tab.style.minimal_height = 300 - tab.style.maximal_height = 300 - tab.style.minimal_width = 500 - tab.style.maximal_width = 500 - tabBarScroll.style.minimal_height = 60 - tabBarScroll.style.maximal_height = 60 - tabBarScroll.style.minimal_width = 500 - tabBarScroll.style.maximal_width = 500 - player.gui.center.add{type='frame',name='temp'}.destroy() - end -end - -function toggleVisable(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 ----------------------------------------------------------------------------------------- ----------------------------Player Events------------------------------------------------ ----------------------------------------------------------------------------------------- -script.on_event(defines.events.on_player_created, function(event) - local player = game.players[event.player_index] - player.force.friendly_fire = false - player.insert{name="iron-plate", count=8} - player.insert{name="pistol", count=1} - player.insert{name="firearm-magazine", count=10} - player.insert{name="burner-mining-drill", count = 1} - player.insert{name="stone-furnace", count = 1} - player.force.chart(player.surface, {{player.position.x - 200, player.position.y - 200}, {player.position.x + 200, player.position.y + 200}}) - silo_script.gui_init(player) -- do not remove part of factorio default -end) - -script.on_event(defines.events.on_player_respawned, function(event) - local player = game.players[event.player_index] - drawPlayerList() - player.insert{name="pistol", count=1} - player.insert{name="firearm-magazine", count=10} -end) - -script.on_event(defines.events.on_player_joined_game, function(event) - --runs when the first player joins to make the permission groups - if global.ranks == nil then scriptInit() end - if commands.commands['server-interface'] == nil then commandInit() end - --Standard start up - local player = game.players[event.player_index] - autoRank(player) - player.print({"", "Welcome"}) - drawPlayerList() - drawToolbar(player) - if not player.admin and ticktominutes(player.online_time) < 1 then drawFrame(player,'Readme','Rules') end -end) - -script.on_event(defines.events.on_player_left_game, function(event) - local player = game.players[event.player_index] - drawPlayerList() -end) ----------------------------------------------------------------------------------------- ----------------------------Gui Events--------------------------------------------------- ----------------------------------------------------------------------------------------- -script.on_event(defines.events.on_gui_click, function(event) - silo_script.on_gui_click(event) -- do not remove part of factorio default - local player = game.players[event.player_index] - if event.element.type == 'button' or event.element.type == 'sprite-button' then - for _,btn in pairs(guis.buttons) do - if btn[1] == event.element.name then - if btn[2] then btn[2](player,event.element) else callRank('Invaid Button'..btn[1],'Mod') end - break - end - end - elseif event.element.type == 'checkbox' then - if event.element.name == 'select' then - global.selected[event.player_index] = global.selected[event.player_index] or {} - selected = global.selected[event.player_index] - if event.element.state then - table.insert(selected,event.element.parent.name) - else - for _,name in pairs(selected) do - if name == event.element.parent.name then table.remove(selected,_) break end - end - end - end - end -end) - -script.on_event(defines.events.on_gui_text_changed, function(event) - local player = game.players[event.player_index] - if event.element.parent.name == 'filterTable' then - local frame = event.element - filters = getPlayerTableFilters(frame) - local select = false - if frame.parent.parent.parent.name == 'Admin' then select = true filters.powerOver = true end - drawPlayerTable(player, frame.parent.parent, select, filters) - end -end) ----------------------------------------------------------------------------------------- ----------------------------Grefer Events------------------------------------------------ ----------------------------------------------------------------------------------------- -script.on_event(defines.events.on_marked_for_deconstruction, function(event) - local eplayer = game.players[event.player_index] - if getRank(eplayer).power > 5 then - if event.entity.type ~= "tree" and event.entity.type ~= "simple-entity" then - event.entity.cancel_deconstruction("player") - eplayer.print("You are not allowed to do this yet, play for player bit longer. Try again in about: " .. math.floor((timeForRegular - ticktominutes(eplayer.online_time))) .. " minutes") - callRank(eplayer.name .. " tryed to deconstruced something") - end - elseif event.entity.type == "tree" or event.entity.type == "simple-entity" and getRank(eplayer).power < 5 then - event.entity.destroy() - end -end) ----------------------------------------------------------------------------------------- ----------------------------Other Events------------------------------------------------- ----------------------------------------------------------------------------------------- -script.on_event(defines.events.on_tick, function(event) - if game.tick % 60 == 0 and game.tick > 300 then - if global.queue ~= nil then command=table.remove(global.queue) end - if command and command.fun and type(command.fun) == 'function' then - local args = command.var or {} - command.fun(args[1],args[2],args[3],args[4],args[5],args[6]) - end - end - if (game.tick/(3600*game.speed)) % 15 == 0 then autoMessage() end -end) ----------------------------------------------------------------------------------------- ----------------------------Tool Bar----------------------------------------------------- ----------------------------------------------------------------------------------------- -addButton("btn_toolbar_playerList", function(player) toggleVisable(mod_gui.get_frame_flow(player).PlayerList) end) -function drawToolbar(player) - local frame = mod_gui.get_button_flow(player) - if not frame.btn_toolbar_playerList then drawButton(frame,"btn_toolbar_playerList", "Playerlist", "Adds/removes the player list to/from your game.",'entity/player') end - for _,f in pairs(guis.frames) do - if frame["btn_".._] then frame["btn_".._].destroy() end - if getRank(player).power <= f[1].require then drawButton(frame,"btn_".._, f[1].caption, f[1].tooltip, f[1].sprite) end - end -end ----------------------------------------------------------------------------------------- ----------------------------Player List-------------------------------------------------- ----------------------------------------------------------------------------------------- -function drawPlayerList() - for i, player in pairs(game.connected_players) do - local flow = mod_gui.get_frame_flow(player) - if flow.PlayerList == nil then - flow.add{type = "frame", name= "PlayerList", direction = "vertical",style=mod_gui.frame_style} - .add{type = "scroll-pane", name= "PlayerListScroll", direction = "vertical", vertical_scroll_policy="always", horizontal_scroll_policy="never"} - end - local Plist= flow.PlayerList.PlayerListScroll - Plist.clear() - Plist.style.maximal_height = 200 - for i, player in pairs(game.connected_players) do - playerRank = getRank(player) - if playerRank.power <= 3 or playerRank.name == 'Jail' then - if playerRank.shortHand ~= '' then Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , ' - '..playerRank.shortHand}} - else Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name}} end - Plist[player.name].style.font_color = playerRank.colour - if player.tag:find('-') then else player.tag = playerRank.tag end - end - end - for i, player in pairs(game.connected_players) do - playerRank = getRank(player) - if playerRank.power > 3 and playerRank.name ~= 'Jail' then - if playerRank.shortHand ~= '' then Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , ' - '..playerRank.shortHand}} - else Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name}} end - Plist[player.name].style.font_color = playerRank.colour - if player.tag:find('-') then else player.tag = playerRank.tag end - end - end - end -end - -function getPlayerTableFilters(frame) - local filters = {online=nil,time=0,name=nil,selected=nil,powerOver=nil,admin=nil} - local filterTable = frame.parent.parent.filterTable - if filterTable.status_input then - local status_input = filterTable.status_input.text - if status_input == 'yes' or status_input == 'online' or status_input == 'true' or status_input == 'y' then filters.online = true - elseif status_input ~= '' then filters.online = false end - end if filterTable.hours_input then - local hours_input = filterTable.hours_input.text - if tonumber(hours_input) and tonumber(hours_input) > 0 then filters.time = tonumber(hours_input) end - end if filterTable.name_input then - local name_input = filterTable.name_input.text - if name_input then filters.name = name_input end - end - return filters -end - -function drawPlayerTable(player, frame, select,filters) - --setup the table - if frame.playerTable then frame.playerTable.destroy() end - pTable = frame.add{name='playerTable', type="table", colspan=5} - pTable.style.minimal_width = 500 - pTable.style.maximal_width = 500 - pTable.style.horizontal_spacing = 10 - pTable.add{name="id", type="label", caption="Id"} - pTable.add{name="Pname", type="label", caption="Name"} - pTable.add{name="online_time", type="label", caption="Online Time"} - pTable.add{name="rank", type="label", caption="Rank"} - if select then pTable.add{name="select_label", type="label", caption="Selection"} end - --filter checking - for i, p in pairs(game.players) do - local addPlayer = nil - if addPlayer ~= false and filters.admin then if p.admin ~= filters.admin then addPlayer = false end end - if addPlayer ~= false and filters.online == true then if p.connected == false then addPlayer = false end end - if addPlayer ~= false and filters.online == false then if p.connected == true then addPlayer = false end end - if addPlayer ~= false and filters.powerOver then if getRank(p).power <= getRank(player).power then addPlayer = false end end - if addPlayer ~= false and filters.time then if filters.time > ticktominutes(p.online_time) then addPlayer = false end end - if addPlayer ~= false and filters.name then if p.name:lower():find(filters.name:lower()) == nil then addPlayer = false end end - --addes the player to the list - if addPlayer == nil then addPlayer = true end - if addPlayer == true and player.name ~= p.name then - if pTable[p.name] == nil then - pTable.add{name=i .. "id", type="label", caption=i} - pTable.add{name=p.name..'_name', type="label", caption=p.name} - --status - if not select then - if p.connected == true - then pTable.add{name=p.name .. "Status", type="label", caption="ONLINE"} - else pTable.add{name=p.name .. "Status", type="label", caption="OFFLINE"} end end - --time and rank - pTable.add{name=p.name .. "Online_Time", type="label", caption=(ticktohour(p.online_time)..'H '..(ticktominutes(p.online_time)-60*ticktohour(p.online_time))..'M')} - pTable.add{name=p.name .. "Rank", type="label", caption=getRank(p).shortHand} - --player slecction - if select then - pTable.add{name=p.name, type="flow"} - local state = false - for _,name in pairs(global.selected[player.index]) do if name == p.name then state = true break end end - pTable[p.name].add{name='select', type="checkbox",state=state} - end - end - end - end -end ----------------------------------------------------------------------------------------- ----------------------------Init--------------------------------------------------------- ----------------------------------------------------------------------------------------- -function scriptInit() - --global - for name,value in pairs(defaults) do global[name] = value end - --ranks - for _,rank in pairs(global.ranks) do - game.permissions.create_group(rank.name) - for _,toRemove in pairs(rank.disallow) do - game.permissions.get_group(rank.name).set_allows_action(defines.input_action[toRemove],false) - end - end - --end - game.print('Script Init Complete') -end - -function commandInit() - commands.add_command('server-interface',' #2#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if getRank(byPlayer).power > 2 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if event.parameter then else byPlayer.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: '..byPlayer.name..'\n Code: '..event.parameter..'\n $£$ '..table.tostring(value), true, 0) byPlayer.print(table.tostring(value)) - else game.write_file('log.txt', '\n Ran by: '..byPlayer.name..'\n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) byPlayer.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.tostring(value), true, 0) print(table.tostring(value)) - else game.write_file('log.txt', '\n Ran by: \n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) print(value) end - end - end) - commands.add_command('auto-message','Sends the auto message to all players #6#',function(event) autoMessage() end) - --base layout for all commands - commands.add_command('online-time',' Get a players online time #6#',function(event) - if event.player_index then --is it a player or the server - local byPlayer = game.players[event.player_index] -- it's a player so gets them - if event.parameter then else byPlayer.print('Invaild Input, /online-time ') return end -- are there any arguments - if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end -- is the user have vaild rank to use command - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end -- gets all the arguments passed - if #args == 1 then else byPlayer.print('Invaild Input, /online-time ') return end -- is enouth arguments passed to aloow the command to work - local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end -- arguments vaildtion - byPlayer.print(ticktohour(player.online_time)..'H '..(ticktominutes(player.online_time)-60*ticktohour(player.online_time))..'M') -- finally the command is done - else -- when the server runs commands no output is given to any user, also server has no rank validation - if event.parameter then else print('Invaild Input, /online-time ') return end -- are there any arguments - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end -- gets all the arguments passed - if #args == 1 then else print('Invaild Input, /online-time ') return end -- is enouth arguments passed to aloow the command to work - local player = game.players[args[1]] if player then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end -- arguments vaildtion - print(ticktohour(player.online_time)..'H '..(ticktominutes(player.online_time)-60*ticktohour(player.online_time))..'M') -- finally the command is done - print('Command Complete') - end - end) - --repair - commands.add_command('repair',' Reives and heals all entitys in this range. Admins can use all as range #4#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if event.parameter then else byPlayer.print('Invaild Input, /repair ') return end - local pos = byPlayer.position - if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else byPlayer.print('Invaild Input, /repair ') return end - local range = tonumber(args[1]) if range or args[1] == 'all' then else byPlayer.print('Invaild Range, must be number below 50') return end - if args[1] == 'all' then - if getRank(byPlayer).power > 2 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end - for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end end return - elseif range < 50 and range > 0 then - for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive() end - for key, entity in pairs(game.surfaces[1].find_entities({{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}})) do if entity.health then entity.health = 10000 end end return - else byPlayer.print('Invaild Range, must be number below 50') return end - else - for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end - for key, entity in pairs(game.surfaces[1].find_entities()) do if entity.health then entity.health = 10000 end end - print('Command Complete') - end - end) - -- tp - commands.add_command('tp',' teleports one player to another #4#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if event.parameter then else byPlayer.print('Invaild Input, /tp ') return end - if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 2 then else byPlayer.print('Invaild Input, /tp ') return end - local p1 = game.players[args[1]] if p1 then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - local p2 = game.players[args[2]] if p2 then else byPlayer.print('Invaild Player Name,'..args[2]..', try using tab key to auto-complete the name') return end - if p1 == p2 then byPlayer.print('Invaild Players, must be two diffrent players') return end - if p1.connected and p2.connected then else byPlayer.print('Invaild Player, player is not online') return end - if getRank(byPlayer).power > getRank(p1).power then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - p1.teleport(game.surfaces[p2.surface.name].find_non_colliding_position("player", p2.position, 32, 1)) - else - if event.parameter then else print('Invaild Input, /tp ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 2 then else print('Invaild Input, /tp ') return end - local p1 = game.players[args[1]] if p1 then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - local p2 = game.players[args[2]] if p2 then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if p1 == p2 then print('Invaild Players, must be two diffrent players') return end - if p1.connected and p2.connected then else print('Invaild Players, one/both of players is not online') return end - p1.teleport(game.surfaces[p2.surface.name].find_non_colliding_position("player", p2.position, 32, 1)) - print('Command Complete') - end - end) - -- kill - commands.add_command('kill',' if no player stated then you kill your self #6#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if event.parameter then - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else byPlayer.print('Invaild Input, /kill ') return end - local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if getRank(byPlayer).power > getRank(player).power or getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if player.connected then else byPlayer.print('Invaild Player, player is not online') return end - if player.character then player.character.die() else byPlayer.print('Invaild Player, their are already dead') return end - else - if byPlayer.character then byPlayer.character.die() else byPlayer.print('Invaild Player, you are already dead') return end - end - else - if event.parameter then else print('Invaild Input, /kill ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else print('Invaild Input, /kill ') return end - local player = game.players[args[1]] if player then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if player.connected then else print('Invaild Player, player is not online') return end - if player.character then player.character.die() else print('Invaild Player, their are already dead') return end - print('Command Complete') - end - end) - -- jail/unjail - commands.add_command('jail',' jail the player disallowing them to move #3#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if event.parameter then else byPlayer.print('Invaild Input, /jail ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else byPlayer.print('Invaild Input, /jail ') return end - local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if getRank(byPlayer).power > getRank(player).power or getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if player.connected then else byPlayer.print('Invaild Player, player is not online') return end - if player == byPlayer then byPlayer.print('Invaild Player, you can\'t jail yourself') return end - if player.permission_group.name ~= 'Jail' then sudo(giveRank,{player,'Jail',byPlayer}) end - else - if event.parameter then else print('Invaild Input, /jail ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else print('Invaild Input, /jail ') return end - local player = game.players[args[1]] if player then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if player.permission_group.name ~= 'Jail' then giveRank(player,'Jail') end - print('Command Complete') - end - end) - commands.add_command('unjail',' jail the player disallowing them to move #3#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if event.parameter then else byPlayer.print('Invaild Input, /unjail ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else byPlayer.print('Invaild Input, /unjail ') return end - local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if getRank(byPlayer).power > getRank(player).power or getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if player.permission_group.name == 'Jail' then sudo(revertRank,{player,byPlayer}) end - else - if event.parameter then else print('Invaild Input, /unjail ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else print('Invaild Input, /unjail ') return end - local player = game.players[args[1]] if player then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if player.permission_group.name == 'Jail' then revertRank(player) end - print('Command Complete') - end - end) - -- tag - commands.add_command('tag',' Gives you your own tag #6#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - local tag = nil - if event.parameter then tag = event.parameter end - if tag and tag:len() > 20 then byPlayer.print('Invaild Tag, must be less then 20 characters') return end - if tag then byPlayer.tag = getRank(byPlayer).tag..' - '..tag..' ' else byPlayer.tag = getRank(byPlayer).tag end - else - if event.parameter then else print('Invaild Input, /tag ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args > 0 then else print('Invaild Input, /tag ') return end - local player = game.players[args[1]] if player then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - if args[2] then player.tag = getRank(player).tag..' - '..table.concat(args,' ',2)..' ' else player.tag = getRank(player).tag end - print('Command Complete') - end - end) - -- tp-all - commands.add_command('tp-all',' Sends everyone to this one person #2#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if getRank(byPlayer).power > 2 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if event.parameter then else byPlayer.print('Invaild Input, /tp-all ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else byPlayer.print('Invaild Input, /tp-all ') return end - local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - for i,p in pairs(game.connected_players) do - local pos = game.surfaces[player.surface.name].find_non_colliding_position("player", player.position, 32, 1) - if p ~= player then p.teleport(pos) end - end - else - if event.parameter then else print('Invaild Input, /tp-all ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args == 1 then else print('Invaild Input, /tp-all ') return end - local player = game.players[args[1]] if player then else print('Invaild Player Name,'..args[1]..', try using tab key to auto-complete the name') return end - for i,p in pairs(game.connected_players) do - local pos = game.surfaces[player.surface.name].find_non_colliding_position("player", player.position, 32, 1) - if p ~= player then p.teleport(pos) end - end - print('Command Complete') - end - end) - -- call-rank - commands.add_command('call-rank',' sends a message to this rank and above #5#',function(event) - if event.player_index then - local byPlayer = game.players[event.player_index] - if getRank(byPlayer).power > 5 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end - if event.parameter then else byPlayer.print('Invaild Input, /call-rank ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args > 1 then else byPlayer.print('Invaild Input, /call-rank ') return end - local rank = stringToRank(args[1]) if rank then else byPlayer.print('Invaild Rank, ther is no rank by that name') return end - if rank.name ~= 'Mod' and getRank(byPlayer).power > rank.power then byPlayer.print('Invaild Rank, rank must not be a higher rank then your (mod is the only exception)') return end - callRank(table.concat(args,' ',2),rank.name) - else - if event.parameter then else print('Invaild Input, /call-rank ') return end - local args = {} for word in event.parameter:gmatch('%S+') do table.insert(args,word) end - if #args > 1 then else print('Invaild Input, /call-rank ') return end - local rank = stringToRank(args[1]) if rank then callRank(table.concat(args,' ',2),rank.name) - else print('Invaild Rank, try asking for help from an admin') return end - print('Command Complete') - end - end) -end ----------------------------------------------------------------------------------------- ----------------------------Read Me Gui-------------------------------------------------- ----------------------------------------------------------------------------------------- -addFrame('Readme',6, 'Rules','Readme', 'Rules, Server info, How to chat, Playerlist, Adminlist.') - -addTab('Readme','Rules','The rules of the server', - function(player,frame) - local rules = { - "Hacking/cheating, exploiting and abusing bugs is not allowed.", - "Do not disrespect any player in the server (This includes staff).", - "Do not spam, this includes stuff such as chat spam, item spam, chest spam etc.", - "Do not laydown concrete with bots without permission.", - "Do not use active provider chests without permission.", - "Do not use speakers on global without permission.", - "Do not remove/move major parts of the factory without permission.", - "Do not walk in player random direction for no reason(to save map size).", - "Do not remove stuff just because you don't like it, tell people first.", - "Do not make train roundabouts. Or any loops of any kind", - "Trains are Left Hand Drive (LHD) only.", - "Do not complain about lag, low fps and low ups or other things like that.", - "Do not ask for rank.", - "Use common sense and what an admin says goes."} - for i, rule in pairs(rules) do - frame.add{name=i, type="label", caption={"", i ,". ", rule}} - end - end) -addTab('Readme','Server Info','Info about the server', - function(player,frame) - frame.add{name=1, type="label", caption={"", "Discord voice and chat server:"}} - frame.add{name=2, type='textfield', text='https://discord.gg/RPCxzgt'}.style.minimal_width=400 - frame.add{name=3, type="label", caption={"", "Our forum:"}} - frame.add{name=4, type='textfield', text='https://explosivegaming.nl'}.style.minimal_width=400 - frame.add{name=5, type="label", caption={"", "Steam:"}} - frame.add{name=6, type='textfield', text='http://steamcommunity.com/groups/tntexplosivegaming'}.style.minimal_width=400 - end) -addTab('Readme','How to chat','Just in case you dont know how to chat', - function(player,frame) - local chat = "Chatting for new players can be difficult because it’s different than other games! It’s very simple, the button you need to press is the “GRAVE/TILDE” key it’s located under the “ESC key”. If you would like to change the key go to your controls tab in options. The key you need to change is “Toggle Lua console” it’s located in the second column 2nd from bottom." - frame.add{name=i, type="label", caption={"", chat}, single_line=false}.style.maximal_width=480 - end) -addTab('Readme', 'Commands', 'Random useful commands', - function(player, frame) - frame.add{name='commandTable',type='table',colspan=2} - for command,help in pairs(commands.commands) do - local power = tonumber(help:sub(-2,-2)) - if power then else callRank(command..'has a help error') power = 0 end - if getRank(player).power > power then else - frame.commandTable.add{name='command_'..command,type='label',caption='/'..command} - frame.commandTable.add{name='help_'..command,type='label',caption=help:sub(1,-4),single_line=false}.style.maximal_width=480 - end - end - end) -addTab('Readme','Players','List of all the people who have been on the server', - function(player,frame) - local players = { - "These are the players who have supported us in the making of this factory. Without", - "you the player we wouldn't have been as far as we are now."} - for i, line in pairs(players) do - frame.add{name=i, type="label", caption={"", line}} - end - frame.add{name='filterTable',type='table',colspan=3} - frame.filterTable.add{name='name_label',type='label',caption='Name'} - frame.filterTable.add{name='status_label',type='label',caption='Online?'} - frame.filterTable.add{name='hours_label',type='label',caption='Online Time (minutes)'} - frame.filterTable.add{name='name_input',type='textfield'} - frame.filterTable.add{name='status_input',type='textfield'} - frame.filterTable.add{name='hours_input',type='textfield'} - drawPlayerTable(player, frame, false, {}) - end) ----------------------------------------------------------------------------------------- ----------------------------Admin Gui---------------------------------------------------- ----------------------------------------------------------------------------------------- -addFrame('Admin',3,'Edit Ranks','Admin',"All admin fuctions are here") - -addButton('setRanks', - function(player,frame) - rank = stringToRank(frame.parent.rank_input.items[frame.parent.rank_input.selected_index]) - if rank then - for _,playerName in pairs(global.selected[player.index]) do - p=game.players[playerName] - if getRank(player).power < getRank(p).power and rank.power > getRank(player).power then - giveRank(p,rank,player) - clearSelection(player) - drawPlayerTable(player, frame.parent.parent, true, {}) - else - player.print('You can not edit '..p.name.."'s rank there rank is too high (or the rank you have slected is above you)") - end - end - end - end) -addButton('clearSelection',function(player,frame) clearSelection(player) drawPlayerTable(player, frame.parent.parent, true, {}) end) - -addTab('Admin', 'Commands', 'Random useful commands', - function(player, frame) - frame.add{name='commandTable',type='table',colspan=2} - for command,help in pairs(commands.commands) do - local power = tonumber(help:sub(-2,-2)) - if power then else callRank(command..'has a help error') power = 0 end - if getRank(player).power > power then else - frame.commandTable.add{name='command_'..command,type='label',caption='/'..command} - frame.commandTable.add{name='help_'..command,type='label',caption=help:sub(1,-4),single_line=false}.style.maximal_width=480 - end - end - end) -addTab('Admin','Edit Ranks', 'Edit the ranks of players below you', - function(player,frame) - clearSelection(player) - frame.add{name='filterTable',type='table',colspan=1} - frame.filterTable.add{name='name_label',type='label',caption='Name'} - frame.filterTable.add{name='name_input',type='textfield'} - frame.add{type='flow',name='rank',direction='horizontal'} - frame.rank.add{name='rank_label',type='label',caption='Rank'} - frame.rank.add{name='rank_input',type='drop-down'} - for _,rank in pairs(global.ranks) do if rank.power > getRank(player).power then frame.rank.rank_input.add_item(rank.name) end end - frame.rank.rank_input.selected_index = 1 - drawButton(frame.rank,'setRanks','Set Ranks','Sets the rank of all selected players') - drawButton(frame.rank,'clearSelection','Clear Selection','Clears all currently selected players') - drawPlayerTable(player, frame, true, {powerOver=true}) - end) ----------------------------------------------------------------------------------------- ----------------------------Admin+ Gui--------------------------------------------------- ----------------------------------------------------------------------------------------- -addFrame('Admin+',2,'Modifiers','Admin+',"Because we are better") - -addButton('remove_biters',function(player,frame) for key, entity in pairs(game.surfaces[1].find_entities_filtered({force='enemy'})) do entity.destroy() end end) -addButton('toggle_cheat',function(player,frame) player.cheat_mode = not player.cheat_mode end) -addButton("btn_Modifier_apply", - function(player,frame) - local forceModifiers = { - "manual_mining_speed_modifier", - "manual_crafting_speed_modifier", - "character_running_speed_modifier", - "worker_robots_speed_modifier", - "worker_robots_storage_bonus", - "character_build_distance_bonus", - "character_item_drop_distance_bonus", - "character_reach_distance_bonus", - "character_resource_reach_distance_bonus", - "character_item_pickup_distance_bonus", - "character_loot_pickup_distance_bonus" - } - for i, modifier in pairs(forceModifiers) do - local number = tonumber(( frame.parent.parent.modifierTable[modifier .. "_input"].text):match("[%d]+[.%d+]")) - if number ~= nil then - if number >= 0 and number < 50 and number ~= player.force[modifier] then - player.force[modifier] = number - player.print(modifier .. " changed to number: " .. tostring(number)) - elseif number == player.force[modifier] then - player.print(modifier .. " Did not change") - else - player.print(modifier .. " needs to be player higher number or it contains an letter") - end - end - end - end) - -addTab('Admin+', 'Commands', 'Random useful commands', - function(player, frame) - drawButton(frame,'remove_biters','Kill Biters','Removes all biters in map') - drawButton(frame,'toggle_cheat','Toggle Cheat Mode','Toggle your cheat mode') - end) - -addTab('Admin+', 'Modifiers', 'Edit in game modifiers', - function(player,frame) - local forceModifiers = { - "manual_mining_speed_modifier", - "manual_crafting_speed_modifier", - "character_running_speed_modifier", - "worker_robots_speed_modifier", - "worker_robots_storage_bonus", - "character_build_distance_bonus", - "character_item_drop_distance_bonus", - "character_reach_distance_bonus", - "character_resource_reach_distance_bonus", - "character_item_pickup_distance_bonus", - "character_loot_pickup_distance_bonus" - } - frame.add{type = "flow", name= "flowNavigation",direction = "horizontal"} - frame.add{name="modifierTable", type="table", colspan=3} - frame.modifierTable.add{name="Mname", type="label", caption="name"} - frame.modifierTable.add{name="input", type="label", caption="input"} - frame.modifierTable.add{name="current", type="label", caption="current"} - for i, modifier in pairs(forceModifiers) do - frame.modifierTable.add{name=modifier, type="label", caption=modifier} - frame.modifierTable.add{name=modifier .. "_input", type="textfield", caption="inputTextField"} - frame.modifierTable.add{name=modifier .. "_current", type="label", caption=tostring(player.force[modifier])} - end - drawButton(frame.flowNavigation,"btn_Modifier_apply","Apply","Apply the new values to the game") -end) +end \ No newline at end of file diff --git a/locale/ExpGaming-Addons/file-header.lua b/locale/ExpGaming-Addons/file-header.lua new file mode 100644 index 00000000..f6b9513e --- /dev/null +++ b/locale/ExpGaming-Addons/file-header.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Addons', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/file-header.lua b/locale/ExpGaming-Core/file-header.lua new file mode 100644 index 00000000..494d8902 --- /dev/null +++ b/locale/ExpGaming-Core/file-header.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/Stand-Alone/file-header.lua b/locale/Stand-Alone/file-header.lua new file mode 100644 index 00000000..1a9394ae --- /dev/null +++ b/locale/Stand-Alone/file-header.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - Scripts', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/file-header.lua b/locale/file-header.lua new file mode 100644 index 00000000..28699a88 --- /dev/null +++ b/locale/file-header.lua @@ -0,0 +1,25 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - Stand-Alone', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +credit_loop(require("ExpGaming-Addons/file-header")) +credit_loop(require("Stand-Alone/file-header")) +credit_loop(require("ExpGaming-Core/file-header")) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file From aa3362d1ece5d92737de39723cd05c86a8576c76 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 1 Jul 2017 17:20:18 +0100 Subject: [PATCH 08/20] Add StdLib and Rank Table --- control.lua | 6 +- .../ExpGaming - Rank Control.lua | 23 +++ .../ExpGaming-Core/ExpGaming - Rank Table.lua | 147 +++++++++++++++ locale/ExpGaming-Core/GUI/file-header.lua | 23 +++ locale/ExpGaming-Core/file-header.lua | 6 +- locale/StdLib/core.lua | 16 ++ locale/StdLib/event.lua | 171 ++++++++++++++++++ locale/StdLib/game.lua | 26 +++ 8 files changed, 412 insertions(+), 6 deletions(-) create mode 100644 locale/ExpGaming-Core/ExpGaming - Rank Control.lua create mode 100644 locale/ExpGaming-Core/ExpGaming - Rank Table.lua create mode 100644 locale/ExpGaming-Core/GUI/file-header.lua create mode 100644 locale/StdLib/core.lua create mode 100644 locale/StdLib/event.lua create mode 100644 locale/StdLib/game.lua diff --git a/control.lua b/control.lua index d74ca81d..6fb39bab 100644 --- a/control.lua +++ b/control.lua @@ -18,12 +18,10 @@ 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----------------------------------------------------------- +credit_loop(require("locale/StdLib/event")) credit_loop(require("locale/file-header")) -script.on_init(function() global.credits = credits end) - - - +Event.register(-1,function() global.credits = credits end) ----TEMP------------------------------------------------------------------------------------- function table.val_to_str ( v ) diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua new file mode 100644 index 00000000..6a02e11f --- /dev/null +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -0,0 +1,23 @@ +--[[ +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='ExpGaming - Rank Control Functions', + owner='Explosive Gaming', + dev='Cooldude2606', + description='The Core for the Rank Controls', + factorio_version='0.15.23', + show=true + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua new file mode 100644 index 00000000..316c83f6 --- /dev/null +++ b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua @@ -0,0 +1,147 @@ +--[[ +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='ExpGaming - Ranks Table', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Table holding the ranks used', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +--[[ +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 + +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 = { + {name='Owner', + shortHand='Owner', + tag='[Owner]', + power=0, + colour={r=170,g=0,b=0}, + disallow={}}, + + {name='Community Manager', + shortHand='Com Mngr', + tag='[Com Mngr]', + power=1, + colour={r=150,g=68,b=161}, + disallow={}}, + + {name='Developer', + shortHand='Dev', + tag='[Dev]', + power=1, + colour={r=179,g=125,b=46}, + disallow={}}, + + {name='Admin', + shortHand='Admin', + tag='[Admin]', + power=2, + colour={r=233,g=63,b=233}, + disallow={ + 'set_allow_commands', + 'edit_permission_group', + 'delete_permission_group', + 'add_permission_group'} + }, + + {name='Mod', + shortHand='Mod', + tag='[Mod]', + power=3, + colour={r=0,g=170,b=0}, + disallow={ + 'server_command'} + }, + + {name='Donator', + shortHand='P2W', + tag='[P2W]', + power=4, + colour={r=233,g=63,b=233}, + disallow={}}, + + {name='Veteran', + shortHand='Vet', + tag='[Veteran]', + power=4, + colour={r=140,g=120,b=200}, + disallow={}}, + + {name='Member', + shortHand='Mem', + tag='[Member]', + power=5, + colour={r=24,g=172,b=188}, + disallow={}}, + + {name='Regular', + shortHand='Reg', + tag='[Regular]', + power=5, + colour={r=24,g=172,b=188}, + disallow={ + 'set_auto_launch_rocket', + 'change_programmable_speaker_alert_parameters', + 'reset_assembling_machine', + 'drop_item'} + }, + + {name='Guest', + shortHand='', + tag='[Guest]', + power=6, + colour={r=255,g=159,b=27}, + disallow={ + 'build_terrain', + 'remove_cables', + 'launch_rocket', + 'cancel_research'} + }, + + {name='Jail', + shortHand='Jail', + tag='[Jail]', + power=7, + colour={r=50,g=50,b=50}, + disallow={ + 'open_character_gui', + 'begin_mining', + 'start_walking', + 'player_leave_game'} + } +} +-- 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 + if ranks[n-1] then + for _,disallow in pairs(ranks[n-1].disallow) do + table.insert(rank.disallow,disallow) + end + end +end +-- Moves The Ranks to the global array +Event.register(-1,function() global.ranks = ranks end) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits, ranks \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/file-header.lua b/locale/ExpGaming-Core/GUI/file-header.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/file-header.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/file-header.lua b/locale/ExpGaming-Core/file-header.lua index 494d8902..93f83600 100644 --- a/locale/ExpGaming-Core/file-header.lua +++ b/locale/ExpGaming-Core/file-header.lua @@ -9,7 +9,7 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='File Header - ExpGaming-Core', + name='File Header - Stand-Alone', owner='Explosive Gaming', dev='Cooldude2606', description='Just A File Header To Organise Code', @@ -18,6 +18,8 @@ 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----------------------------------------------------------- - +credit_loop(require("GUI/file-header")) +credit_loop(require("ExpGaming - Rank Table")) +credit_loop(require("ExpGaming - Rank Control")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/StdLib/core.lua b/locale/StdLib/core.lua new file mode 100644 index 00000000..3fb83a51 --- /dev/null +++ b/locale/StdLib/core.lua @@ -0,0 +1,16 @@ +--- Core module +-- @module Core + +Core = {} --luacheck: allow defined top + +--- Errors if the variable evaluates to false, with an optional msg +-- @param var variable to evaluate +-- @tparam[opt='missing value'] string msg message +function Core.fail_if_missing(var, msg) + if not var then + error(msg or "Missing value", 3) + end + return false +end + +return Core \ No newline at end of file diff --git a/locale/StdLib/event.lua b/locale/StdLib/event.lua new file mode 100644 index 00000000..640e9d28 --- /dev/null +++ b/locale/StdLib/event.lua @@ -0,0 +1,171 @@ +--- Makes working with events in factorio a lot more simple. +--

Factorio can only have one handler registered per event. This module +-- allows you to easily register multiple handlers for each event. +-- Using this module is as simple as replacing script.on_event(...) with Event.register(...)

+-- @module Event +-- @usage require('stdlib/event/event') + +local credits = {{ + name='StdLib', + owner='Afforess', + dev='Afforess', + description='The Factorio StdLib used here for the event handler', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end + +local fail_if_missing = require 'core'['fail_if_missing'] +local Game = require 'game' + +Event = { --luacheck: allow defined top + _registry = {}, + core_events = { + init = -1, + load = -2, + configuration_changed = -3, + _register = function(id) + if id == Event.core_events.init then + script.on_init( + function() + Event.dispatch({name = Event.core_events.init, tick = game.tick}) + end + ) + elseif id == Event.core_events.load then + script.on_load( + function() + Event.dispatch({name = Event.core_events.load, tick = -1}) + end + ) + elseif id == Event.core_events.configuration_changed then + script.on_configuration_changed( + function(event) + event.name = Event.core_events.configuration_changed + event.data = event -- for backwards compatibilty + Event.dispatch(event) + end + ) + end + end + } +} + +--- Registers a function for a given event. If a nil handler is passed remove all events and stop listening for that event. +-- Events are dispatched in the order they are registered. +-- @usage Event.register(defines.events.on_tick, function(event) print event.tick end) +-- -- creates an event that prints the current tick every tick. +-- @tparam defines.events|{defines.events,...} event events to register +-- @tparam function handler Function to call when event is triggered +-- @treturn Event +function Event.register(event, handler) + fail_if_missing(event, "missing event argument") + + event = (type(event) == "table" and event) or {event} + + for _, event_id in pairs(event) do + if not (type(event_id) == "number" or type(event_id) == "string") then + error("Invalid Event Id, Must be string or int, or array of strings and/or ints", 2) + end + if handler == nil then + Event._registry[event_id] = nil + script.on_event(event_id, nil) + else + if not Event._registry[event_id] then + Event._registry[event_id] = {} + + if type(event_id) == "string" or event_id >= 0 then + script.on_event(event_id, Event.dispatch) + elseif event_id < 0 then + Event.core_events._register(event_id) + end + end + table.insert(Event._registry[event_id], handler) + end + end + return Event +end + +--- Calls the registerd handlers +-- Will stop dispatching remaning handlers if any handler passes invalid event userdata. +-- Handlers are dispatched in the order they were created +-- @tparam table event LuaEvent as created by script.raise_event +-- @see https://forums.factorio.com/viewtopic.php?t=32039#p202158 Invalid Event Objects +function Event.dispatch(event) + if event then + local _registry = event.name and Event._registry[event.name] or event.input_name and Event._registry[event.input_name] + if _registry then + local force_crc = Event.force_crc + for idx, handler in ipairs(_registry) do + + -- Check for userdata and stop processing further handlers if not valid + for _, val in pairs(event) do + if type(val) == "table" and val.__self == "userdata" and not val.valid then + return + end + end + + setmetatable(event, { __index = { _handler = handler } }) + + -- Call the handler + local success, err = pcall(handler, event) + + -- If the handler errors lets make sure someone notices + if not success then + if _G.game then -- may be nil in on_load + if Game.print_all(err) == 0 then + error(err) -- no players received the message, force a real error so someone notices + end + else + error(err) -- no way to handle errors cleanly when the game is not up + end + -- continue processing the remaning handlers. In most cases they won't be related to the failed code. + end + + -- force a crc check if option is enabled. This is a debug option and will hamper perfomance if enabled + if (force_crc or event.force_crc) and _G.game then + local msg = 'CRC check called for event '..event.name..' handler #'..idx + log(msg) -- log the message to factorio-current.log + game.force_crc() + end + + -- if present stop further handlers for this event + if event.stop_processing then + return + end + end + end + else + error('missing event argument') + end +end + +--- Removes the handler from the event. If it removes the last handler for an event stop listening for that event. +-- @tparam defines.events|{defines.events,...} event events to remove the handler for +-- @tparam function handler to remove +-- @return Event +function Event.remove(event, handler) + fail_if_missing(event, "missing event argument") + fail_if_missing(handler, "missing handler argument") + + event = (type(event) == "table" and event) or {event} + + for _, event_id in pairs(event) do + if not (type(event_id) == "number" or type(event_id) == "string") then + error("Invalid Event Id, Must be string or int, or array of strings and/or ints", 2) + end + if Event._registry[event_id] then + for i=#Event._registry[event_id], 1, -1 do + if Event._registry[event_id][i] == handler then + table.remove(Event._registry[event_id], i) + end + end + if #Event._registry[event_id] == 0 then + Event._registry[event_id] = nil + script.on_event(event_id, nil) + end + end + end + return Event +end + +return credits, Event \ No newline at end of file diff --git a/locale/StdLib/game.lua b/locale/StdLib/game.lua new file mode 100644 index 00000000..642e7913 --- /dev/null +++ b/locale/StdLib/game.lua @@ -0,0 +1,26 @@ +--- Game module +-- @module Game +-- @usage local Game = require('stdlib/game') + +Game = {} --luacheck: allow defined top + +Game.VALID_FILTER = function(v) + return v.valid +end + +--- Messages all players currently connected to the game +-- @tparam string msg message to send to players +-- @param[opt] condition condition to be true for the player to be messaged +-- @treturn int the number of players who received the message. Offline players are not counted as having received the message. +function Game.print_all(msg, condition) + local num = 0 + for _, player in pairs(game.connected_players) do + if condition == nil or select(2, pcall(condition, player)) then + player.print(msg) + num = num + 1 + end + end + return num +end + +return Game \ No newline at end of file From 126e51a6c324cd9dff313696a0106f4724ac15cc Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 1 Jul 2017 18:09:57 +0100 Subject: [PATCH 09/20] Added Rank Control and preset ranks --- .../ExpGaming - Rank Control.lua | 99 +++++++++++++++++++ .../ExpGaming - Rank Presets.lua | 77 +++++++++++++++ .../ExpGaming-Core/ExpGaming - Rank Table.lua | 11 +++ locale/ExpGaming-Core/file-header.lua | 4 +- 4 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 locale/ExpGaming-Core/ExpGaming - Rank Presets.lua diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua index 6a02e11f..5b4f5670 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -19,5 +19,104 @@ 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----------------------------------------------------------- +local function get_rank(player) + if player then + for _,rank in pairs(global.ranks) do + if player.permission_group == game.permissions.get_group(rank.name) then return rank end + end + return string.to_rank('Guest') + end +end + +local function string.to_rank(string) + if type(string) == 'string' then + local Foundranks={} + for _,rank in pairs(global.ranks) do + if rank.name:lower() == string:lower() then return rank end + if rank.name:lower():find(string:lower()) then table.insert(Foundranks,rank) end + end + if #Foundranks == 1 then return Foundranks[1] end + end +end + +local function rank_print(msg, rank, inv) + local rank = string.to_rank(rank) or string.to_rank('Mod') -- default mod or higher + local inv = inv or false + for _, player in pairs(game.players) do + rankPower = get_rank(player).power + if inv then + if rankPower >= rank.power then + player.print(('[Everyone]: '..msg)) + end + else + if rankPower <= rank.power then + if rank.shortHand ~= '' then player.print(('['..(rank.shortHand)..']: '..msg)) else player.print(('[Everyone]: '..msg)) end + end + end + end +end + +local function give_rank(player,rank,byPlayer) + local byPlayer = byPlayer or 'system' + local rank = string.to_rank(rank) or rank or string.to_rank('Guest') + local old_rank = get_rank(player) + local message = 'demoted' + if rank.power <= old_rank.power then message = 'promoted' end + if byPlayer.name then + rank_print(player.name..' was '..message..' to '..rank.name..' by '..byPlayer.name,'Guest') + else + rank_print(player.name..' was '..message..' to '..rank.name..' by ','Guest') + end + player.permission_group = game.permissions.get_group(rank.name) + if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end + player.tag = get_rank(player).tag + drawToolbar(player) + drawPlayerList() + if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end +end + +local function revert_rank(player,byPlayer) + local rank = string.to_rank(global.old_ranks[player.index]) + give_rank(player,rank,byPlayer) +end + +local function find_new_rank(player) + local function loop_preset_rank(players) + for _,p in pairs(players) do + if player.name:lower() == p:lower() then return string.to_rank(rank) end + end + end + local current_rank = get_rank(player) + local old_rank = get_rank(player) + local possible_ranks = {current_rank} + --loops though preset ranks + for rank,players in pairs(preset_ranks) do + local rank = loop_preset_rank(players) + if rank then table.insert(possible_ranks,string.to_rank(rank)) break end + end + --loops though rank times + for _,rank in pairs(global.ranks) do + if rank.time and ticktominutes(player.online_time) >= trank.time then table.insert(possible_ranks,string.to_rank(rank)) end + end + --loops though possible ranks + if current_rank.name ~='Jail' then + local highest_rank = possible_ranks[1] + for _,rank in pairs(possible_ranks) do + if rank.power > highest_rank.power then highest_rank = rank end + end + --gives player new rank if availble + if highest_rank.name == 'Guest' then + player.permission_group=game.permissions.get_group('Guest') + else + give_rank(player,highest_rank) + 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 old_rank.name ~= get_rank(player).name then global.old_ranks[player.index]=old_rank.name end +end + +Event.register(-1,function() global.old_ranks = {} end) +Event.register('on_player_joined_game',function(event) find_new_rank(game.players[game.players[event.player_index]]) end) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua b/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua new file mode 100644 index 00000000..69d15779 --- /dev/null +++ b/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua @@ -0,0 +1,77 @@ +--[[ +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='ExpGaming - Rank Preset Table', + owner='Explosive Gaming', + dev='Cooldude2606', + description='The Ranks that players are given apon joining', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +local preset_ranks = { + Owner={'badgamernl'}, + + ['Community Manager']={'arty714'}, + + Developer={'Cooldude2606'}, + + Admin={ + 'eissturm', + 'PropangasEddy', + 'Smou'}, + + Mod={ + 'Alanore', + 'Aquaday', + 'cafeslacker', + 'CrashKonijn', + 'Drahc_pro', + 'FlipHalfling90', + 'freek16', + 'Hobbitkicker', + 'hud', + 'Koroto', + 'mark9064', + 'Matthias60', + 'MeDDish', + 'Mindxt20', + 'MottledPetrel', + 'Mr_Happy_212', + 'NextIdea', + 'Phoenix27833', + 'samy115', + 'Sand3r205', + 'scarbvis', + 'steentje77', + 'tophatgaming123', + 'VR29', + 'xenocyber'}, + + Donator={ + 'M74132', + 'Splicer'}, + + Veteran={}, + + Member={}, + + Regular={}, + + Guest={}, + + Jail={} +} + +Event.register(-1,function() global.preset_ranks = preset_ranks end) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua index 316c83f6..f8322a32 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua @@ -38,6 +38,7 @@ local ranks = { shortHand='Owner', tag='[Owner]', power=0, + time=nil, colour={r=170,g=0,b=0}, disallow={}}, @@ -45,6 +46,7 @@ local ranks = { shortHand='Com Mngr', tag='[Com Mngr]', power=1, + time=nil, colour={r=150,g=68,b=161}, disallow={}}, @@ -52,6 +54,7 @@ local ranks = { shortHand='Dev', tag='[Dev]', power=1, + time=nil, colour={r=179,g=125,b=46}, disallow={}}, @@ -59,6 +62,7 @@ local ranks = { shortHand='Admin', tag='[Admin]', power=2, + time=nil, colour={r=233,g=63,b=233}, disallow={ 'set_allow_commands', @@ -71,6 +75,7 @@ local ranks = { shortHand='Mod', tag='[Mod]', power=3, + time=nil, colour={r=0,g=170,b=0}, disallow={ 'server_command'} @@ -80,6 +85,7 @@ local ranks = { shortHand='P2W', tag='[P2W]', power=4, + time=nil, colour={r=233,g=63,b=233}, disallow={}}, @@ -87,6 +93,7 @@ local ranks = { shortHand='Vet', tag='[Veteran]', power=4, + time=600, colour={r=140,g=120,b=200}, disallow={}}, @@ -94,6 +101,7 @@ local ranks = { shortHand='Mem', tag='[Member]', power=5, + time=nil, colour={r=24,g=172,b=188}, disallow={}}, @@ -101,6 +109,7 @@ local ranks = { shortHand='Reg', tag='[Regular]', power=5, + time=180, colour={r=24,g=172,b=188}, disallow={ 'set_auto_launch_rocket', @@ -113,6 +122,7 @@ local ranks = { shortHand='', tag='[Guest]', power=6, + time=nil, colour={r=255,g=159,b=27}, disallow={ 'build_terrain', @@ -125,6 +135,7 @@ local ranks = { shortHand='Jail', tag='[Jail]', power=7, + time=nil, colour={r=50,g=50,b=50}, disallow={ 'open_character_gui', diff --git a/locale/ExpGaming-Core/file-header.lua b/locale/ExpGaming-Core/file-header.lua index 93f83600..be44d50a 100644 --- a/locale/ExpGaming-Core/file-header.lua +++ b/locale/ExpGaming-Core/file-header.lua @@ -18,8 +18,10 @@ 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----------------------------------------------------------- -credit_loop(require("GUI/file-header")) +--as this is the core file the order in which the files are loaded does matter do not change credit_loop(require("ExpGaming - Rank Table")) +credit_loop(require("ExpGaming - Rank Presets")) credit_loop(require("ExpGaming - Rank Control")) +credit_loop(require("GUI/file-header")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file From 2ca6ef6d773043dbb2cfcb69c047b78c9d34d734 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 1 Jul 2017 21:54:35 +0100 Subject: [PATCH 10/20] Add ExpGaming Lib and ranks are in working condition --- control.lua | 37 ---------- locale/ExpGaming-Core/ExpGaming - Lib.lua | 68 ++++++++++++++++++ .../ExpGaming - Rank Control.lua | 72 ++++++++++--------- .../ExpGaming-Core/ExpGaming - Rank Table.lua | 2 +- locale/ExpGaming-Core/file-header.lua | 1 + 5 files changed, 110 insertions(+), 70 deletions(-) create mode 100644 locale/ExpGaming-Core/ExpGaming - Lib.lua diff --git a/control.lua b/control.lua index 6fb39bab..c8cee94f 100644 --- a/control.lua +++ b/control.lua @@ -22,40 +22,3 @@ credit_loop(require("locale/StdLib/event")) credit_loop(require("locale/file-header")) Event.register(-1,function() global.credits = credits end) - -----TEMP------------------------------------------------------------------------------------- -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 - 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 \ No newline at end of file diff --git a/locale/ExpGaming-Core/ExpGaming - Lib.lua b/locale/ExpGaming-Core/ExpGaming - Lib.lua new file mode 100644 index 00000000..9bc0d51a --- /dev/null +++ b/locale/ExpGaming-Core/ExpGaming - Lib.lua @@ -0,0 +1,68 @@ +--[[ +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='ExpGaming - Lib', + owner='Explosive Gaming', + dev='Cooldude2606', + description='A few basic functions used by scripts', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +--this will convert ticks into hours based on game speed +function tick_to_hour (tick) + local hour = tostring(math.floor(tick/(216000*game.speed))) + return hour +end +--this will convert ticks into minutes based on game speed +function tick_to_min (tick) + local minutes = math.floor(tick/(3600*game.speed)) + return minutes +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.to_string( v ) 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.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 +--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 5b4f5670..b1c88081 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -18,17 +18,17 @@ 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----------------------------------------------------------- - -local function get_rank(player) +--this will return the rank of the player given +function get_rank(player) if player then for _,rank in pairs(global.ranks) do if player.permission_group == game.permissions.get_group(rank.name) then return rank end end - return string.to_rank('Guest') + return string_to_rank('Guest') end end - -local function string.to_rank(string) +--this will convert the name of a rank into the rank object +function string_to_rank(string) if type(string) == 'string' then local Foundranks={} for _,rank in pairs(global.ranks) do @@ -38,9 +38,9 @@ local function string.to_rank(string) if #Foundranks == 1 then return Foundranks[1] end end end - -local function rank_print(msg, rank, inv) - local rank = string.to_rank(rank) or string.to_rank('Mod') -- default mod or higher +--this will send a message to all members if this rank and above default is mod rank +function rank_print(msg, rank, inv) + local rank = string_to_rank(rank) or string_to_rank('Mod') -- default mod or higher local inv = inv or false for _, player in pairs(game.players) do rankPower = get_rank(player).power @@ -55,54 +55,53 @@ local function rank_print(msg, rank, inv) end end end - -local function give_rank(player,rank,byPlayer) - local byPlayer = byPlayer or 'system' - local rank = string.to_rank(rank) or rank or string.to_rank('Guest') +--this will give the user their new rank and raise the Event.rank_change event +function give_rank(player,rank,by_player) + local by_player = by_player or 'system' + local rank = string_to_rank(rank) or rank or string_to_rank('Guest') local old_rank = get_rank(player) local message = 'demoted' if rank.power <= old_rank.power then message = 'promoted' end - if byPlayer.name then - rank_print(player.name..' was '..message..' to '..rank.name..' by '..byPlayer.name,'Guest') + if by_player.name then + rank_print(player.name..' was '..message..' to '..rank.name..' by '..by_player.name,'Guest') else rank_print(player.name..' was '..message..' to '..rank.name..' by ','Guest') end player.permission_group = game.permissions.get_group(rank.name) if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end player.tag = get_rank(player).tag - drawToolbar(player) - drawPlayerList() if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end + script.raise_event(Event.rank_change, {player=player, by_player=by_player, new_rank=rank, old_rank=old_rank}) end - -local function revert_rank(player,byPlayer) - local rank = string.to_rank(global.old_ranks[player.index]) - give_rank(player,rank,byPlayer) +--the user's rank is reverted to what it was before the lastest change +function revert_rank(player,by_player) + local rank = string_to_rank(global.old_ranks[player.index]) + give_rank(player,rank,by_player) end - -local function find_new_rank(player) - local function loop_preset_rank(players) +--the player is given a new rank based on playtime and/or preset ranks +function find_new_rank(player) + local function loop_preset_rank(players,rank) for _,p in pairs(players) do - if player.name:lower() == p:lower() then return string.to_rank(rank) end + if player.name:lower() == p:lower() then return rank end end end local current_rank = get_rank(player) local old_rank = get_rank(player) local possible_ranks = {current_rank} --loops though preset ranks - for rank,players in pairs(preset_ranks) do - local rank = loop_preset_rank(players) - if rank then table.insert(possible_ranks,string.to_rank(rank)) break end + for rank,players in pairs(global.preset_ranks) do + local found_rank = loop_preset_rank(players, rank) + if found_rank then table.insert(possible_ranks,string_to_rank(found_rank)) break end end --loops though rank times for _,rank in pairs(global.ranks) do - if rank.time and ticktominutes(player.online_time) >= trank.time then table.insert(possible_ranks,string.to_rank(rank)) end + if rank.time and tick_to_min(player.online_time) >= rank.time then table.insert(possible_ranks,string_to_rank(rank)) end end --loops though possible ranks if current_rank.name ~='Jail' then local highest_rank = possible_ranks[1] for _,rank in pairs(possible_ranks) do - if rank.power > highest_rank.power then highest_rank = rank end + if rank.power < highest_rank.power then highest_rank = rank end end --gives player new rank if availble if highest_rank.name == 'Guest' then @@ -115,8 +114,17 @@ local function find_new_rank(player) if get_rank(player).power <= 3 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.register(-1,function() global.old_ranks = {} end) -Event.register('on_player_joined_game',function(event) find_new_rank(game.players[game.players[event.player_index]]) end) +--event handlers +Event.rank_change = script.generate_event_name() +Event.register(-1,function() + global.old_ranks = {} + for _,rank in pairs(global.ranks) do + game.permissions.create_group(rank.name) + for _,toRemove in pairs(rank.disallow) do + 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) find_new_rank(game.players[event.player_index]) end) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua index f8322a32..b7ab0a59 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua @@ -155,4 +155,4 @@ end -- Moves The Ranks to the global array Event.register(-1,function() global.ranks = ranks end) --Please Only Edit Above This Line----------------------------------------------------------- -return credits, ranks \ No newline at end of file +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/file-header.lua b/locale/ExpGaming-Core/file-header.lua index be44d50a..9a7090ec 100644 --- a/locale/ExpGaming-Core/file-header.lua +++ b/locale/ExpGaming-Core/file-header.lua @@ -19,6 +19,7 @@ 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----------------------------------------------------------- --as this is the core file the order in which the files are loaded does matter do not change +credit_loop(require("ExpGaming - Lib")) credit_loop(require("ExpGaming - Rank Table")) credit_loop(require("ExpGaming - Rank Presets")) credit_loop(require("ExpGaming - Rank Control")) From 9241ef28ae1cad8b82db03d5138ca737485ad26a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 1 Jul 2017 22:47:57 +0100 Subject: [PATCH 11/20] Server interface added --- .../ExpGaming - Server Interface.lua | 54 +++++++++++++++++++ locale/ExpGaming-Core/file-header.lua | 1 + 2 files changed, 55 insertions(+) create mode 100644 locale/ExpGaming-Core/ExpGaming - Server Interface.lua diff --git a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua new file mode 100644 index 00000000..0a581e14 --- /dev/null +++ b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua @@ -0,0 +1,54 @@ +--[[ +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='ExpGaming - Server Interface', + owner='Explosive Gaming', + dev='Cooldude2606', + description='A way of talking with the server with out breaking achevements', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +--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) +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 +--runs one sudo command every second if one is present +Event.register(defines.events.on_tick, function(event) + if game.tick % 60 == 0 and global.sudo and #global.sudo > 0 then + command=table.remove(global.sudo) + if command and command.fun and type(command.fun) == 'function' then + local args = command.var or {} + command.fun(args[1],args[2],args[3],args[4],args[5],args[6]) + end + end +end) +Event.register(-1,function() global.sudo = {} end) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/file-header.lua b/locale/ExpGaming-Core/file-header.lua index 9a7090ec..c6953436 100644 --- a/locale/ExpGaming-Core/file-header.lua +++ b/locale/ExpGaming-Core/file-header.lua @@ -24,5 +24,6 @@ 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 - Server Interface")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file From 45798b7b88699f812e809c4169ed0a79f1fd0a18 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 2 Jul 2017 11:17:22 +0100 Subject: [PATCH 12/20] Add Gui Inputs (Unable to test) --- .../ExpGaming - Server Interface.lua | 2 +- .../GUI/ExpGaming - Center Gui.lua | 23 ++++++ .../ExpGaming-Core/GUI/ExpGaming - Inputs.lua | 76 +++++++++++++++++++ .../GUI/ExpGaming - Left Gui.lua | 23 ++++++ .../GUI/ExpGaming - Modlue Setup.lua | 49 ++++++++++++ .../GUI/ExpGaming - Player Table.lua | 23 ++++++ .../ExpGaming-Core/GUI/ExpGaming - Popup.lua | 23 ++++++ .../GUI/ExpGaming - Toolbar.lua | 23 ++++++ locale/ExpGaming-Core/GUI/file-header.lua | 8 +- 9 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua diff --git a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua index 0a581e14..4f380587 100644 --- a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua +++ b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua @@ -45,7 +45,7 @@ Event.register(defines.events.on_tick, function(event) command=table.remove(global.sudo) if command and command.fun and type(command.fun) == 'function' then local args = command.var or {} - command.fun(args[1],args[2],args[3],args[4],args[5],args[6]) + command.fun(unpack(args)) end end end) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua new file mode 100644 index 00000000..8855d6e0 --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua @@ -0,0 +1,76 @@ +--[[ +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='Gui Input Handler', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +local add_input = ExpGui.add_input +local inputs = ExpGui.inputs +--allows defining of new buttons;;name how to call button;;default_display what is showen 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) + table.insert(inputs.buttons,{name,default_display,default_tooltip,event}) +end +--allows defining of text box inputs;;name how to call button;;default_display what is showen on the button;;event function(player,element) that runs on text change +function add_input.text(name,default_display,event) + table.insert(inputs.text,{name,default_display,event}) +end +--draws the button into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default +function add_input.draw_button(frame,name,display,tooltip) + for _,btn in pairs(inputs.buttons) do + if btn[1] == name then + local display = display or btn[2] + local tooltip = tooltip or btn[3] + if 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 break + end + end +end +--draws the text into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default +function add_input.draw_button(frame,name,display) + for _,text in pairs(inputs.text) do + if text[1] == name then + local display = display or text[2] + frame.add{name=name, type='textfield', text=display} + break + end + end +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 + for _,btn in pairs(inputs.buttons) do + if btn[1] == event.element.name then + if btn[4] then btn[4](player,event.element) else rank_print('Button Without Function '..btn[1],'Mod') end break + 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] + for _,text in pairs(inputs.text) do + if text[1] == event.element.name then + if text[3] then text[3](player,event.element) end break + end + end +end) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua new file mode 100644 index 00000000..dec5d7ec --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua @@ -0,0 +1,49 @@ +--[[ +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='Setup for the Gui Object', + owner='Explosive Gaming', + dev='Cooldude2606', + description='The very fondation of the Gui System', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- +ExpGui = { + add_frame={ + --center + --left + --popup + }, + add_input={ + --button + --text + --draw_button + --draw_text + }, + toolbar={ + --draw + --add_button + }, + --add_player_table + inputs={ + buttons={}, + text={} + }, + frames={ + center={}, + left={}, + popup={} + } +} +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/XSsBV6b + +The credit below may be used by another script do not remove. +]] +local credits = {{ + name='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + factorio_version='0.15.23', + show=false + }} +local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end +--Please Only Edit Below This Line----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/file-header.lua b/locale/ExpGaming-Core/GUI/file-header.lua index c0e1633b..32df0761 100644 --- a/locale/ExpGaming-Core/GUI/file-header.lua +++ b/locale/ExpGaming-Core/GUI/file-header.lua @@ -18,6 +18,12 @@ 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----------------------------------------------------------- - +credit_loop(require("ExpGaming - Modlue Setup")) +credit_loop(require("ExpGaming - Inputs")) +credit_loop(require("ExpGaming - Toolbar")) +credit_loop(require("ExpGaming - Center Gui")) +credit_loop(require("ExpGaming - Left Gui")) +credit_loop(require("ExpGaming - Player Table")) +credit_loop(require("ExpGaming - Popup")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file From 1efdb4ca92e73a1d368f56364c59dc97abbba7a8 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 2 Jul 2017 20:30:35 +0100 Subject: [PATCH 13/20] Add the toolbar manager --- control.lua | 1 + .../ExpGaming - Rank Control.lua | 6 ++++- .../ExpGaming-Core/GUI/ExpGaming - Inputs.lua | 14 +++++++--- .../GUI/ExpGaming - Modlue Setup.lua | 1 + .../GUI/ExpGaming - Toolbar.lua | 27 ++++++++++++++++--- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/control.lua b/control.lua index c8cee94f..8727ff70 100644 --- a/control.lua +++ b/control.lua @@ -18,6 +18,7 @@ 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----------------------------------------------------------- +require("mod-gui") credit_loop(require("locale/StdLib/event")) credit_loop(require("locale/file-header")) diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua index b1c88081..dd5acf2f 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -60,6 +60,7 @@ function give_rank(player,rank,by_player) local by_player = by_player or 'system' local rank = string_to_rank(rank) or rank or string_to_rank('Guest') local old_rank = get_rank(player) + --messaging local message = 'demoted' if rank.power <= old_rank.power then message = 'promoted' end if by_player.name then @@ -67,8 +68,11 @@ 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 + --rank change player.permission_group = game.permissions.get_group(rank.name) - if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end player.tag = get_rank(player).tag if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end script.raise_event(Event.rank_change, {player=player, by_player=by_player, new_rank=rank, old_rank=old_rank}) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua index 8855d6e0..dbe02701 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua @@ -12,7 +12,7 @@ local credits = {{ name='Gui Input Handler', owner='Explosive Gaming', dev='Cooldude2606', - description='Just A File Header To Organise Code', + description='Handles all gui inputs', factorio_version='0.15.23', show=false }} @@ -22,17 +22,21 @@ local add_input = ExpGui.add_input local inputs = ExpGui.inputs --allows defining of new buttons;;name how to call button;;default_display what is showen 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 table.insert(inputs.buttons,{name,default_display,default_tooltip,event}) end --allows defining of text box inputs;;name how to call button;;default_display what is showen 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 table.insert(inputs.text,{name,default_display,event}) end --draws the button into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides 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 for _,btn in pairs(inputs.buttons) do if btn[1] == name then - local display = display or btn[2] + local display = display or btn[2] or btn[1] local tooltip = tooltip or btn[3] if frame.gui.is_valid_sprite_path(display) then frame.add{name=name, type = "sprite-button", sprite=display, tooltip=tooltip, style = mod_gui.button_style} @@ -43,10 +47,12 @@ function add_input.draw_button(frame,name,display,tooltip) end end --draws the text into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default -function add_input.draw_button(frame,name,display) +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 for _,text in pairs(inputs.text) do if text[1] == name then - local display = display or text[2] + local display = display or text[2] or text[1] frame.add{name=name, type='textfield', text=display} break end diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua index dec5d7ec..66b56632 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua @@ -31,6 +31,7 @@ ExpGui = { --draw_text }, toolbar={ + buttons={} --draw --add_button }, diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua index c0e1633b..dd3b8303 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -9,15 +9,36 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='File Header - ExpGaming-Core-GUI', + name='A Very Useful Toolbar', owner='Explosive Gaming', dev='Cooldude2606', - description='Just A File Header To Organise Code', + description='Some simple functions that help to control the toolbar', factorio_version='0.15.23', show=false }} local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- - +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,restriction,event) + local restriction = restriction or 0 + if not name then error('Button requires a name') end + table.insert(toolbar.buttons,{name,restriction}) + 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) + if not player then error('Need a player to draw to') end + local toolbar_frame = player.gui.top.toolbar or player.gui.top.add{name='toolbar',type='flow'} + toolbar_frame.clear() + for _,btn in pairs(toolbar.buttons) do + local rank = get_rank(player) + if btn[2] >= rank.power then + ExpGui.add_input.draw_button(toolbar_frame,btn[1]) + end + end +end +--auto redraw toolbar after new rank is given +Event.register(Event.rank_change,function(event) toolbar.draw(event.player) end) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file From 0c68849870b3709de5a4ff91ded67eaec5c1ef99 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 2 Jul 2017 22:28:27 +0100 Subject: [PATCH 14/20] Added center gui --- .../GUI/ExpGaming - Center Gui.lua | 54 ++++++++++++++++++- .../GUI/ExpGaming - Modlue Setup.lua | 18 +++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua index c0e1633b..7af14de5 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -18,6 +18,58 @@ 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----------------------------------------------------------- - +local add_frame = ExpGui.add_frame +local frames = ExpGui.frames +local draw_frame = ExpGui.draw_frame +--adds a frame in the center; tabs is a list that can contain already defined tabs; event(player,element) is a option to have a custom gui in the center +function add_frame.center(name,display,tooltip,restriction,tabs,event) + if not name then error('Frame requires a name') end + local tabs = tabs or {} + table.insert(frames.center,{name,display,tabs,event}) + ExpGui.toolbar.add_button(name,display,tooltip,restriction,draw_frame.center) +end +--defines a tab; frame is need as every tab must be used once; event(player,tab) is the draw function +function add_frame.tab(name,display,tooltip,restriction,frame,event) + if not name then error('Tab requires a name') end + if not frame then error('Tab requires a frame') end + table.insert(frames.tabs,{name,display,frame,event}) + for _,f in pairs(frames.center) do if f[1] == frame then table.insert(f[3],{name,restriction}) end end + ExpGui.add_input.button(name,display,tooltip,draw_frame.tab) +end +--draw the center gui for the player; do not call manuley must use other functions to call +ExpGui.add_input.button('close_center','Close','Close This Gui',function(player,element) player.gui.center.clear() end) +function draw_frame.center(player,element) + local frame_data = nil + for _,frame in pairs(frames.center) do if element.name == frame[1] then frame_data = frame break end end + if player.gui.is_valid_sprite_path(frame_data[2]) then frame_data[2] = frame_data[1] end + if player.gui.center[frame_data[1]] then player.gui.center.clear() return end + if frame_data[4] and type(frame_data[4]) == 'function' then frame_data[4](player,element) return end + local frame = player.gui.center.add{name=frame_data[1],type='frame',caption=frame_data[2],direction='vertical',style=mod_gui.frame_style} + 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"} + for n,t in pairs(frame_data[3]) do if t[2] >= get_rank(player).power then ExpGui.add_input.draw_button(tab_bar,t[1]) end end + draw_frame.tab(player,tab_bar[frame_data[3][1][1]]) + ExpGui.add_input.draw_button(tab_bar,'close_center') + 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 manuley must use other functions to call +function draw_frame.tab(player,element) + 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() + for _,tab in pairs(frames.tabs) do if element.name == tab[1] then tab[4](player,element.parent.parent.parent.tab) break end end +end --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua index 66b56632..bafade34 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua @@ -21,6 +21,13 @@ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits ExpGui = { add_frame={ --center + --tab + --left + --popup + }, + draw_frame={ + --center + --tab --left --popup }, @@ -42,9 +49,20 @@ ExpGui = { }, frames={ center={}, + tabs={}, left={}, popup={} } } +--simple function to toggle the visiblly of a frame +function ExpGui.toggleVisable(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 credits \ No newline at end of file From 71e789b5080bfd8427434a8b2abc20342abc4350 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 2 Jul 2017 23:18:04 +0100 Subject: [PATCH 15/20] Made Some of the core files show credit --- locale/ExpGaming-Core/ExpGaming - Rank Control.lua | 4 ++-- locale/ExpGaming-Core/ExpGaming - Server Interface.lua | 4 ++-- locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua | 4 ++-- locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua | 6 +++--- locale/StdLib/event.lua | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua index dd5acf2f..41f0bfec 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -9,10 +9,10 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='ExpGaming - Rank Control Functions', + name='Explosive Gaming Rank System', owner='Explosive Gaming', dev='Cooldude2606', - description='The Core for the Rank Controls', + description='The very core that all of the others are based on', factorio_version='0.15.23', show=true }} diff --git a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua index 4f380587..506a9851 100644 --- a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua +++ b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua @@ -9,12 +9,12 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='ExpGaming - Server Interface', + name='Explosive Gaming Server Interface', owner='Explosive Gaming', dev='Cooldude2606', description='A way of talking with the server with out breaking achevements', factorio_version='0.15.23', - show=false + 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----------------------------------------------------------- diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua index 7af14de5..9c07edf6 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -9,10 +9,10 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='File Header - ExpGaming-Core-GUI', + name='Center Gui', owner='Explosive Gaming', dev='Cooldude2606', - description='Just A File Header To Organise Code', + description='The main gui in the center', factorio_version='0.15.23', show=false }} diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua index bafade34..a1697239 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua @@ -9,12 +9,12 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='Setup for the Gui Object', + name='Explosive Gaming Gui System', owner='Explosive Gaming', dev='Cooldude2606', - description='The very fondation of the Gui System', + description='Without this it would not be the same', factorio_version='0.15.23', - show=false + 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----------------------------------------------------------- diff --git a/locale/StdLib/event.lua b/locale/StdLib/event.lua index 640e9d28..3c68bb80 100644 --- a/locale/StdLib/event.lua +++ b/locale/StdLib/event.lua @@ -6,12 +6,12 @@ -- @usage require('stdlib/event/event') local credits = {{ - name='StdLib', + name='Factorio StdLib', owner='Afforess', dev='Afforess', description='The Factorio StdLib used here for the event handler', factorio_version='0.15.23', - show=false + show=true }} local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end From f1ce424e909db24d3e7e4b8ea2edc1d9651d4014 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Mon, 3 Jul 2017 20:06:26 +0100 Subject: [PATCH 16/20] Added left Gui plus same changes else where --- .../GUI/ExpGaming - Center Gui.lua | 4 +-- .../ExpGaming-Core/GUI/ExpGaming - Inputs.lua | 3 ++- .../GUI/ExpGaming - Left Gui.lua | 25 ++++++++++++++++--- .../GUI/ExpGaming - Toolbar.lua | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua index 9c07edf6..ac9e6027 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -9,7 +9,7 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='Center Gui', + name='ExpGaming - Center Gui', owner='Explosive Gaming', dev='Cooldude2606', description='The main gui in the center', @@ -42,7 +42,7 @@ function draw_frame.center(player,element) local frame_data = nil for _,frame in pairs(frames.center) do if element.name == frame[1] then frame_data = frame break end end if player.gui.is_valid_sprite_path(frame_data[2]) then frame_data[2] = frame_data[1] end - if player.gui.center[frame_data[1]] then player.gui.center.clear() return end + if player.gui.center[frame_data[1]] then player.gui.center.clear() return else player.gui.center.clear() end if frame_data[4] and type(frame_data[4]) == 'function' then frame_data[4](player,element) return end local frame = player.gui.center.add{name=frame_data[1],type='frame',caption=frame_data[2],direction='vertical',style=mod_gui.frame_style} local tab_bar_scroll = frame.add{type = "scroll-pane", name= "tab_bar_scroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"} diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua index dbe02701..242e3f78 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua @@ -42,9 +42,10 @@ function add_input.draw_button(frame,name,display,tooltip) 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 break + end return end 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) overides the default;;tooltip(opptinal) overides the default function add_input.draw_text(frame,name,display) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua index c0e1633b..c29c3ef3 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -9,15 +9,34 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='File Header - ExpGaming-Core-GUI', + name='ExpGaming - Left Gui', owner='Explosive Gaming', dev='Cooldude2606', - description='Just A File Header To Organise Code', + description='A simple way to add toggle menus to the left', factorio_version='0.15.23', show=false }} local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- - +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 visabilty toggled +--adds a frame to the left bar; event(player,frame) must be present for left guis as there is no default +function add_frame.left(name,display,tooltip,restriction,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 + table.insert(frames.left,{name,display,event}) + ExpGui.toolbar.add_button(name,display,tooltip,restriction,draw_frame.left) +end +--draw the left gui for the player; do not call manuley must use other functions to call +function draw_frame.left(player,element) + local frame_data = nil + for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end + local left = player.gui.left + if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end + local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2]} + frame_data[3](player,frame) +end --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua index dd3b8303..6515fbde 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -29,7 +29,7 @@ end --draw the toolbar to the player only showing buttons within their restriction function toolbar.draw(player) if not player then error('Need a player to draw to') end - local toolbar_frame = player.gui.top.toolbar or player.gui.top.add{name='toolbar',type='flow'} + local toolbar_frame = player.gui.top toolbar_frame.clear() for _,btn in pairs(toolbar.buttons) do local rank = get_rank(player) From de5fa86749d5601fc9f36d5124eea42c2afdd15f Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Mon, 3 Jul 2017 21:18:25 +0100 Subject: [PATCH 17/20] Added Popup guis and test guis in control.lua --- control.lua | 7 +++ .../GUI/ExpGaming - Center Gui.lua | 14 ++--- .../GUI/ExpGaming - Left Gui.lua | 10 ++-- .../ExpGaming-Core/GUI/ExpGaming - Popup.lua | 60 ++++++++++++++++++- .../GUI/ExpGaming - Toolbar.lua | 2 +- locale/ExpGaming-Core/GUI/file-header.lua | 2 +- 6 files changed, 78 insertions(+), 17 deletions(-) diff --git a/control.lua b/control.lua index 8727ff70..3e126981 100644 --- a/control.lua +++ b/control.lua @@ -23,3 +23,10 @@ credit_loop(require("locale/StdLib/event")) credit_loop(require("locale/file-header")) Event.register(-1,function() global.credits = credits end) + +--temp +ExpGui.add_frame.center('Test','Test','A Simple Gui',5) +ExpGui.add_frame.tab('testing','Long Tab','Just Like any other',5,'Test',function(player,tab) for i=0,100 do tab.add{type='label',name=i,caption=player.name} end end) +ExpGui.add_frame.tab('just_a_tab','A Tab','Just Like any other',5,'Test',function(player,tab) tab.add{type='label',name='temp',caption=player.name} end) +ExpGui.add_frame.left('left_test','Player Name','Just Like any other',5,function(player,frame) for i=0,10 do frame.add{type='label',name=i,caption=player.name..'\n'} end end) +ExpGui.add_frame.popup('Message','Message','Just A ToolTip',5,function(player,frame) frame.add{name='TEST',type='label',caption=player.name} end,function(player,frame,args) frame.add{name='Message',type='label',caption=args[1]..' '..args[2]} end) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua index ac9e6027..965eab12 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -22,22 +22,22 @@ local add_frame = ExpGui.add_frame local frames = ExpGui.frames local draw_frame = ExpGui.draw_frame --adds a frame in the center; tabs is a list that can contain already defined tabs; event(player,element) is a option to have a custom gui in the center -function add_frame.center(name,display,tooltip,restriction,tabs,event) +function add_frame.center(name,default_display,default_tooltip,restriction,tabs,event) if not name then error('Frame requires a name') end local tabs = tabs or {} - table.insert(frames.center,{name,display,tabs,event}) - ExpGui.toolbar.add_button(name,display,tooltip,restriction,draw_frame.center) + table.insert(frames.center,{name,default_display,tabs,event}) + ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.center) end --defines a tab; frame is need as every tab must be used once; event(player,tab) is the draw function -function add_frame.tab(name,display,tooltip,restriction,frame,event) +function add_frame.tab(name,default_display,default_tooltip,restriction,frame,event) if not name then error('Tab requires a name') end if not frame then error('Tab requires a frame') end - table.insert(frames.tabs,{name,display,frame,event}) + table.insert(frames.tabs,{name,default_display,frame,event}) for _,f in pairs(frames.center) do if f[1] == frame then table.insert(f[3],{name,restriction}) end end - ExpGui.add_input.button(name,display,tooltip,draw_frame.tab) + ExpGui.add_input.button(name,default_display,default_tooltip,draw_frame.tab) end --draw the center gui for the player; do not call manuley must use other functions to call -ExpGui.add_input.button('close_center','Close','Close This Gui',function(player,element) player.gui.center.clear() end) +ExpGui.add_input.button('close_center','Close','Close This Gui',function(player,element) element.parent.parent.parent.destroy() end) function draw_frame.center(player,element) local frame_data = nil for _,frame in pairs(frames.center) do if element.name == frame[1] then frame_data = frame break end end diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua index c29c3ef3..d071a151 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -23,19 +23,19 @@ local frames = ExpGui.frames local draw_frame = ExpGui.draw_frame --left guis are always present and only have their visabilty toggled --adds a frame to the left bar; event(player,frame) must be present for left guis as there is no default -function add_frame.left(name,display,tooltip,restriction,event) +function add_frame.left(name,default_display,default_tooltip,restriction,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 - table.insert(frames.left,{name,display,event}) - ExpGui.toolbar.add_button(name,display,tooltip,restriction,draw_frame.left) + table.insert(frames.left,{name,default_display,event}) + ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.left) end --draw the left gui for the player; do not call manuley must use other functions to call function draw_frame.left(player,element) local frame_data = nil for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end - local left = player.gui.left + local left = mod_gui.get_frame_flow(player) if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end - local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2]} + local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical'} frame_data[3](player,frame) end --Please Only Edit Above This Line----------------------------------------------------------- diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua index c0e1633b..10b4678d 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua @@ -9,15 +9,69 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='File Header - ExpGaming-Core-GUI', + name='ExpGaming - Popup Gui', owner='Explosive Gaming', dev='Cooldude2606', - description='Just A File Header To Organise Code', + description='Small popups in the top left', factorio_version='0.15.23', show=false }} local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- - +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','Close This Popup',function(player,element) element.parent.destroy() end) +local function get_next_popup(popups,name) + if name then + local flow = popups.add{type='flow',name=name..'_on_click',direction='horizontal'} + local frame = flow.add{name='popup_frame',type='frame',direction='vertical'} + ExpGui.add_input.draw_button(flow,'close_popup') return frame + end + local current = #popups.children + for _,p in pairs(popups.children) do + if p.name == 'popup'..current then current = current+1 else + local flow = popups.add{type='flow',name='popup'..current,direction='horizontal'} + local frame = flow.add{name='popup_frame',type='frame',direction='vertical'} + ExpGui.add_input.draw_button(flow,'close_popup') return frame end + end + if #popups.children == 0 then + local flow = popups.add{type='flow',name='popup'..current,direction='horizontal'} + local frame = flow.add{name='popup_frame',type='frame',direction='vertical'} + ExpGui.add_input.draw_button(flow,'close_popup') return frame end +end +--adds a frame to the popup flow;restriction is the power need to use the on_click function +--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 drawen to; args is any infor you want to pass in +function add_frame.popup(style,default_display,default_tooltip,restriction,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 + local restriction = restriction or 0 + table.insert(frames.popup,{style,default_display,on_click,event}) + if on_click and type(on_click) == 'function' then + ExpGui.toolbar.add_button(style,default_display,default_tooltip,restriction,draw_frame.popup_button) + end +end +--draw the popup on_click gui for the player; do not call manuley must use other functions to call +function draw_frame.popup_button(player,element) + local frame_data = nil + for _,frame in pairs(frames.popup) do if element.name == frame[1] then frame_data = frame break end end + local popups = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} + if popups[frame_data[1]..'_on_click'] then popups[frame_data[1]..'_on_click'].destroy() return end + local frame = get_next_popup(popups,frame_data[1]) + frame_data[3](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 = nil + for _,frame in pairs(frames.popup) do if style == frame[1] then frame_data = frame break end end + for _,player in pairs(game.connected_players) do + local popups = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} + local frame = get_next_popup(popups) + frame_data[4](player,frame,args) + end +end --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua index 6515fbde..90f5d309 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -29,7 +29,7 @@ end --draw the toolbar to the player only showing buttons within their restriction function toolbar.draw(player) if not player then error('Need a player to draw to') end - local toolbar_frame = player.gui.top + local toolbar_frame = mod_gui.get_button_flow(player) toolbar_frame.clear() for _,btn in pairs(toolbar.buttons) do local rank = get_rank(player) diff --git a/locale/ExpGaming-Core/GUI/file-header.lua b/locale/ExpGaming-Core/GUI/file-header.lua index 32df0761..268d6da4 100644 --- a/locale/ExpGaming-Core/GUI/file-header.lua +++ b/locale/ExpGaming-Core/GUI/file-header.lua @@ -23,7 +23,7 @@ credit_loop(require("ExpGaming - Inputs")) credit_loop(require("ExpGaming - Toolbar")) credit_loop(require("ExpGaming - Center Gui")) credit_loop(require("ExpGaming - Left Gui")) -credit_loop(require("ExpGaming - Player Table")) credit_loop(require("ExpGaming - Popup")) +credit_loop(require("ExpGaming - Player Table")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file From 8e0df7c54338a130c1dd2c318f09ffda192cbff0 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Mon, 3 Jul 2017 22:15:50 +0100 Subject: [PATCH 18/20] Fixed Popup --- control.lua | 10 +++++-- .../GUI/ExpGaming - Left Gui.lua | 19 ++++++++++--- .../ExpGaming-Core/GUI/ExpGaming - Popup.lua | 27 +++++++++---------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/control.lua b/control.lua index 3e126981..5bfc172c 100644 --- a/control.lua +++ b/control.lua @@ -28,5 +28,11 @@ Event.register(-1,function() global.credits = credits end) ExpGui.add_frame.center('Test','Test','A Simple Gui',5) ExpGui.add_frame.tab('testing','Long Tab','Just Like any other',5,'Test',function(player,tab) for i=0,100 do tab.add{type='label',name=i,caption=player.name} end end) ExpGui.add_frame.tab('just_a_tab','A Tab','Just Like any other',5,'Test',function(player,tab) tab.add{type='label',name='temp',caption=player.name} end) -ExpGui.add_frame.left('left_test','Player Name','Just Like any other',5,function(player,frame) for i=0,10 do frame.add{type='label',name=i,caption=player.name..'\n'} end end) -ExpGui.add_frame.popup('Message','Message','Just A ToolTip',5,function(player,frame) frame.add{name='TEST',type='label',caption=player.name} end,function(player,frame,args) frame.add{name='Message',type='label',caption=args[1]..' '..args[2]} end) +ExpGui.add_frame.left('left_test','Player Name','Just Like any other',5,true,function(player,frame) for i=0,10 do frame.add{type='label',name=i,caption=player.name..'\n'} end end) +ExpGui.add_input.button('make_message','Messgaes','Lots of messages',function() for i = 1,10 do ExpGui.draw_frame.popup('Message',{'Just A Message',i}) end end) +ExpGui.add_frame.popup('Message','Message','Just A ToolTip',5, + function(player,frame) + ExpGui.add_input.draw_button(frame,'make_message') end, + function(player,frame,args) + frame.add{name='Message',type='label',caption=args[1]..' '..args[2]} +end) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua index d071a151..50242614 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -23,10 +23,12 @@ local frames = ExpGui.frames local draw_frame = ExpGui.draw_frame --left guis are always present and only have their visabilty toggled --adds a frame to the left bar; event(player,frame) must be present for left guis as there is no default -function add_frame.left(name,default_display,default_tooltip,restriction,event) +--vis must be true must be true or false based on the default stae of the gui +function add_frame.left(name,default_display,default_tooltip,restriction,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 - table.insert(frames.left,{name,default_display,event}) + local vis = vis or false + table.insert(frames.left,{name,default_display,event,vis}) ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.left) end --draw the left gui for the player; do not call manuley must use other functions to call @@ -35,8 +37,19 @@ function draw_frame.left(player,element) for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end local left = mod_gui.get_frame_flow(player) if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end - local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical'} + local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical',style=mod_gui.frame_style} frame_data[3](player,frame) 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[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end + local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical',style=mod_gui.frame_style} + frame_data[3](player,frame) + frame.style.visible = frame_data[4] + end +end) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua index 10b4678d..164629ef 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua @@ -25,21 +25,16 @@ local draw_frame = ExpGui.draw_frame ExpGui.add_input.button('close_popup','X','Close This Popup',function(player,element) element.parent.destroy() end) local function get_next_popup(popups,name) if name then - local flow = popups.add{type='flow',name=name..'_on_click',direction='horizontal'} - local frame = flow.add{name='popup_frame',type='frame',direction='vertical'} + 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 = #popups.children - for _,p in pairs(popups.children) do - if p.name == 'popup'..current then current = current+1 else - local flow = popups.add{type='flow',name='popup'..current,direction='horizontal'} - local frame = flow.add{name='popup_frame',type='frame',direction='vertical'} - ExpGui.add_input.draw_button(flow,'close_popup') return frame end - end - if #popups.children == 0 then - local flow = popups.add{type='flow',name='popup'..current,direction='horizontal'} - local frame = flow.add{name='popup_frame',type='frame',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;restriction is the power need to use the on_click function --on_click(player,element) is what is called when button is clicked if nil no button is made @@ -57,7 +52,7 @@ end function draw_frame.popup_button(player,element) local frame_data = nil for _,frame in pairs(frames.popup) do if element.name == frame[1] then frame_data = frame break end end - local popups = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} + local popups = mod_gui.get_frame_flow(player).popups if popups[frame_data[1]..'_on_click'] then popups[frame_data[1]..'_on_click'].destroy() return end local frame = get_next_popup(popups,frame_data[1]) frame_data[3](player,frame) @@ -68,10 +63,12 @@ function draw_frame.popup(style,args) local frame_data = nil for _,frame in pairs(frames.popup) do if style == frame[1] then frame_data = frame break end end for _,player in pairs(game.connected_players) do - local popups = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} + local popups = mod_gui.get_frame_flow(player).popups local frame = get_next_popup(popups) frame_data[4](player,frame,args) end end +--used to make the popup area +Event.register(defines.events.on_player_joined_game,function(event) mod_gui.get_frame_flow(game.players[event.player_index]).add{name='popups',type='flow',direction='vertical'} end) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file From bf1895fd526f708fd7ea1f9518ad1c883b2fafa7 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 4 Jul 2017 18:46:26 +0100 Subject: [PATCH 19/20] Small edits --- .../ExpGaming-Core/ExpGaming - Rank Control.lua | 10 ++++++---- .../ExpGaming-Core/ExpGaming - Rank Presets.lua | 1 + .../GUI/ExpGaming - Center Gui.lua | 2 +- .../ExpGaming-Core/GUI/ExpGaming - Left Gui.lua | 16 +++++++++++----- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua index 41f0bfec..40b8cb68 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Control.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Control.lua @@ -92,10 +92,12 @@ function find_new_rank(player) local current_rank = get_rank(player) local old_rank = get_rank(player) local possible_ranks = {current_rank} - --loops though preset ranks - for rank,players in pairs(global.preset_ranks) do - local found_rank = loop_preset_rank(players, rank) - if found_rank then table.insert(possible_ranks,string_to_rank(found_rank)) break end + --loops though preset ranks only if playtime is less than 5 minutes + if tick_to_min(player.online_time) < 5 then + for rank,players in pairs(global.preset_ranks) do + local found_rank = loop_preset_rank(players, rank) + if found_rank then table.insert(possible_ranks,string_to_rank(found_rank)) break end + end end --loops though rank times for _,rank in pairs(global.ranks) do diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua b/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua index 69d15779..9ae1d269 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Presets.lua @@ -31,6 +31,7 @@ local preset_ranks = { 'Smou'}, Mod={ + 'AcThPaU', 'Alanore', 'Aquaday', 'cafeslacker', diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua index 965eab12..cd6aca7b 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -21,7 +21,7 @@ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits local add_frame = ExpGui.add_frame local frames = ExpGui.frames local draw_frame = ExpGui.draw_frame ---adds a frame in the center; tabs is a list that can contain already defined tabs; event(player,element) is a option to have a custom gui in the center +--adds a frame in the center; tabs {{name,restriction},{...}} is a list that can contain already defined tabs; event(player,element) is a option to have a custom gui in the center function add_frame.center(name,default_display,default_tooltip,restriction,tabs,event) if not name then error('Frame requires a name') end local tabs = tabs or {} diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua index 50242614..67ee80f9 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -31,13 +31,19 @@ function add_frame.left(name,default_display,default_tooltip,restriction,vis,eve table.insert(frames.left,{name,default_display,event,vis}) ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.left) end ---draw the left gui for the player; do not call manuley must use other functions to call -function draw_frame.left(player,element) +--draw the left gui for the player; called via script, only call manuley when update is true and element is the name of the gui +function draw_frame.left(player,element,update) + local frame = nil local frame_data = nil - for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end local left = mod_gui.get_frame_flow(player) - if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end - local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical',style=mod_gui.frame_style} + if not update then + for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end + if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end + local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical',style=mod_gui.frame_style} + else + for _,frame in pairs(frames.left) do if element == frame[1] then frame_data = frame break end end + local frame = left[frame_data[1]] frame.clear() + end frame_data[3](player,frame) end --used to load all left guis From 89f69fa184ff3d7703743dcff091c40a5ed977c4 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 4 Jul 2017 20:38:13 +0100 Subject: [PATCH 20/20] Core is DONE!!! --- control.lua | 4 + .../GUI/ExpGaming - Modlue Setup.lua | 12 ++- .../GUI/ExpGaming - Player Table.lua | 102 +++++++++++++++++- 3 files changed, 113 insertions(+), 5 deletions(-) diff --git a/control.lua b/control.lua index 5bfc172c..20633dc7 100644 --- a/control.lua +++ b/control.lua @@ -36,3 +36,7 @@ ExpGui.add_frame.popup('Message','Message','Just A ToolTip',5, function(player,frame,args) frame.add{name='Message',type='label',caption=args[1]..' '..args[2]} end) +ExpGui.add_frame.tab('player_table','Player Table','Just Like any other',5,'Test',function(player,tab) + ExpGui.player_table.draw_filters(player,tab,{'player_name','online_time','rank'}) + ExpGui.player_table.draw(player,tab,{{'online',true}},tab) +end) \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua index a1697239..0117bbbb 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua @@ -38,11 +38,17 @@ ExpGui = { --draw_text }, toolbar={ - buttons={} + buttons={} + --draw + --add_button + }, + player_table={ + filters={} --draw - --add_button + --draw_filters + --get_filters + --player_match }, - --add_player_table inputs={ buttons={}, text={} diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua index c0e1633b..326db4d2 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua @@ -9,15 +9,113 @@ Discord: https://discord.gg/XSsBV6b The credit below may be used by another script do not remove. ]] local credits = {{ - name='File Header - ExpGaming-Core-GUI', + name='ExpGaming - Player Table', owner='Explosive Gaming', dev='Cooldude2606', - description='Just A File Header To Organise Code', + description='Allows addition of a player table with filters', factorio_version='0.15.23', show=false }} local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- +local player_table_functions = ExpGui.player_table +local yes = {'yes','y','true','ye'} +local no = {'no','false','nay'} +--filters that are used fell free to add more +player_table_functions.filters = { + --{name,is_text,function(player,input) return true end} + {'is_admin',false,function(player) return player.admin end}, + {'player_name',true,function(player,input) if input and player.name:lower():find(input:lower()) then return true end end}, + {'online',false,function(player) return player.connected end}, + {'offline',false,function(player) return not player.connected end}, + {'online_time',true,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}, + {'rank',true,function(player,input) if input and string_to_rank(input) and get_rank(player).power <= string_to_rank(input).power then return true end end} +} +--set up all the text inputs +for _,filter in pairs(player_table_functions.filters) do + if filter[2] then + ExpGui.add_input.text(filter[1],'Enter '..filter[1]: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) + 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[1] == 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[1]] then + if frame.input_bar[filter[1]].text ~= 'Enter '..filter[1]:gsub('_',' ') or not frame.input_bar[filter[1]].text:find('%S') then + table.insert(filters,{filter[1],frame.input_bar[filter[1]].text}) + end + end + end + return filters +end +--used to test if a player matches filter critria +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[3] and type(filter[3]) == 'function' then return filter[3](player,input) end +end +--used by script on filter texts +function player_table_functions.redraw(player,element) + local frame = global.current_filters[player.index][2] + local filters = global.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 leanth is 2 then it will not atemp to get a user input +function player_table_functions.draw(player,frame,filters,input_location) + global.current_filters[player.index] = {filters,frame} + --setup the table + if frame.player_table then frame.player_table.destroy() end + 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="Id"} + player_table.add{name="player_name", type="label", caption="Name"} + player_table.add{name="status", type="label", caption="Status"} + player_table.add{name="online_time", type="label", caption="Online Time"} + player_table.add{name="rank", type="label", caption="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 + local result = player_table_functions.player_match(p,filter[1],filter[2]) + if not result and filter[2] == true then result = filter[2] end + add = result or false + end + end + for _,filter in pairs(player_table_functions.get_filters(input_location)) do + if add then + add = player_table_functions.player_match(p,filter[1],filter[2]) or false + end + end + --add the player + if add then--and player.name ~= p.name then + 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_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} + end + end +end +Event.register(-1,function() global.current_filters = {} end) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file