mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-28 03:55:23 +09:00
Converted Modules To Use Roles
This commit is contained in:
@@ -4,55 +4,55 @@
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
--- This file will be loaded when ExpGamingCore.Ranking is present
|
||||
--- This file will be loaded when ExpGamingCore.Role is present
|
||||
-- @function _comment
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Color = require('FactorioStdLib.Color')
|
||||
local Ranking = require('ExpGamingCore.Ranking')
|
||||
local Role = require('ExpGamingCore.Role')
|
||||
|
||||
--- Used as a redirect to Ranking._base_preset that will set the rank given to a player apon joining
|
||||
-- @usage Sync.set_ranks{player_name=rank_name,...}
|
||||
function Sync.set_ranks(...)
|
||||
Ranking._base_preset(...)
|
||||
--- Used as a redirect to Role._base_preset that will set the rank given to a player apon joining
|
||||
-- @usage Sync.set_roles{player_name=rank_name,...}
|
||||
function Sync.set_roles(...)
|
||||
Role._base_preset(...)
|
||||
end
|
||||
|
||||
--- Used to get the number of players in each rank and currently online
|
||||
-- @usage Sync.count_ranks()
|
||||
-- @usage Sync.count_roles()
|
||||
-- @treturn table contains the ranks and the players in that rank
|
||||
function Sync.count_ranks()
|
||||
function Sync.count_roles()
|
||||
if not game then return {'Offline'} end
|
||||
local _ranks = {}
|
||||
for name,rank in pairs(Ranking.ranks) do
|
||||
local players = rank:get_players()
|
||||
local _roles = {}
|
||||
for name,role in pairs(Role.roles) do
|
||||
local players = role:get_players()
|
||||
for k,player in pairs(players) do players[k] = player.name end
|
||||
local online = rank:get_players(true)
|
||||
local online = role:get_players(true)
|
||||
for k,player in pairs(online) do online[k] = player.name end
|
||||
_ranks[rank.name] = {players=players,online=online,n_players=#players,n_online=#online}
|
||||
_roles[role.name] = {players=players,online=online,n_players=#players,n_online=#online}
|
||||
end
|
||||
return _ranks
|
||||
return _roles
|
||||
end
|
||||
|
||||
-- Adds a caption to the info gui that shows the rank given to the player
|
||||
if Sync.add_to_gui then
|
||||
Sync.add_to_gui(function(player,frame)
|
||||
return 'You have been assigned the rank \''..Ranking.get_rank(player).name..'\''
|
||||
return 'You have been assigned the rank \''..Role.get_highest(player).name..'\''
|
||||
end)
|
||||
end
|
||||
|
||||
-- adds a discord emit for rank chaning
|
||||
script.on_event('on_rank_change',function(event)
|
||||
local rank = Ranking.get_rank(event.new_rank)
|
||||
script.on_event('on_role_change',function(event)
|
||||
local role = Role.get(event.role_name)
|
||||
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
|
||||
local by_player = Game.get_player(event.by_player_index) or SERVER
|
||||
local global = global['ExpGamingCore.Role^4.0.0']
|
||||
if role.is_jail == 'Jail' and global.last_change[1] ~= player.index 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,
|
||||
['By:']='<<inline>>'..by_player.name,
|
||||
['Reason:']='No Reason'
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user