mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-28 12:05:21 +09:00
Better Sync Functions
This commit is contained in:
@@ -177,12 +177,12 @@ function Sync.count_afk_times(time)
|
||||
return rtn
|
||||
end
|
||||
|
||||
--- Used to get the number of players in each rank and currently online; if ExpGamingCore/Role is present then it will give more than admin and user
|
||||
--- Used to get the number of players in each rank and currently online
|
||||
-- @usage Sync.count_roles()
|
||||
-- @treturn table contains the ranks and the players in that rank
|
||||
function Sync.count_roles()
|
||||
if not game then return {'Offline'} end
|
||||
local _roles = {admin={online={},players={}},user={online={},players={}}}
|
||||
local _rtn = {admin={online={},players={}},user={online={},players={}}}
|
||||
for index,player in pairs(game.players) do
|
||||
if player.admin then
|
||||
table.insert(_roles.admin.players,player.name)
|
||||
@@ -192,9 +192,9 @@ function Sync.count_roles()
|
||||
if player.connected then table.insert(_roles.user.online,player.name) end
|
||||
end
|
||||
end
|
||||
_roles.admin.n_players,_roles.admin.n_online=#_roles.admin.players,#_roles.admin.online
|
||||
_roles.user.n_players,_roles.user.n_online=#_roles.user.players,#_roles.user.online
|
||||
return _roles
|
||||
_rtn.admin.n_players,_roles.admin.n_online=#_rtn.admin.players,#_rtn.admin.online
|
||||
_rtn.user.n_players,_roles.user.n_online=#_rtn.user.players,#_rtn.user.online
|
||||
return _rtn
|
||||
end
|
||||
|
||||
--- Used to get a list of every player name with the option to limit to only online players
|
||||
@@ -310,7 +310,6 @@ script.on_event('on_rocket_launched',Sync.emit_update)
|
||||
|
||||
function Sync:on_init()
|
||||
if loaded_modules['ExpGamingCore.Gui@^4.0.0'] then verbose('ExpGamingCore.Gui is installed; Loading gui src') require(module_path..'/src/gui',{Sync=Sync,module_path=module_path}) end
|
||||
if loaded_modules['ExpGamingCore.Role@^4.0.0'] then verbose('ExpGamingCore.Role is installed; Loading role src') require(module_path..'/src/ranking',{Sync=Sync}) end
|
||||
if loaded_modules['ExpGamingCore.Server@^4.0.0'] then require('ExpGamingCore.Server@^4.0.0').add_module_to_interface('Sync','ExpGamingCore.Sync') end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
--- Allows syncing with an outside server and info panle.
|
||||
-- @submodule ExpGamingCore.Sync
|
||||
-- @alias Sync
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
--- This file will be loaded when ExpGamingCore.Role is present
|
||||
-- @function _comment
|
||||
|
||||
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||
local Color = require('FactorioStdLib.Color@^0.8.0')
|
||||
local Role = require('ExpGamingCore.Role@^4.0.0')
|
||||
|
||||
--- 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.set_preassign(...)
|
||||
end
|
||||
|
||||
--- Used to get the number of players in each rank and currently online
|
||||
-- @usage Sync.count_roles()
|
||||
-- @treturn table contains the ranks and the players in that rank
|
||||
function Sync.count_roles()
|
||||
if not game then return {'Offline'} end
|
||||
local _roles = {}
|
||||
for name,role in pairs(Role.roles) do
|
||||
local players = role:get_players()
|
||||
local _players = {}
|
||||
for k,player in pairs(players) do _players[k] = player.name end
|
||||
local online = role:get_players(true)
|
||||
local _online = {}
|
||||
for k,player in pairs(online) do _online[k] = player.name end
|
||||
_roles[role.name] = {players=_players,online=_online,n_players=#_players,n_online=#_online}
|
||||
end
|
||||
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)
|
||||
local names = {}
|
||||
for _,role in pairs(Role.get(player)) do table.insert(names,role.name) end
|
||||
return 'You have been assigned the roles: '..table.concat(names,', ')
|
||||
end)
|
||||
end
|
||||
|
||||
-- adds a discord emit for rank chaning
|
||||
script.on_event('on_role_change',function(event)
|
||||
local role = Role.get(event.role_name)
|
||||
local player = Game.get_player(event)
|
||||
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,
|
||||
['Reason:']='No Reason'
|
||||
}
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user