Added module: ExpGamingCore.Ranking

This commit is contained in:
Cooldude2606
2018-06-02 21:08:33 +01:00
parent 4d05f13cb3
commit b8b514b133
12 changed files with 432 additions and 353 deletions

View File

@@ -150,7 +150,8 @@ Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tost
-- @usage global[key] -- used like the normal global table -- @usage global[key] -- used like the normal global table
-- @usage global{'foo','bar'} -- sets the default value -- @usage global{'foo','bar'} -- sets the default value
-- @usage global(true) -- restores global to default -- @usage global(true) -- restores global to default
-- @tparam[opt={}] ?table|true default the default value of global, if true then default is restored -- @usage global(mopdule_name) -- returns that module's global
-- @tparam[opt={}] ?table|string|true if table then the default for the global, if a string then the module to get the global of, if true then reset the global to default
-- @treturn table the new global table for that module -- @treturn table the new global table for that module
Manager.global=setmetatable({__defaults={},__global={ Manager.global=setmetatable({__defaults={},__global={
__call=function(tbl,default) return Manager.global(default) end, __call=function(tbl,default) return Manager.global(default) end,
@@ -167,8 +168,10 @@ Manager.global=setmetatable({__defaults={},__global={
}},{ }},{
__call=function(tbl,default) __call=function(tbl,default)
local global = _G.global local global = _G.global
local module_name = type(default) == 'string' and default or module_name
local module_path = type(default) == 'string' and moduleIndex[default] or module_path
if not module_path or not module_name then return _G.global end if not module_path or not module_name then return _G.global end
if default then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end if type(default) == 'table' then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end
local path = 'global' local path = 'global'
local new_dir = false local new_dir = false
for dir in module_path:gmatch('%a+') do for dir in module_path:gmatch('%a+') do

View File

@@ -1 +1,3 @@
new_type('command','Commands',false,'param') new_type('command','Commands',false,'param')
new_type('event','Commands',false,'field')
new_type('gui','Commands')

View File

@@ -1,104 +1,168 @@
--[[ --- A full ranking system for factorio.
Explosive Gaming -- @module ExpGamingCore.Ranking
-- @alias Ranking
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local Ranking = {} local Ranking = {}
defines.events.rank_change = script.generate_event_name() local module_verbose = false --true|false
Ranking._rank = {}
Ranking._group = {} --- Global Table
-- this is just for debuging when setting you rank powers -- @table global
-- @field old contains the previous rank a use had before a rank change
-- @field preset contains the preset ranks that users will recive apon joining
-- @filed last_change contains the name of the player who last had there rank chagned
local global = global{old={},preset={},last_change=nil}
--- Called when there is a rank change for a user
-- @event rank_change
-- @field name the rank id
-- @field tick the tick which the event was raised on
-- @field player_index the player whos rank was changed
-- @field by_player_index the player who changed the rank, 0 means server
-- @field new_rank the name of the rank that was given
-- @field old_rank the name of the rank the player had
script.generate_event_name('rank_change')
--- Outputs as a string all the ranks and the loaded order
-- @usage Ranking.output_ranks(player) -- prints to player
-- @tparam[opt=server] ?player_name|player_index|LuaPlayer player the player that the info will be printed to, nil will print to server
-- @todo show inheritance of ranks
function Ranking.output_ranks(player) function Ranking.output_ranks(player)
local player = Game.get_player(player) or game.player or nil local player = Game.get_player(player) or game.player or nil
if not player then return end local function output(rank)
for power,rank in pairs(Ranking._ranks()) do
local output = power..') '..rank.name
output=output..' '..rank.tag
local admin = 'No'; if rank.is_root then admin = 'Root' elseif rank.is_admin then admin = 'Yes' end local admin = 'No'; if rank.is_root then admin = 'Root' elseif rank.is_admin then admin = 'Yes' end
output=output..' Admin: '..admin local rtn = string.format('%s) %q %s > Admin: %s Group: %q AFK: %s Time: %s',
output=output..' Group: '..rank.group.name rank.power,rank.name,rank.tag,admin,rank.group,tostring(rank.base_afk_time),tostring(rank.time))
output=output..' AFK: '..tostring(rank.base_afk_time) player_return(rtn,rank.colour,player)
player_return(output,rank.colour,player)
end end
local function recur(_rank)
for name,rank in pairs(_rank.children) do output(Ranking.ranks[rank]) end
for name,rank in pairs(_rank.children) do recur(Ranking.ranks[rank]) end
end
local root = Ranking.get_rank(Ranking.meta.root)
output(root)
recur(root)
end end
-- this function is to avoid errors - see /ranks.lua --- Contains the location of all the ranks, readonly during runtime
function Ranking._ranks(names) -- @table Ranking.ranks
return {} Ranking.ranks = setmetatable({},{
__metatable=false,
__index=table.autokey,
__newindex=function(tbl,key,value) if game then error('Can not create new ranks during runtime',2) else rawset(tbl,key,value) end end,
__len=function(tbl)
local rtn = 0
for name,rank in pairs(tbl) do
rtn=rtn+1
end end
return rtn
-- this function is to avoid errors - see /ranks.lua
function Ranking._groups(names)
return {}
end end
})
-- this function is to avoid errors - see /ranks.lua --- Contains the location of all the rank groups, readonly during runtime
function Ranking._meta() -- @table Ranking.ranks
return {} Ranking.groups = setmetatable({},{
__metatable=false,
__index=table.autokey,
__newindex=function(tbl,key,value) if game then error('Can not create new rank groups during runtime',2) else rawset(tbl,key,value) end end,
__len=function(tbl)
local rtn = 0
for name,rank in pairs(tbl) do
rtn=rtn+1
end end
return rtn
-- this function is to avoid errors - see addons/playerRanks.lua
function Ranking._base_preset(table)
Ranking._presets().current = table
end end
})
-- this returns a global list --- Contains some meta data about the ranks
function Ranking._presets() -- @table Ranking.meta
if not global.exp_core then global.exp_core = {} end -- @field default this is the name of the default rank
if not global.exp_core.ranking then global.exp_core.ranking = {meta=Ranking._meta(),old={},current={},last_jail=nil} end -- @filed root this is the name of the root rank
return global.exp_core.ranking -- @field time_ranks a list of all ranks which have a time requirement
-- @field time_highest the power of the highest rank that has a time requirement
-- @field time_lowest the lowest amount of time required for a time rank
Ranking.meta = setmetatable({},{
__metatable=false,
__call=function(tbl)
rawset(tbl,'time_ranks',{})
for name,rank in pairs(Ranking.ranks) do
if not rawget(tbl,'default') and rank.is_default then rawset(tbl,'default',rank.name) end
if not rawget(tbl,'root') and rank.is_root then rawset(tbl,'root',rank.name) end
if rank.time then
table.insert(tbl.time_ranks,rank.name)
if not rawget(tbl,'time_highest') or rank.power < tbl.time_highest then if rank.power then rawset(tbl,'time_highest',rank.power) end end
if not rawget(tbl,'time_lowest') or rank.time < tbl.time_lowest then rawset(tbl,'time_lowest',rank.time) end
end
end
if not rawget(tbl,'default') then error('No default rank') end
if not rawget(tbl,'root') then error('No root rank') end
end,
__index=function(tbl,key)
tbl()
return rawget(tbl,key)
end,
__newindex=function() error('Ranking metadata is read only',2) end
})
--- Used to set the prset ranks that will be given to players
-- @usage Ranking._base_preset{name=rank_name,nameTwo=rank_name_two} -- sets player name to have rank rank_name on join
-- @tparam table ranks table of player names with the player name as the key and rank name as the value
function Ranking._base_preset(ranks)
if not is_type(ranks,'table') then error('Ranking._base_preset was not given a table',2) end
global.preset = ranks
end end
--- Returns a rank object given a player or rank name --- Returns a rank object given a player or rank name
-- @usage Ranking.get_rank(game.player) -- @usage Ranking.get_rank(game.player) -- returns player's rank
-- Ranking.get_rank('admin') -- @usage Ranking.get_rank('admin') -- returns rank by the name of admin
-- @param mixed player|player index|player name|rank name|rank|'server'|'root' what rank to get -- @tparam ?player|player_index|player_name|rank_name|Ranking._rank|'server'|'root' mixed what rank to get
-- @treturn table the rank that is linked to mixed -- @treturn[1] table the rank that is linked to mixed
-- @trrturn[2] nil there was no rank found
function Ranking.get_rank(mixed) function Ranking.get_rank(mixed)
if not mixed then return false end if not mixed then return error('Ranking.get_rank recived no paramerters') end
local ranks = Ranking._ranks(true) local ranks = Ranking.ranks
local _return = false local _return = false
if is_type(mixed,'table') then if is_type(mixed,'table') then
if mixed.index then -- is it a player, then get player rank; if it is a rank then return the rank
_return = game.players[mixed.index] and ranks[mixed.permission_group.name] or nil if mixed.index then _return = game.players[mixed.index] and ranks[mixed.permission_group.name] or error('Invalid player name to Ranking.get_rank',2)
else _return = mixed.group and mixed or nil end
else else
_return = mixed.group and mixed or nil -- if it is a player name/index, then get player rank; if it is a rank name, get that rank; if it is server or root; return root rank; else nil
end _return = game and game.players[mixed] and ranks[game.players[mixed].permission_group.name]
else
_return = game.players[mixed] and ranks[game.players[mixed].permission_group.name]
or table.autokey(ranks,mixed) and table.autokey(ranks,mixed) or table.autokey(ranks,mixed) and table.autokey(ranks,mixed)
or string.contains(mixed,'server') and Ranking.get_rank(Ranking._presets().meta.root) or string.contains(mixed,'server') and Ranking.get_rank(Ranking.meta.root)
or string.contains(mixed,'root') and Ranking.get_rank(Ranking._presets().meta.root) or string.contains(mixed,'root') and Ranking.get_rank(Ranking.meta.root)
or nil or nil
end end
return _return return _return
end end
--- Returns the group object used to sort ranks given group name or see Ranking.get_rank --- Returns the group object used to sort ranks given group name or rank
-- @usage Ranking.get_group(game.player) -- @usage Ranking.get_group(game.player) -- returns player's rank group
-- Ranking.get_group('root') -- @usage Ranking.get_group('root') -- returns group by name of root
-- @param mixed player|player index|player name|rank name|rank|'server'|'root'|group name|group what group to get -- @tparam ?player|player_index|player_name|rank_name|rank|'server'|'root'|group name|group mixed what group to get
-- @treturn table the group that is linked to mixed -- @see Ranking.get_rank
-- @treturn[1] table the group that is linked to mixed
-- @trrturn[2] nil there was no rank group found
function Ranking.get_group(mixed) function Ranking.get_group(mixed)
if not mixed then return false end if not mixed then return error('Ranking.get_group recived no paramerters') end
local groups = Ranking._groups(true) local groups = Ranking.groups
local rank = Ranking.get_rank(mixed) local rank = Ranking.get_rank(mixed)
return rank and rank.group -- if it is a table see if it is a group, return the group; if it is a string, return group by that name; if there is a rank found, return the ranks group
or is_type(mixed,'table') and mixed.ranks and mixed return is_type(mixed,'table') and not mixed.__self and mixed.ranks and mixed
or is_type(mixed,'string') and table.autokey(groups,mixed) and table.autokey(groups,mixed) or is_type(mixed,'string') and table.autokey(groups,mixed)
or false or rank and rank.group
or nil
end end
--- Prints to all rank of greater/lower power of the rank given --- Prints to all rank of greater/lower power of the rank given
-- @usage Ranking.print('admin','We got a grifer') -- @usage Ranking.print('admin','We got a grifer')
-- @param rank_base the rank that acts as the cut off point (rank is always included) -- @todo change to use parent and child ranks rather than power
-- @tparam ?Ranking._rank|pointerToRank rank_base the rank that acts as the cut off point (rank is always included)
-- @param rtn what do you want to return to the players -- @param rtn what do you want to return to the players
-- @tparam defines.color colour the colour that will be used to print -- @tparam[opt=defines.color.white] defines.color colour the colour that will be used to print
-- @tparam bolean below if true rank below base are printed to -- @tparam[opt=false] boolean below if true print to children rather than parents
function Ranking.print(rank_base,rtn,colour,below) function Ranking.print(rank_base,rtn,colour,below)
local colour = colour or defines.color.white local colour = colour or defines.color.white
local rank_base = Ranking.get_rank(rank_base) local rank_base = Ranking.get_rank(rank_base)
@@ -116,51 +180,42 @@ end
--- Gives a user a rank --- Gives a user a rank
-- @usage Ranking.give_rank(1,'admin') -- @usage Ranking.give_rank(1,'admin')
-- @param player the player to give the rank to -- @tparam ?LuaPlayer|pointerToPlayer player the player to give the rank to
-- @param rank the rank to give to the player -- @tparam[opt=default] ?Ranking._rank|pointerToRank rank the rank to give to the player
-- @param[opt='server'] by_player the player who is giving the rank -- @tparam[opt='server'] ?LuaPlayer|pointerToPlayer by_player the player who is giving the rank
-- @param[opt=game.tick] tick the tick that the rank is being given on -- @tparam[opt=game.tick] number tick the tick that the rank is being given on, used as pass though
function Ranking.give_rank(player,rank,by_player,tick) function Ranking.give_rank(player,rank,by_player,tick)
local print_colour = defines.textcolor.info local print_colour = defines.textcolor.info
local tick = tick or game.tick local tick = tick or game.tick
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or game.player and game.player.name or is_type(by_player,'string') and by_player or 'server' local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or game.player and game.player.name or is_type(by_player,'string') and by_player or 'server'
local rank = Ranking.get_rank(rank) or Ranking.get_rank(Ranking._presets().meta.default) local rank = Ranking.get_rank(rank) or Ranking.get_rank(Ranking.meta.default)
local player = Game.get_player(player) or error('No Player To Give Rank') local player = Game.get_player(player) or error('No player given to Ranking.give_rank',2)
local old_rank = Ranking.get_rank(player) or Ranking.get_rank(Ranking._presets().meta.default) local old_rank = Ranking.get_rank(player) or Ranking.get_rank(Ranking.meta.default)
local message = 'ranking.rank-down' local message = 'ranking.rank-down'
-- messaging -- messaging
if old_rank.name == rank.name then return end if old_rank.name == rank.name then return end
if rank.power < old_rank.power then message = 'ranking.rank-up' player.play_sound{path='utility/achievement_unlocked'} if rank.power < old_rank.power then message = 'ranking.rank-up' player.play_sound{path='utility/achievement_unlocked'}
else player.play_sound{path='utility/game_lost'} end else player.play_sound{path='utility/game_lost'} end
if player.online_time > 60 or by_player_name ~= 'server' then game.print({message,player.name,rank.name,by_player_name},print_colour) end if player.online_time > 60 or by_player_name ~= 'server' then game.print({message,player.name,rank.name,by_player_name},print_colour) end
if rank.group.name ~= 'User' then player_return({'ranking.rank-given',rank.name},print_colour,player) end if rank.group ~= 'User' then player_return({'ranking.rank-given',rank.name},print_colour,player) end
if player.tag ~= old_rank.tag then player_return({'ranking.tag-reset'},print_colour,player) end if player.tag ~= old_rank.tag then player_return({'ranking.tag-reset'},print_colour,player) end
-- rank change -- rank change
player.permission_group = game.permissions.get_group(rank.name) player.permission_group = game.permissions.get_group(rank.name)
player.tag = rank.tag player.tag = rank.tag
if old_rank.group.name ~= 'Jail' then Ranking._presets().old[player.index] = old_rank.name end if old_rank.group ~= 'Jail' then global.old[player.index] = old_rank.name end
player.admin = rank.is_admin or false player.admin = rank.is_admin or false
player.spectator = rank.is_spectator or false player.spectator = rank.is_spectator or false
if defines.events.rank_change then local by_player_index = by_player_name == 'server' and 0 or Game.get_player(by_player_name).index
script.raise_event(defines.events.rank_change,{ script.raise_event(defines.events.rank_change,{
name=defines.events.rank_change, name=defines.events.rank_change,
tick=tick, tick=tick,
player_index=player.index, player_index=player.index,
by_player_name=by_player_name, by_player_index=by_player_index,
new_rank=rank, new_rank=rank.name,
old_rank=old_rank old_rank=old_rank.name
}) })
end -- logs to file if rank is chagned after first join
if rank.group.name == 'Jail' and Ranking._presets().last_jail ~= player.name then if player.online_time > 60 then
Sync.emit_embeded{
title='Player Jail',
color=Color.to_hex(defines.textcolor.med),
description='There was a player jailed.',
['Player:']=player.name,
['By:']='<<inline>>'..by_player_name,
['Reason:']='No Reason'
}
end
game.write_file('ranking-change.json', game.write_file('ranking-change.json',
table.json({ table.json({
tick=tick, tick=tick,
@@ -168,37 +223,40 @@ function Ranking.give_rank(player,rank,by_player,tick)
player_name=player.name, player_name=player.name,
by_player_name=by_player_name, by_player_name=by_player_name,
new_rank=rank.name, new_rank=rank.name,
old_rank=old_rank.name, old_rank=old_rank.name
power_increase=(old_rank.power-rank.power)
})..'\n' })..'\n'
, true, 0) , true, 0)
end end
end
--- Revert the last change to a players rank --- Revert the last change to a players rank
-- @usage Ranking.revert(1) -- @usage Ranking.revert(1) -- reverts the rank of player with index 1
-- @param player the player to revert the rank of -- @tparam ?LuaPlayer|pointerToPlayer player the player to revert the rank of
-- @param[opt=nil] by_player the player who is doing the revert -- @param[opt=nil] by_player the player who is doing the revert
function Ranking.revert(player,by_player) function Ranking.revert(player,by_player)
local player = Game.get_player(player) local player = Game.get_player(player)
Ranking.give_rank(player,Ranking._presets().old[player.index],by_player) Ranking.give_rank(player,global.old[player.index],by_player)
end end
--- Given the player has a rank in the preset table it is given --- Given that the player has a rank in the preset table it is given; also will attempt to promote players if a time requirement is met
-- @usage Ranking.find_preset(1) -- @usage Ranking.find_preset(1) -- attemps to find the preset for player with index 1
-- @param player the player to test for an auto rank -- @tparam ?LuaPlayer|pointerToPlayer player the player to test for an auto rank
-- @tparam[opt=nil] number tick the tick it happens on -- @tparam[opt=nil] number tick the tick it happens on
function Ranking.find_preset(player,tick) function Ranking.find_preset(player,tick)
local presets = Ranking._presets().current local presets = global.preset
local meta_data = Ranking._presets().meta local meta_data = Ranking.meta
local default = Ranking.get_rank(meta_data.default) local default = Ranking.get_rank(meta_data.default)
local player = Game.get_player(player) local player = Game.get_player(player)
local current_rank = Ranking.get_rank(player) or {power=-1,group={name='not jail'}} local current_rank = Ranking.get_rank(player) or {power=-1,group='not jail'}
local ranks = {default} local ranks = {default}
if current_rank.group.name == 'Jail' then return end -- users in rank group jail are ingroned
if current_rank.group == 'Jail' then return end
-- looks in preset table for player name
if presets[string.lower(player.name)] then if presets[string.lower(player.name)] then
local rank = Ranking.get_rank(presets[string.lower(player.name)]) local rank = Ranking.get_rank(presets[string.lower(player.name)])
table.insert(ranks,rank) table.insert(ranks,rank)
end end
-- if the player mets check requirements then play time is checked
if current_rank.power > meta_data.time_highest and tick_to_min(player.online_time) > meta_data.time_lowest then if current_rank.power > meta_data.time_highest and tick_to_min(player.online_time) > meta_data.time_lowest then
for _,rank_name in pairs(meta_data.time_ranks) do for _,rank_name in pairs(meta_data.time_ranks) do
local rank = Ranking.get_rank(rank_name) local rank = Ranking.get_rank(rank_name)
@@ -207,11 +265,13 @@ function Ranking.find_preset(player,tick)
end end
end end
end end
-- if the new rank is closer to root then it is the new rank
local _rank = current_rank local _rank = current_rank
for _,rank in pairs(ranks) do for _,rank in pairs(ranks) do
if rank.power < _rank.power or _rank.power == -1 then _rank = rank end if rank.power < _rank.power or _rank.power == -1 then _rank = rank end
end end
if _rank then -- this new rank is given to the player
if _rank.name == current_rank.name then return end
if _rank.name == default.name then if _rank.name == default.name then
player.tag = _rank.tag player.tag = _rank.tag
player.permission_group = game.permissions.get_group(_rank.name) player.permission_group = game.permissions.get_group(_rank.name)
@@ -219,174 +279,199 @@ function Ranking.find_preset(player,tick)
Ranking.give_rank(player,_rank,nil,tick) Ranking.give_rank(player,_rank,nil,tick)
end end
end end
end
-- this is the base rank object, do not store in global --- The class for the ranks
-- @type Rank
-- @alias Ranking._rank
-- @field name the name that is given to the rank, must be unique
-- @field short_hand the shorter way of displaying this rank, can be used by other modules
-- @field tag the tag that player in this rank will be given
-- @field colour the colour that modules should display this rank as in guis
-- @field parent the name of the rank that permissions are inherited from, allow comes from children, disallow given to children
-- @field base_afk_time a relative number that the rank should be given that other modules can use for relitive importance
-- @field time the time that is requied for this rank to be given, can be nil for manal only
-- @field allow a list of permissions that this rank is allowed
-- @field disallow a list of acctions that is blocked by the ingame permission system
-- @field is_default will be given to all players if no other rank is set for them
-- @field is_admin will promote player to ingame admin if flag set (will auto demote if not set)
-- @field is_spectator will auto set the spectator option for the player (will cleat option if not set)
-- @field is_root rank is always allowed all action, when present in root group will become the root child that all ranks are indexed from
Ranking._rank = {}
--- Is this rank allowed to open this gui or use this command etc. --- Is this rank allowed to open this gui or use this command etc.
-- @usage rank:allowed('server-interface') -- @usage rank:allowed('interface') -- does the rank have permision for 'interface'
-- @tparam teh action to test for -- @tparam teh action to test for
-- @treturn bolean is it allowed -- @treturn boolean is it allowed
function Ranking._rank:allowed(action) function Ranking._rank:allowed(action)
return self.allow[action] or self.is_root or false return self.allow[action] or self.is_root or false
end end
--- Get all the players in this rank --- Get all the players in this rank
-- @usage rank:get_players() -- @usage rank:get_players()
-- @tparam bolean online get only online players -- @tparam[opt=false] boolean online get only online players
-- @treturn table a table of all players in this rank -- @treturn table a table of all players in this rank
function Ranking._rank:get_players(online) function Ranking._rank:get_players(online)
local players = game.permissions.get_group(self.name).players local players = game.permissions.get_group(self.name).players
local _return = {} local _return = {}
if online then if online then
for _,player in pairs(players) do for _,player in pairs(players) do if player.connected then table.insert(_return,player) end end
if player.connected then table.insert(_return,player) end else _return = players end
end
else
_return = players
end
return _return return _return
end end
--- Print a message to all players of this rank --- Print a message to all players of this rank
-- @usage rank:print('foo') -- @usage rank:print('foo') -- prints to all members of this rank
-- @param rtn any value you want to return -- @param rtn any value you want to return
-- @tparam define.color colour the colour that will be used to print -- @tparam[opt=defines.color.white] define.color colour the colour that will be used to print
-- @tparam boolean show_default weather to use the default rank name for the print -- @tparam[opt=false] boolean show_default weather to use the default rank name for the print, used as a pass though
function Ranking._rank:print(rtn,colour,show_default) function Ranking._rank:print(rtn,colour,show_default)
local colour = colour or defines.color.white local colour = colour or defines.color.white
local meta_data = Ranking._presets().meta local default = Ranking.get_rank(Ranking.meta.default)
local default = Ranking.get_rank(meta_data.default)
if not Server or not Server._thread then
for _,player in pairs(self:get_players(true)) do for _,player in pairs(self:get_players(true)) do
if self.name == default.name or show_default then if self.name == default.name or show_default then player_return({'ranking.all-rank-print',rtn},colour,player)
player_return({'ranking.all-rank-print',rtn},colour,player) else player_return({'ranking.rank-print',self.name,rtn},colour,player) end
else
player_return({'ranking.rank-print',self.name,rtn},colour,player)
end
end
else
-- using threads to make less lag
Server.new_thread{
data={rank=self,rtn=rtn,default=default.name,all=show_default}
}:on_event('resolve',function(thread)
return thread.data.rank:get_players(true)
end):on_event('success',function(thread,players)
for _,player in pairs(players) do
if thread.data.rank.name == thread.data.default or thread.data.all then
player_return({'ranking.all-rank-print',thread.data.rtn},colour,player)
else
player_return({'ranking.rank-print',thread.data.rank.name,thread.data.rtn},colour,player)
end
end
end):queue()
end 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 --- Allows for a clean way to edit rank objects
-- see Addons/playerRanks for examples -- @usage rank:edit('allow',{'interface'}) -- allows this rank to use 'interface'
function Ranking._rank:edit(key,set_value,value) -- @tparam string key the key to edit, often allow or disallow
-- @param value the new value to be set
function Ranking._rank:edit(key,value)
if game then return end if game then return end
verbose('Edited Rank: '..self.name..'/'..key) verbose('Edited Rank: '..self.group..'/'..self.name..'/'..key)
if set_value then self[key] = value return end if key == 'disallow' then self.disallow = table.merge(self.disallow,value,true)
if key == 'disallow' then elseif key == 'allow' then self.allow = table.merge(self.allow,value)
self.disallow = table.merge(self.disallow,value,true) else self[key] = value end
elseif key == 'allow' then
self.allow = table.merge(self.allow,value)
end
Ranking._update_rank(self)
end end
-- this is the base group object, do not store in global, these cant be used in game --- The class for the rank groups, the way to allow modules to idex a group that is always present, ranks will always look to there group as a parent
-- @type Group
-- @alias Ranking._group
-- @field name the name that is given to the rank group, must be unique
-- @field parent the name of the group that permissions are inherited from
-- @field allow a list of permissions that this rank is allowed
-- @field disallow a list of acctions that is blocked by the ingame permission system
Ranking._group = {}
-- this makes a new group --- Creates a new group
-- {name='root',allow={},disallow={}} -- @usage Ranking._group:create{name='root'} -- returns group with name root
-- @tparam table obj the fields for this object
-- @treturn Ranking._group returns the object to allow chaining
function Ranking._group:create(obj) function Ranking._group:create(obj)
if game then return end if game then return end
if not is_type(obj.name,'string') then return end if not is_type(obj.name,'string') then error('Group creationg is invalid',2) end
verbose('Created Group: '..obj.name) verbose('Created Group: '..obj.name)
setmetatable(obj,{__index=Ranking._group}) setmetatable(obj,{__index=Ranking._group})
self.index = #Ranking._groups(names)+1
obj.ranks = {} obj.ranks = {}
obj.allow = obj.allow or {} obj.allow = obj.allow or {}
obj.disallow = obj.disallow or {} obj.disallow = obj.disallow or {}
Ranking._add_group(obj) Ranking.groups[obj.name] = obj
return obj return obj
end end
-- this makes a new rank in side this group --- Creats a new rank with this group as its group
-- {name='Root',short_hand='Root',tag='[Root]',time=nil,colour=defines.colors.white,allow={},disallow={}} -- @usage group:add_rank{name='root'} -- returns self
-- if the rank is given power then it is given that place realative to the highest rank in that group,if no power then it is added to the end -- @tparam table obj the fields for this object
-- @treturn Ranking._group returns the object to allow chaining
function Ranking._group:add_rank(obj) function Ranking._group:add_rank(obj)
if game then return end if game then return end
if not is_type(obj.name,'string') or if not is_type(obj.name,'string') or
not is_type(obj.short_hand,'string') or not is_type(obj.short_hand,'string') or
not is_type(obj.tag,'string') or not is_type(obj.tag,'string') or
not is_type(obj.colour,'table') then return end not is_type(obj.colour,'table') then error('Rank creation is invalid',2) end
verbose('Created Rank: '..obj.name) verbose('Created Rank: '..obj.name)
setmetatable(obj,{__index=Ranking._rank}) setmetatable(obj,{__index=Ranking._rank})
obj.group = self obj.group = self.name
obj.children = {}
obj.allow = obj.allow or {} obj.allow = obj.allow or {}
obj.disallow = obj.disallow or {} obj.disallow = obj.disallow or {}
obj.power = obj.power and self.highest and self.highest.power+obj.power or obj.power or self.lowest and self.lowest.power+1 or nil table.insert(self.ranks,obj.name)
setmetatable(obj.allow,{__index=self.allow}) Ranking.ranks[obj.name] = obj
setmetatable(obj.disallow,{__index=self.disallow}) return self
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 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 --- Allows for a clean way to edit rank group objects
-- see Addons/playerRanks for examples -- @usage group:edit('allow',{'interface'}) -- allows this rank to use 'interface'
function Ranking._group:edit(key,set_value,value) -- @tparam string key the key to edit, often allow or disallow
-- @param value the new value to be set
function Ranking._group:edit(key,value)
if game then return end if game then return end
verbose('Edited Group: '..self.name..'/'..key) verbose('Edited Group: '..self.name..'/'..key)
if set_value then self[key] = value return end if key == 'disallow' then self.disallow = table.merge(self.disallow,value,true)
if key == 'disallow' then elseif key == 'allow' then self.allow = table.merge(self.allow,value)
self.disallow = table.merge(self.disallow,value,true) else self[key] = value end
elseif key == 'allow' then
self.allow = table.merge(self.allow,value)
end
Ranking._update_group(self)
end end
Event.register(defines.events.on_player_joined_game,function(event) script.on_event('on_player_joined_game',function(event)
Ranking.find_preset(event.player_index) Ranking.find_preset(event.player_index)
end) end)
Event.register(-1,function(event) script.on_event('on_init',function(event)
for power,rank in pairs(Ranking._ranks()) do for name,rank in pairs(Ranking.ranks) do
local perm = game.permissions.create_group(rank.name) local perm = game.permissions.create_group(name)
for _,toRemove in pairs(rank.disallow) do for _,toRemove in pairs(rank.disallow) do
perm.set_allows_action(defines.input_action[toRemove],false) perm.set_allows_action(defines.input_action[toRemove],false)
end end
end end
end) end)
Event.register(defines.events.on_tick,function(event) script.on_event('on_tick',function(event)
if (((event.tick+10)/(3600*game.speed))+(15/2))% 15 == 0 then if (((event.tick+10)/(3600*game.speed))+(15/2))% 15 == 0 then
-- this is the system to auto rank players -- this is the system to auto rank players
if not Server or not Server._thread then
for _,player in pairs(game.connected_players) do for _,player in pairs(game.connected_players) do
Ranking.find_preset(player,tick) Ranking.find_preset(player,tick)
end end
else
Server.new_thread{
data={players=game.connected_players}
}:on_event('tick',function(thread)
if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1)
Ranking.find_preset(player,tick)
end):open()
end
end end
end) end)
Ranking.on_init=function(self) Ranking.on_init=function(self)
require(module_path.."/base_ranks") if loaded_modules.Server then require(module_path..'/src/server') end
require(module_path.."/config_ranks") require(module_path..'/src/core')
require(module_path..'/src/config')
-- sets up the power system, the lower the power the closer to root, root is 0
-- there must be a rank with is_root flag set and one rank with is_default flag set, if multiple found then first found is used
local root = Ranking.get_rank(Ranking.meta.root)
root:edit('power',0)
-- asigning of children
verbose('Creating Rank Tree')
for name,rank in pairs(Ranking.ranks) do
if rank ~= root then
if not rank.parent then error('Rank has no parent: "'..name..'"') end
if not Ranking.ranks[rank.parent] then error('Invalid parent rank: "'..rank.parent..'"') end
table.insert(Ranking.ranks[rank.parent].children,name)
Ranking.ranks[rank.parent]:edit('allow',rank.allow)
rank:edit('disallow',Ranking.ranks[rank.parent].disallow)
end
end
-- asigning of powers
verbose('Assigning Rank Powers')
local power = 1
local function set_powers(rank)
for _,name in pairs(rank.children) do
Ranking.ranks[name]:edit('power',power)
power=power+1
end
for _,name in pairs(rank.children) do set_powers(Ranking.ranks[name]) end
end
set_powers(root)
-- asigning group meta data
verbose('Creating Rank-Group Relationship')
for name,group in pairs(Ranking.groups) do
if name ~= 'Root' then
if not group.parent then error('Group has no parent: "'..name..'"') end
if not Ranking.groups[group.parent] then error('Invalid parent rank: "'..group.parent..'"') end
Ranking.groups[group.parent]:edit('allow',group.allow)
group:edit('disallow',Ranking.groups[group.parent].disallow)
end
for _,name in pairs(group.ranks) do
local rank = Ranking.ranks[name]
rank:edit('disallow',group.disallow)
rank:edit('allow',group.allow)
if not group.highest or Ranking.ranks[group.highest].power > rank.power then group.highest = rank.name end
if not group.lowest or Ranking.ranks[group.highest].power < rank.power then group.lowest = rank.name end
end
end
end end
return Ranking return Ranking

View File

@@ -1,12 +1,8 @@
--[[ --- Description - A small description that will be displayed on the doc
Explosive Gaming -- @submodule ExpGamingCore.Ranking
-- @alias Ranking
This file can be used with permission but this and the credit below must remain in the file. -- @author Cooldude2606
Contact a member of management on our discord to seek permission to use our code. -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
--[[ --[[
How to use groups: How to use groups:
@@ -34,18 +30,14 @@ 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
--]] --]]
-- See ExpCore/ranks.lua for examples - you add your own and edit pre-made ones here. local groups = Ranking.groups
local ranks = Ranking.ranks
local groups = Ranking._groups(true)
groups['Root']:edit('allow',false,{
['testing']=true
})
groups['Root']:add_rank{ groups['Root']:add_rank{
name='Owner', name='Owner',
short_hand='Owner', short_hand='Owner',
tag='[Owner]', tag='[Owner]',
parent='Root',
time=nil, time=nil,
colour={r=170,g=0,b=0}, colour={r=170,g=0,b=0},
is_admin = true, is_admin = true,
@@ -56,6 +48,7 @@ groups['Root']:add_rank{
name='Community Manager', name='Community Manager',
short_hand='Com Mngr', short_hand='Com Mngr',
tag='[Com Mngr]', tag='[Com Mngr]',
parent='Root',
colour={r=150,g=68,b=161}, colour={r=150,g=68,b=161},
is_admin = true, is_admin = true,
is_spectator=true, is_spectator=true,
@@ -65,16 +58,19 @@ groups['Root']:add_rank{
name='Developer', name='Developer',
short_hand='Dev', short_hand='Dev',
tag='[Dev]', tag='[Dev]',
parent='Root',
colour={r=179,g=125,b=46}, colour={r=179,g=125,b=46},
is_admin = true, is_admin = true,
is_spectator=true, is_spectator=true,
base_afk_time=false base_afk_time=false
} }
ranks['Admin']:edit('parent','Developer')
groups['Admin']:add_rank{ groups['Admin']:add_rank{
name='Mod', name='Mod',
short_hand='Mod', short_hand='Mod',
tag='[Mod]', tag='[Mod]',
parent='Admin',
colour={r=0,g=170,b=0}, colour={r=0,g=170,b=0},
disallow={ disallow={
'server_command' 'server_command'
@@ -88,8 +84,8 @@ groups['User']:add_rank{
name='Donator', name='Donator',
short_hand='P2W', short_hand='P2W',
tag='[P2W]', tag='[P2W]',
parent='Mod',
colour={r=233,g=63,b=233}, colour={r=233,g=63,b=233},
power=0,
is_spectator=true, is_spectator=true,
base_afk_time=120 base_afk_time=120
} }
@@ -97,24 +93,22 @@ groups['User']:add_rank{
name='Veteran', name='Veteran',
short_hand='Vet', short_hand='Vet',
tag='[Veteran]', tag='[Veteran]',
parent='Donator',
time=600, time=600,
colour={r=140,g=120,b=200}, colour={r=140,g=120,b=200},
power=1,
base_afk_time=60 base_afk_time=60
} }
ranks['Member']:edit('parent','Veteran')
groups['User']:add_rank{ groups['User']:add_rank{
name='Regular', name='Regular',
short_hand='Reg', short_hand='Reg',
tag='[Regular]', tag='[Regular]',
parent='Member',
time=180, time=180,
colour={r=24,g=172,b=188}, colour={r=24,g=172,b=188},
power=3,
base_afk_time=30 base_afk_time=30
} }
ranks['Guest']:edit('parent','Regular')
local ranks = Ranking._ranks(true)
ranks['Root']:edit('test',true,'testing')
Ranking._base_preset{ Ranking._base_preset{
['badgamernl']='Owner', ['badgamernl']='Owner',

View File

@@ -1,20 +1,8 @@
--[[ --- Description - A small description that will be displayed on the doc
Explosive Gaming -- @submodule ExpGamingCore.Ranking
-- @alias Ranking
This file can be used with permission but this and the credit below must remain in the file. -- @author Cooldude2606
Contact a member of management on our discord to seek permission to use our code. -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local groups = {}
local ranks = {}
function Ranking._add_group(group) if game then return end table.insert(groups,group) 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: How to use groups:
@@ -42,11 +30,10 @@ 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
--]] --]]
-- If you wish to add more groups please use addons/playerRanks.lua -- If you wish to add more groups please use src/config or add during your own module
-- If you wish to add to these rank groups use addons/playerRanks.lua -- If you wish to add to these rank groups use src/config or add during your own module
-- Ranks will inherite from each other ie higher ranks can do everything lower ranks can
-- But groups do not inherite from each other -- But groups do not inherite from each other
-- DO NOT REMOVE ANY OF THESE GROUPS -- DO NOT REMOVE ANY OF THESE GROUPS!!!
local root = Ranking._group:create{ local root = Ranking._group:create{
name='Root', name='Root',
@@ -57,9 +44,9 @@ local root = Ranking._group:create{
} }
local admin = Ranking._group:create{ local admin = Ranking._group:create{
name='Admin', name='Admin',
parent='Root',
allow={}, allow={},
disallow={ disallow={
'set_allow_commands',
'edit_permission_group', 'edit_permission_group',
'delete_permission_group', 'delete_permission_group',
'add_permission_group' 'add_permission_group'
@@ -67,22 +54,15 @@ local admin = Ranking._group:create{
} }
local user = Ranking._group:create{ local user = Ranking._group:create{
name='User', name='User',
parent='Admin',
allow={}, allow={},
disallow={ disallow={}
'set_allow_commands',
'edit_permission_group',
'delete_permission_group',
'add_permission_group'
}
} }
local jail = Ranking._group:create{ local jail = Ranking._group:create{
name='Jail', name='Jail',
parent='User',
allow={}, allow={},
disallow={ disallow={
'set_allow_commands',
'edit_permission_group',
'delete_permission_group',
'add_permission_group',
'open_character_gui', 'open_character_gui',
'begin_mining', 'begin_mining',
'start_walking', 'start_walking',
@@ -110,8 +90,8 @@ local jail = Ranking._group:create{
} }
} }
-- If you wish to add more ranks please use addons/playerRanks.lua -- If you wish to add more ranks please use src/config or add during your own module
-- If you wish to add to these rank use addons/playerRanks.lua -- If you wish to add to these rank use src/config or add during your own module
root:add_rank{ root:add_rank{
name='Root', name='Root',
short_hand='Root', short_hand='Root',
@@ -127,6 +107,7 @@ admin:add_rank{
name='Admin', name='Admin',
short_hand='Admin', short_hand='Admin',
tag='[Admin]', tag='[Admin]',
parent='Root',
colour={r=233,g=63,b=233}, colour={r=233,g=63,b=233},
is_admin=true, is_admin=true,
is_spectator=true, is_spectator=true,
@@ -137,6 +118,7 @@ user:add_rank{
name='Member', name='Member',
short_hand='Mem', short_hand='Mem',
tag='[Member]', tag='[Member]',
parent='Admin',
colour={r=24,g=172,b=188}, colour={r=24,g=172,b=188},
disallow={ disallow={
'set_auto_launch_rocket', 'set_auto_launch_rocket',
@@ -149,6 +131,7 @@ user:add_rank{
name='Guest', name='Guest',
short_hand='', short_hand='',
tag='', tag='',
parent='Member',
colour={r=255,g=159,b=27}, colour={r=255,g=159,b=27},
is_default=true, is_default=true,
disallow={ disallow={
@@ -165,66 +148,8 @@ jail:add_rank{
name='Jail', name='Jail',
short_hand='Jail', short_hand='Jail',
tag='[Jail]', tag='[Jail]',
parent='Guest',
colour={r=50,g=50,b=50}, colour={r=50,g=50,b=50},
disallow={}, disallow={},
base_afk_time=false base_afk_time=false
} }
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
local rank = ranks[power]
rank:edit('disallow',false,rank.group.disallow)
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
if name then
local _return = {}
for power,group in pairs(groups) do
_return[group.name] = group
end
return _return
end
end
return groups
end
function Ranking._ranks(name)
if name then
local _return = {}
for power,rank in pairs(ranks) do
_return[rank.name] = rank
end
return _return
end
return ranks
end
-- used to save lag by doing some calculation at the start
function Ranking._meta()
local meta = {time_ranks={}}
for power,rank in pairs(ranks) do
meta.rank_count = power
if rank.is_default then
meta.default = rank.name
end
if rank.is_root then
meta.root = rank.name
end
if rank.time then
table.insert(meta.time_ranks,rank.name)
if not meta.time_highest or power < meta.time_highest then meta.time_highest = power end
if not meta.time_lowest or rank.time < meta.time_lowest then meta.time_lowest = rank.time end
end
end
return meta
end

View File

@@ -0,0 +1,43 @@
--- Description - A small description that will be displayed on the doc
-- @submodule ExpGamingCore.Ranking
-- @alias Ranking
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
--- This file will be loaded when ExpGamingCore.Server is present
-- @function _comment
--- Print a message to all players of this rank
-- @usage rank:print('foo') -- prints to all members of this rank
-- @param rtn any value you want to return
-- @tparam[opt=defines.color.white] define.color colour the colour that will be used to print
-- @tparam[opt=false] boolean show_default weather to use the default rank name for the print, used as a pass though
function Ranking._rank:print(rtn,colour,show_default)
local colour = colour or defines.color.white
local default = Ranking.get_rank(Ranking.meta.default)
Server.new_thread{
data={rank=self,rtn=rtn,default=default.name,all=show_default}
}:on_event('resolve',function(thread)
return thread.data.rank:get_players(true)
end):on_event('success',function(thread,players)
for _,player in pairs(players) do
if thread.data.rank.name == thread.data.default or thread.data.all then
player_return({'ranking.all-rank-print',thread.data.rtn},colour,player)
else
player_return({'ranking.rank-print',thread.data.rank.name,thread.data.rtn},colour,player)
end
end
end):queue()
end
script.on_event('on_tick',function(event)
if (((event.tick+10)/(3600*game.speed))+(15/2))% 15 == 0 then
Server.new_thread{
data={players=game.connected_players}
}:on_event('tick',function(thread)
if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1)
Ranking.find_preset(player,tick)
end):open()
end
end)

View File

@@ -5,6 +5,7 @@
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
local Server = {} local Server = {}
local module_verbose = false --true|false
--- Global Table --- Global Table
-- @table global -- @table global
@@ -45,6 +46,7 @@ end)
-- @treturn[1] number the number of threads -- @treturn[1] number the number of threads
-- @treturn[2] table table of all threads -- @treturn[2] table table of all threads
Server.threads = setmetatable({},{ Server.threads = setmetatable({},{
__metatable=false,
__call=function(tbl) return global.all._n end, __call=function(tbl) return global.all._n end,
__index=function(tbl,key) return rawget(global.all,key) end, __index=function(tbl,key) return rawget(global.all,key) end,
__newindex=function(tbl,key,value) rawset(global.all,key,value) end, __newindex=function(tbl,key,value) rawset(global.all,key,value) end,
@@ -231,6 +233,10 @@ end
--- The class for the server threads, allows abbilty to run async function --- The class for the server threads, allows abbilty to run async function
-- @type Thread -- @type Thread
-- @alias Server._thread -- @alias Server._thread
-- @field name the name that is given to the thread, use for easy later indexing
-- @field timeout the time in ticks that the thread will have before it times out
-- @field reopen when true the thread will reopen itself untill set to false, combine with timeout to create a long on_nth_tick wait
-- @field data any data that the thread will beable to access
Server._thread = {} Server._thread = {}
--- Returns a new thread object --- Returns a new thread object

View File

@@ -6,6 +6,7 @@
local Sync = {} local Sync = {}
local Sync_updates = {} local Sync_updates = {}
local module_verbose = false --true|false
--- Global Table --- Global Table
-- @table global -- @table global

View File

@@ -18,9 +18,8 @@ end
-- @treturn table contains the ranks and the players in that rank -- @treturn table contains the ranks and the players in that rank
function Sync.count_ranks() function Sync.count_ranks()
if not game then return {'Offline'} end if not game then return {'Offline'} end
if not Ranking then return {'Ranking module not installed'} end
local _ranks = {} local _ranks = {}
for power,rank in pairs(Ranking._ranks()) do for name,rank in pairs(Ranking.ranks) do
local players = rank:get_players() local players = rank:get_players()
for k,player in pairs(players) do players[k] = player.name end for k,player in pairs(players) do players[k] = player.name end
local online = rank:get_players(true) local online = rank:get_players(true)
@@ -36,3 +35,21 @@ if Sync.add_to_gui then
return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\'' return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\''
end) end)
end end
-- adds a discord emit for rank chaning
script.on_event('rank_change',function(event)
local rank = Ranking.get_rank(event.new_rank)
local player = Game.get_player(event)
local by_player_name = Game.get_player(event.by_player_index) or '<server>'
local global = global('Ranking')
if rank.group.name == 'Jail' and global.last_change ~= player.name then
Sync.emit_embeded{
title='Player Jail',
color=Color.to_hex(defines.textcolor.med),
description='There was a player jailed.',
['Player:']='<<inline>>'..player.name,
['By:']='<<inline>>'..by_player_name,
['Reason:']='No Reason'
}
end
end)

View File

@@ -40,7 +40,10 @@
"version": "3.4.0", "version": "3.4.0",
"location": "url", "location": "url",
"dependencies": { "dependencies": {
"ExpGamingLib": ">=3.0.0" "ExpGamingLib": ">=3.0.0",
"FactorioStdLib.Color": ">=0.8.0",
"FactorioStdLib.Table": ">=0.8.0",
"ExpGamingCore.Server": "?>=3.0.0"
} }
}, },
"Server": { "Server": {
@@ -53,8 +56,8 @@
"dependencies": { "dependencies": {
"ExpGamingLib": ">=3.0.0", "ExpGamingLib": ">=3.0.0",
"FactorioStdLib.Table": ">=0.8.0", "FactorioStdLib.Table": ">=0.8.0",
"ExpGamingCore/Ranking": "?>=3.0.0", "ExpGamingCore.Ranking": "?>=3.0.0",
"ExpGamingCore/Commands": "?>=3.0.0" "ExpGamingCore.Commands": "?>=3.0.0"
} }
}, },
"Sync": { "Sync": {

View File

@@ -72,7 +72,7 @@ end
-- @tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ingroned when printing to console -- @tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ingroned when printing to console
-- @tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server -- @tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server
function ExpLib.player_return(rtn,colour,player) function ExpLib.player_return(rtn,colour,player)
local colour = ExpLib.is_type(colour) == 'table' and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] local colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour]
local player = player or game.player local player = player or game.player
local function _return(callback,rtn) local function _return(callback,rtn)
if ExpLib.is_type(rtn,'table') then if ExpLib.is_type(rtn,'table') then

View File

@@ -9,7 +9,7 @@ return {
['Color']='/modules/FactorioStdLib/Color', ['Color']='/modules/FactorioStdLib/Color',
['table']='/modules/FactorioStdLib/Table', ['table']='/modules/FactorioStdLib/Table',
['string']='/modules/FactorioStdLib/String', ['string']='/modules/FactorioStdLib/String',
--['Ranking']='/modules/ExpGamingCore/Ranking', ['Ranking']='/modules/ExpGamingCore/Ranking',
--['commands']='/modules/ExpGamingCore/Commands', --['commands']='/modules/ExpGamingCore/Commands',
--['Gui']='/modules/ExpGamingCore/Gui', --['Gui']='/modules/ExpGamingCore/Gui',
['Server']='/modules/ExpGamingCore/Server', ['Server']='/modules/ExpGamingCore/Server',