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
function get_rank(player)
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
end
return string_to_rank('Guest')
@@ -31,7 +31,7 @@ end
function string_to_rank(string)
if type(string) == 'string' then
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():find(string:lower()) then table.insert(Foundranks,rank) end
end
@@ -99,7 +99,7 @@ function find_new_rank(player)
end
end
--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
end
--Loop through possible ranks
@@ -142,7 +142,7 @@ Event.register(Event.rank_change,function(event)
end)
Event.register(-1,function()
global.old_ranks = {}
for _,rank in pairs(global.ranks) do
for _,rank in pairs(get_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)

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
--]]
local ranks = {
{name='Owner',
short_hand='Owner',
tag='[Owner]',
time=nil,
colour={r=170,g=0,b=0},
disallow={}},
{name='Community Manager',
short_hand='Com Mngr',
tag='[Com Mngr]',
time=nil,
colour={r=150,g=68,b=161},
disallow={}},
{name='Developer',
short_hand='Dev',
tag='[Dev]',
time=nil,
colour={r=179,g=125,b=46},
disallow={}},
{name='Admin',
short_hand='Admin',
tag='[Admin]',
time=nil,
colour={r=233,g=63,b=233},
disallow={
'set_allow_commands',
'edit_permission_group',
'delete_permission_group',
'add_permission_group'}
},
{name='Mod',
short_hand='Mod',
tag='[Mod]',
time=nil,
colour={r=0,g=170,b=0},
disallow={
'server_command'}
},
{name='Donator',
short_hand='P2W',
tag='[P2W]',
time=nil,
colour={r=233,g=63,b=233},
disallow={}},
{name='Veteran',
short_hand='Vet',
tag='[Veteran]',
time=600,
colour={r=140,g=120,b=200},
disallow={}},
{name='Member',
short_hand='Mem',
tag='[Member]',
time=nil,
colour={r=24,g=172,b=188},
disallow={}},
{name='Regular',
short_hand='Reg',
tag='[Regular]',
time=180,
colour={r=24,g=172,b=188},
disallow={
'set_auto_launch_rocket',
'change_programmable_speaker_alert_parameters',
'drop_item'}
},
{name='Guest',
short_hand='',
tag='[Guest]',
time=nil,
colour={r=255,g=159,b=27},
disallow={
'build_terrain',
'remove_cables',
'launch_rocket',
'reset_assembling_machine',
'cancel_research'}
},
{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'}
--these are asigned during the rank set up
highest_timed_rank=nil,
lowest_time_for_rank=nil,
number_of_ranks=0,
ranks={
{name='Owner',
short_hand='Owner',
tag='[Owner]',
time=nil,
colour={r=170,g=0,b=0},
disallow={},
allow={}},
{name='Community Manager',
short_hand='Com Mngr',
tag='[Com Mngr]',
time=nil,
colour={r=150,g=68,b=161},
disallow={},
allow={}},
{name='Developer',
short_hand='Dev',
tag='[Dev]',
time=nil,
colour={r=179,g=125,b=46},
disallow={},
allow={}},
{name='Admin',
short_hand='Admin',
tag='[Admin]',
time=nil,
colour={r=233,g=63,b=233},
disallow={
'set_allow_commands',
'edit_permission_group',
'delete_permission_group',
'add_permission_group'},
allow={}
},
{name='Mod',
short_hand='Mod',
tag='[Mod]',
time=nil,
colour={r=0,g=170,b=0},
disallow={
'server_command'},
allow={}
},
{name='Donator',
short_hand='P2W',
tag='[P2W]',
time=nil,
colour={r=233,g=63,b=233},
disallow={},
allow={}},
{name='Veteran',
short_hand='Vet',
tag='[Veteran]',
time=600,
colour={r=140,g=120,b=200},
disallow={},
allow={}},
{name='Member',
short_hand='Mem',
tag='[Member]',
time=nil,
colour={r=24,g=172,b=188},
disallow={},
allow={}},
{name='Regular',
short_hand='Reg',
tag='[Regular]',
time=180,
colour={r=24,g=172,b=188},
disallow={
'set_auto_launch_rocket',
'change_programmable_speaker_alert_parameters',
'drop_item'},
allow={}
},
{name='Guest',
short_hand='',
tag='[Guest]',
time=nil,
colour={r=255,g=159,b=27},
disallow={
'build_terrain',
'remove_cables',
'launch_rocket',
'reset_assembling_machine',
'cancel_research'},
allow={}
},
{name='Jail',
short_hand='Jail',
tag='[Jail]',
time=nil,
colour={r=50,g=50,b=50},
disallow={
'open_character_gui',
'begin_mining',
'start_walking',
'player_leave_game'},
allow={}
}
}
}
-- 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
if ranks[n-1] then
for _,disallow in pairs(ranks[n-1].disallow) do
if ranks_list[n-1] then
for _,disallow in pairs(ranks_list[n-1].disallow) do
table.insert(rank.disallow,disallow)
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
-- returns a list off all the ranks, return only one part if given
function get_ranks(part)
local to_return = {}
if part then
for _,rank in pairs(global.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.ranks end
for _,rank in pairs(global.ranks.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.ranks.ranks end
return to_return
end
-- Move the ranks to the global array