Added Allow and other details to main rank object

This commit is contained in:
Cooldude2606
2017-09-14 17:32:28 +01:00
parent 48a0f6d22c
commit 993abf054f
2 changed files with 139 additions and 106 deletions

View File

@@ -21,7 +21,7 @@ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits
--Return the rank of a given player --Return the rank of a given player
function get_rank(player) function get_rank(player)
if player then if player then
for _,rank in pairs(global.ranks) do for _,rank in pairs(get_ranks()) do
if player.permission_group == game.permissions.get_group(rank.name) then return rank end if player.permission_group == game.permissions.get_group(rank.name) then return rank end
end end
return string_to_rank('Guest') return string_to_rank('Guest')
@@ -31,7 +31,7 @@ end
function string_to_rank(string) function string_to_rank(string)
if type(string) == 'string' then if type(string) == 'string' then
local Foundranks={} local Foundranks={}
for _,rank in pairs(global.ranks) do for _,rank in pairs(get_ranks()) do
if rank.name:lower() == string:lower() then return rank end if rank.name:lower() == string:lower() then return rank end
if rank.name:lower():find(string:lower()) then table.insert(Foundranks,rank) end if rank.name:lower():find(string:lower()) then table.insert(Foundranks,rank) end
end end
@@ -99,7 +99,7 @@ function find_new_rank(player)
end end
end end
--Loop through rank times --Loop through rank times
for _,rank in pairs(global.ranks) do for _,rank in pairs(get_ranks()) do
if rank.time and tick_to_min(player.online_time) >= rank.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 end
--Loop through possible ranks --Loop through possible ranks
@@ -142,7 +142,7 @@ Event.register(Event.rank_change,function(event)
end) end)
Event.register(-1,function() Event.register(-1,function()
global.old_ranks = {} global.old_ranks = {}
for _,rank in pairs(global.ranks) do for _,rank in pairs(get_ranks()) do
game.permissions.create_group(rank.name) game.permissions.create_group(rank.name)
for _,toRemove in pairs(rank.disallow) do for _,toRemove in pairs(rank.disallow) do
game.permissions.get_group(rank.name).set_allows_action(defines.input_action[toRemove],false) game.permissions.get_group(rank.name).set_allows_action(defines.input_action[toRemove],false)

View File

@@ -32,120 +32,153 @@ Example: defines.input_action.drop_item -> 'drop_item'
http://lua-api.factorio.com/latest/defines.html#defines.input_action http://lua-api.factorio.com/latest/defines.html#defines.input_action
--]] --]]
local ranks = { local ranks = {
{name='Owner', --these are asigned during the rank set up
short_hand='Owner', highest_timed_rank=nil,
tag='[Owner]', lowest_time_for_rank=nil,
time=nil, number_of_ranks=0,
colour={r=170,g=0,b=0}, ranks={
disallow={}}, {name='Owner',
short_hand='Owner',
{name='Community Manager', tag='[Owner]',
short_hand='Com Mngr', time=nil,
tag='[Com Mngr]', colour={r=170,g=0,b=0},
time=nil, disallow={},
colour={r=150,g=68,b=161}, allow={}},
disallow={}},
{name='Community Manager',
{name='Developer', short_hand='Com Mngr',
short_hand='Dev', tag='[Com Mngr]',
tag='[Dev]', time=nil,
time=nil, colour={r=150,g=68,b=161},
colour={r=179,g=125,b=46}, disallow={},
disallow={}}, allow={}},
{name='Admin', {name='Developer',
short_hand='Admin', short_hand='Dev',
tag='[Admin]', tag='[Dev]',
time=nil, time=nil,
colour={r=233,g=63,b=233}, colour={r=179,g=125,b=46},
disallow={ disallow={},
'set_allow_commands', allow={}},
'edit_permission_group',
'delete_permission_group', {name='Admin',
'add_permission_group'} short_hand='Admin',
}, tag='[Admin]',
time=nil,
{name='Mod', colour={r=233,g=63,b=233},
short_hand='Mod', disallow={
tag='[Mod]', 'set_allow_commands',
time=nil, 'edit_permission_group',
colour={r=0,g=170,b=0}, 'delete_permission_group',
disallow={ 'add_permission_group'},
'server_command'} allow={}
}, },
{name='Donator', {name='Mod',
short_hand='P2W', short_hand='Mod',
tag='[P2W]', tag='[Mod]',
time=nil, time=nil,
colour={r=233,g=63,b=233}, colour={r=0,g=170,b=0},
disallow={}}, disallow={
'server_command'},
{name='Veteran', allow={}
short_hand='Vet', },
tag='[Veteran]',
time=600, {name='Donator',
colour={r=140,g=120,b=200}, short_hand='P2W',
disallow={}}, tag='[P2W]',
time=nil,
{name='Member', colour={r=233,g=63,b=233},
short_hand='Mem', disallow={},
tag='[Member]', allow={}},
time=nil,
colour={r=24,g=172,b=188}, {name='Veteran',
disallow={}}, short_hand='Vet',
tag='[Veteran]',
{name='Regular', time=600,
short_hand='Reg', colour={r=140,g=120,b=200},
tag='[Regular]', disallow={},
time=180, allow={}},
colour={r=24,g=172,b=188},
disallow={ {name='Member',
'set_auto_launch_rocket', short_hand='Mem',
'change_programmable_speaker_alert_parameters', tag='[Member]',
'drop_item'} time=nil,
}, colour={r=24,g=172,b=188},
disallow={},
{name='Guest', allow={}},
short_hand='',
tag='[Guest]', {name='Regular',
time=nil, short_hand='Reg',
colour={r=255,g=159,b=27}, tag='[Regular]',
disallow={ time=180,
'build_terrain', colour={r=24,g=172,b=188},
'remove_cables', disallow={
'launch_rocket', 'set_auto_launch_rocket',
'reset_assembling_machine', 'change_programmable_speaker_alert_parameters',
'cancel_research'} 'drop_item'},
}, allow={}
},
{name='Jail',
short_hand='Jail', {name='Guest',
tag='[Jail]', short_hand='',
time=nil, tag='[Guest]',
colour={r=50,g=50,b=50}, time=nil,
disallow={ colour={r=255,g=159,b=27},
'open_character_gui', disallow={
'begin_mining', 'build_terrain',
'start_walking', 'remove_cables',
'player_leave_game'} 'launch_rocket',
'reset_assembling_machine',
'cancel_research'},
allow={}
},
{name='Jail',
short_hand='Jail',
tag='[Jail]',
time=nil,
colour={r=50,g=50,b=50},
disallow={
'open_character_gui',
'begin_mining',
'start_walking',
'player_leave_game'},
allow={}
}
} }
} }
-- Feed the disallows of each rank into the one below itself -- Feed the disallows of each rank into the one below itself
for n,rank in pairs(ranks) do for n,rank in pairs(ranks.ranks) do
local ranks_list = ranks.ranks
rank.power = n rank.power = n
if ranks[n-1] then if ranks_list[n-1] then
for _,disallow in pairs(ranks[n-1].disallow) do for _,disallow in pairs(ranks_list[n-1].disallow) do
table.insert(rank.disallow,disallow) table.insert(rank.disallow,disallow)
end end
end end
if ranks_list[n+1] then
for _,allow in pairs(ranks_list[n+1].allow) do
table.insert(rank.allow,allow)
end
end
if rank.time and not ranks.highest_timed_rank then ranks.highest_timed_rank=rank end
if rank.time then ranks.lowest_time_for_rank=rank end
ranks.number_of_ranks=ranks.number_of_ranks+1
end
-- surches the rank for a certain allow command
function rank_allowed(rank,is_allowed)
for _,allow in rank.allow do
if allow == is_allowed then return true end
end
return false
end end
-- returns a list off all the ranks, return only one part if given -- returns a list off all the ranks, return only one part if given
function get_ranks(part) function get_ranks(part)
local to_return = {} local to_return = {}
if part then if part then
for _,rank in pairs(global.ranks) do table.insert(to_return,rank[part]) end for _,rank in pairs(global.ranks.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.ranks end else to_return = global.ranks.ranks end
return to_return return to_return
end end
-- Move the ranks to the global array -- Move the ranks to the global array