mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Ranks done
This commit is contained in:
@@ -36,4 +36,6 @@ Ranking, Server, Gui = require('/locale/ExpCore/load'){'Ranking','Server','Gui'}
|
||||
-- this loads the ranks that Ranking uses
|
||||
require('/locale/ExpCore/ranks')
|
||||
-- this loads any edits that are not need in core pcall as file may not be preset
|
||||
pcall(require,'/locale/Addons/playerRanks')
|
||||
pcall(require,'/locale/Addons/playerRanks')
|
||||
-- this makes sure that all the little details are cleaned up
|
||||
Ranking._auto_edit_ranks()
|
||||
|
||||
@@ -36,6 +36,36 @@ http://lua-api.factorio.com/latest/defines.html#defines.input_action
|
||||
|
||||
-- see ExpCore/ranks.lua for examples - you add your own and edit pre-made ones here.
|
||||
|
||||
function Ranking._base_preset()
|
||||
return {}
|
||||
end
|
||||
local groups = Ranking._groups(true)
|
||||
local ranks = Ranking._ranks(true)
|
||||
|
||||
groups['Root']:edit('allow',false,{
|
||||
['testing']=true
|
||||
})
|
||||
ranks['Root']:edit('test',true,'testing')
|
||||
|
||||
groups['User']:add_rank{
|
||||
name='Veteran',
|
||||
short_hand='Vet',
|
||||
tag='[Veteran]',
|
||||
time=600,
|
||||
colour={r=140,g=120,b=200},
|
||||
power=8
|
||||
}
|
||||
groups['User']:add_rank{
|
||||
name='Regular',
|
||||
short_hand='Reg',
|
||||
tag='[Regular]',
|
||||
time=180,
|
||||
colour={r=24,g=172,b=188},
|
||||
power=10
|
||||
}
|
||||
|
||||
Ranking._base_preset{
|
||||
['badgamernl']='Owner',
|
||||
['arty714']='Community Manager',
|
||||
['cooldude2606']='Developer',
|
||||
['eissturm']='Admin',
|
||||
['mark9064']='Admin',
|
||||
['smou']='Admin'
|
||||
}
|
||||
@@ -27,14 +27,14 @@ function Ranking._meta()
|
||||
end
|
||||
|
||||
-- this function is to avoid errors - see addons/playerRanks.lua
|
||||
function Ranking._base_preset()
|
||||
return {}
|
||||
function Ranking._base_preset(table)
|
||||
Ranking._presets().current = table
|
||||
end
|
||||
|
||||
-- this returns a global list
|
||||
function Ranking._presets()
|
||||
if not global.exp_core then global.exp_core = {} end
|
||||
if not global.exp_core.ranking then global.exp_core.ranking = {meta=Ranking._meta(),old={},current=Ranking._base_preset()} end
|
||||
if not global.exp_core.ranking then global.exp_core.ranking = {meta=Ranking._meta(),old={},current={}} end
|
||||
return global.exp_core.ranking
|
||||
end
|
||||
|
||||
@@ -56,8 +56,8 @@ function Ranking.get_rank(mixed)
|
||||
else
|
||||
_return = game.players[mixed] and ranks[game.players[mixed].permission_group.name]
|
||||
or table.autokey(ranks,mixed) and table.autokey(ranks,mixed)
|
||||
or string.contains(mixed,'server') and Ranking.get_group('Root').highest
|
||||
or string.contains(mixed,'root') and Ranking.get_group('Root').highest
|
||||
or string.contains(mixed,'server') and Ranking.get_rank(Ranking._presets().meta.root)
|
||||
or string.contains(mixed,'root') and Ranking.get_rank(Ranking._presets().meta.root)
|
||||
or false
|
||||
end
|
||||
return _return
|
||||
@@ -228,6 +228,20 @@ function Ranking._rank:print(rtn)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- this is used to edit a group once made key is what is being edited and set_value makes it over ride the current value
|
||||
-- see Addons/playerRanks for examples
|
||||
function Ranking._rank:edit(key,set_value,value)
|
||||
if game then return end
|
||||
if set_value then self[key] = value return end
|
||||
if key == 'disallow' then
|
||||
self.disallow = table.merge(self.disallow,value,true)
|
||||
elseif key == 'allow' then
|
||||
self.allow = table.merge(self.allow,value)
|
||||
end
|
||||
Ranking._update_rank(self)
|
||||
end
|
||||
|
||||
-- this is the base group object, do not store in global, these cant be used in game
|
||||
|
||||
-- this makes a new group
|
||||
@@ -236,6 +250,7 @@ function Ranking._group:create(obj)
|
||||
if game then return end
|
||||
if not is_type(obj.name,'string') then return end
|
||||
setmetatable(obj,{__index=Ranking._group})
|
||||
self.index = #Ranking._groups(names)+1
|
||||
obj.ranks = {}
|
||||
obj.allow = obj.allow or {}
|
||||
obj.disallow = obj.disallow or {}
|
||||
@@ -257,18 +272,31 @@ function Ranking._group:add_rank(obj)
|
||||
obj.disallow = obj.disallow or {}
|
||||
setmetatable(obj.allow,{__index=self.allow})
|
||||
setmetatable(obj.disallow,{__index=self.disallow})
|
||||
Ranking._add_rank(obj)
|
||||
Ranking._add_rank(obj,obj.power)
|
||||
Ranking._set_rank_power()
|
||||
table.insert(self.ranks,obj)
|
||||
if not self.highest or obj.power > self.highest.power then self.highest = obj end
|
||||
if not self.lowest or obj.power < self.lowest.power then self.lowest = obj end
|
||||
end
|
||||
|
||||
-- this is used to edit a group once made key is what is being edited and set_value makes it over ride the current value
|
||||
-- see Addons/playerRanks for examples
|
||||
function Ranking._group:edit(key,set_value,value)
|
||||
if game then return end
|
||||
if set_value then self[key] = value return end
|
||||
if key == 'disallow' then
|
||||
self.disallow = table.merge(self.disallow,value,true)
|
||||
elseif key == 'allow' then
|
||||
self.allow = table.merge(self.allow,value)
|
||||
end
|
||||
Ranking._update_group(self)
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_player_joined_game,function(event)
|
||||
Ranking.find_preset(event.player_index)
|
||||
end)
|
||||
|
||||
Event.register(-1,function(event)
|
||||
Event.register(-1,function(event)
|
||||
for power,rank in pairs(Ranking._ranks()) do
|
||||
local perm = game.permissions.create_group(rank.name)
|
||||
for _,toRemove in pairs(rank.disallow) do
|
||||
|
||||
@@ -11,8 +11,10 @@ local groups = {}
|
||||
local ranks = {}
|
||||
|
||||
function Ranking._add_group(group) if game then return end table.insert(groups,group) end
|
||||
function Ranking._add_rank(rank) if game then return end table.insert(ranks,rank) end
|
||||
function Ranking._add_rank(rank,pos) if game then return end if pos then table.insert(ranks,pos,rank) else table.insert(ranks,rank) end end
|
||||
function Ranking._set_rank_power() if game then return end for power,rank in pairs(ranks) do rank.power = power end end
|
||||
function Ranking._update_rank(rank) if game then return end ranks[rank.power] = rank end
|
||||
function Ranking._update_group(group) if game then return end groups[group.index] = group end
|
||||
|
||||
--[[
|
||||
How to use groups:
|
||||
@@ -42,6 +44,8 @@ http://lua-api.factorio.com/latest/defines.html#defines.input_action
|
||||
|
||||
-- If you wish to add more groups please use addons/playerRanks.lua
|
||||
-- If you wish to add to these rank groups use addons/playerRanks.lua
|
||||
-- Ranks will inherite from each other ie higher ranks can do everything lower ranks can
|
||||
-- But groups do not inherite from each other
|
||||
-- DO NOT REMOVE ANY OF THESE GROUPS
|
||||
|
||||
local root = Ranking._group:create{
|
||||
@@ -54,17 +58,32 @@ local root = Ranking._group:create{
|
||||
local admin = Ranking._group:create{
|
||||
name='Admin',
|
||||
allow={},
|
||||
disallow={}
|
||||
disallow={
|
||||
'set_allow_commands',
|
||||
'edit_permission_group',
|
||||
'delete_permission_group',
|
||||
'add_permission_group'
|
||||
}
|
||||
}
|
||||
local user = Ranking._group:create{
|
||||
name='User',
|
||||
allow={},
|
||||
disallow={}
|
||||
disallow={
|
||||
'set_allow_commands',
|
||||
'edit_permission_group',
|
||||
'delete_permission_group',
|
||||
'add_permission_group'
|
||||
}
|
||||
}
|
||||
local jail = Ranking._group:create{
|
||||
name='Jail',
|
||||
allow={},
|
||||
disallow={}
|
||||
disallow={
|
||||
'set_allow_commands',
|
||||
'edit_permission_group',
|
||||
'delete_permission_group',
|
||||
'add_permission_group'
|
||||
}
|
||||
}
|
||||
|
||||
-- If you wish to add more ranks please use addons/playerRanks.lua
|
||||
@@ -76,15 +95,100 @@ root:add_rank{
|
||||
colour=defines.color.white,
|
||||
is_root=true
|
||||
}
|
||||
root:add_rank{
|
||||
name='Owner',
|
||||
short_hand='Owner',
|
||||
tag='[Owner]',
|
||||
time=nil,
|
||||
colour={r=170,g=0,b=0}
|
||||
}
|
||||
root:add_rank{
|
||||
name='Community Manager',
|
||||
short_hand='Com Mngr',
|
||||
tag='[Com Mngr]',
|
||||
colour={r=150,g=68,b=161}
|
||||
}
|
||||
root:add_rank{
|
||||
name='Developer',
|
||||
short_hand='Dev',
|
||||
tag='[Dev]',
|
||||
colour={r=179,g=125,b=46}
|
||||
}
|
||||
|
||||
admin:add_rank{
|
||||
name='Admin',
|
||||
short_hand='Admin',
|
||||
tag='[Admin]',
|
||||
colour={r=233,g=63,b=233}
|
||||
}
|
||||
admin:add_rank{
|
||||
name='Mod',
|
||||
short_hand='Mod',
|
||||
tag='[Mod]',
|
||||
colour={r=0,g=170,b=0},
|
||||
disallow={
|
||||
'server_command'
|
||||
}
|
||||
}
|
||||
|
||||
user:add_rank{
|
||||
name='Donator',
|
||||
short_hand='P2W',
|
||||
tag='[P2W]',
|
||||
colour={r=233,g=63,b=233}
|
||||
}
|
||||
user:add_rank{
|
||||
name='Member',
|
||||
short_hand='Mem',
|
||||
tag='[Member]',
|
||||
colour={r=24,g=172,b=188},
|
||||
disallow={
|
||||
'set_auto_launch_rocket',
|
||||
'change_programmable_speaker_alert_parameters',
|
||||
'drop_item'
|
||||
}
|
||||
}
|
||||
user:add_rank{
|
||||
name='Guest',
|
||||
short_hand='',
|
||||
tag='',
|
||||
colour={r=255,g=159,b=27},
|
||||
is_default=true
|
||||
is_default=true,
|
||||
disallow={
|
||||
'build_terrain',
|
||||
'remove_cables',
|
||||
'launch_rocket',
|
||||
'reset_assembling_machine',
|
||||
'cancel_research'
|
||||
}
|
||||
}
|
||||
|
||||
jail:add_rank{
|
||||
name='Jail',
|
||||
short_hand='Jail',
|
||||
tag='[Jail]',
|
||||
colour={r=50,g=50,b=50},
|
||||
disallow={
|
||||
'open_character_gui',
|
||||
'begin_mining',
|
||||
'start_walking',
|
||||
'player_leave_game'
|
||||
}
|
||||
}
|
||||
|
||||
function Ranking._auto_edit_ranks()
|
||||
for power,rank in pairs(ranks) do
|
||||
if ranks[power-1] then
|
||||
rank:edit('disallow',false,ranks[power-1].disallow)
|
||||
end
|
||||
end
|
||||
for power = #ranks, 1, -1 do
|
||||
rank = ranks[power]
|
||||
if ranks[power+1] then
|
||||
rank:edit('allow',false,ranks[power+1].allow)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- used to force rank to be read-only
|
||||
function Ranking._groups(name)
|
||||
if name then
|
||||
@@ -112,7 +216,7 @@ end
|
||||
|
||||
-- used to save lag by doing some calculation at the start
|
||||
function Ranking._meta()
|
||||
local meta = {}
|
||||
local meta = {time_ranks={}}
|
||||
for power,rank in pairs(ranks) do
|
||||
if rank.is_default then
|
||||
meta.default = rank.name
|
||||
|
||||
@@ -185,7 +185,7 @@ if commands._expgaming then
|
||||
local callback = args.code
|
||||
if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end
|
||||
if game.player then callback = 'local player, surface, force = game.player, game.player.surface, game.player.force '..callback end
|
||||
if Ranking and Ranking.get_rank then callback = 'local rank = Ranking.get_rank(game.player) '..callback end
|
||||
if Ranking and Ranking.get_rank and game.player then callback = 'local rank = Ranking.get_rank(game.player) '..callback end
|
||||
local success, err = Server.interface(callback)
|
||||
player_return(err)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user