From 126e51a6c324cd9dff313696a0106f4724ac15cc Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 1 Jul 2017 18:09:57 +0100 Subject: [PATCH] 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