mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Added ExpGamingPlayer.playerList
This commit is contained in:
39
modules/ExpGamingPlayer/afkKick/afk-kick.lua
Normal file
39
modules/ExpGamingPlayer/afkKick/afk-kick.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
--[[
|
||||
Explosive Gaming
|
||||
|
||||
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-----------------------------------------------------------
|
||||
|
||||
function get_allowed_afk_time(player)
|
||||
local rank = Ranking.get_rank(player)
|
||||
local count = #game.connected_players
|
||||
local base = rank.base_afk_time or false
|
||||
if not base then return false end
|
||||
return (base/5)*count
|
||||
end
|
||||
|
||||
Event.register(-1,function(event)
|
||||
Server.new_thread{
|
||||
name='afk-kick',
|
||||
}:on_event('tick',function(self)
|
||||
if (game.tick%3600) ~= 0 then return end
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
|
||||
if afk then
|
||||
if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end
|
||||
end
|
||||
end
|
||||
end):on_event('error',function(self,err)
|
||||
Sync.emit_embeded{
|
||||
title='Auto Kick Error',
|
||||
color=Color.to_hex(defines.text_color.bg),
|
||||
description='Auto Kick Error - Closed Thread',
|
||||
Error=err
|
||||
}
|
||||
self:close()
|
||||
end):open()
|
||||
end)
|
||||
40
modules/ExpGamingPlayer/playerInfo/player-info.lua
Normal file
40
modules/ExpGamingPlayer/playerInfo/player-info.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
--[[
|
||||
Explosive Gaming
|
||||
|
||||
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-----------------------------------------------------------
|
||||
|
||||
function get_player_info(player,frame,add_cam)
|
||||
local player = Game.get_player(player)
|
||||
if not player then return {} end
|
||||
local _player = {}
|
||||
_player.index = player.index
|
||||
_player.name = player.name
|
||||
_player.online = player.connected
|
||||
_player.tag = player.tag
|
||||
_player.color = player.color
|
||||
_player.admin = player.admin
|
||||
_player.online_time = player.online_time
|
||||
_player.rank = Ranking.get_rank(player).name
|
||||
_player.group = Ranking.get_group(player).name
|
||||
if frame then
|
||||
local frame = frame.add{type='frame',direction='vertical',style='image_frame'}
|
||||
frame.style.width = 200
|
||||
frame.style.height = 275
|
||||
frame.add{type='label',caption={'player-info.name',_player.index,_player.name},style='caption_label'}
|
||||
local _online = {'player-info.no'}; if _player.online then _online = {'player-info.yes'} end
|
||||
frame.add{type='label',caption={'player-info.online',_online,tick_to_display_format(_player.online_time)}}
|
||||
local _admin = {'player-info.no'}; if _player.admin then _admin = {'player-info.yes'} end
|
||||
frame.add{type='label',caption={'player-info.admin',_admin}}
|
||||
frame.add{type='label',caption={'player-info.group',_player.group}}
|
||||
frame.add{type='label',caption={'player-info.rank',_player.rank}}
|
||||
if add_cam then
|
||||
Gui.cam_link{entity=player.character,frame=frame,width=200,height=150,zoom=0.5,respawn_open=true}
|
||||
end
|
||||
end
|
||||
return _player
|
||||
end
|
||||
132
modules/ExpGamingPlayer/playerList/control.lua
Normal file
132
modules/ExpGamingPlayer/playerList/control.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
--- A full ranking system for factorio.
|
||||
-- @module ExpGamingPlayer.playerList
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local Admin -- hanndled on load
|
||||
|
||||
local global = global{
|
||||
update=0,
|
||||
delay=10,
|
||||
intervial=54000
|
||||
}
|
||||
|
||||
-- this will be replaced on load if playerInfo module is present
|
||||
local function playerInfo(player,frame)
|
||||
frame.add{
|
||||
type='label',
|
||||
caption={'player-list.no-info-file'}
|
||||
}
|
||||
end
|
||||
|
||||
local function getPlayers()
|
||||
local rtn = {{{r=233,g=63,b=233},'Admin',{}},{{r=255,g=159,b=27},'',{}}}
|
||||
for _,player in pairs(game.connected_players) do
|
||||
if player.admin then table.insert(rtn[2][3],player)
|
||||
else table.insert(rtn[1][3],player) end
|
||||
end
|
||||
return rtn
|
||||
end
|
||||
|
||||
local function queue_update(tick)
|
||||
local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick
|
||||
if tick + global.delay > global.update - global.intervial then
|
||||
global.update = tick + global.delay
|
||||
end
|
||||
end
|
||||
|
||||
local back_btn = Gui.inputs.add{
|
||||
type='button',
|
||||
caption='utility/enter',
|
||||
name='player-list-back'
|
||||
}:on_event('click',function(event)
|
||||
event.element.parent.parent.scroll.style.visible = true
|
||||
event.element.parent.destroy()
|
||||
end)
|
||||
|
||||
Gui.left.add{
|
||||
name='player-list',
|
||||
caption='entity/player',
|
||||
tooltip={'player-list.tooltip'},
|
||||
draw=function(frame)
|
||||
frame.caption = ''
|
||||
local player_list = frame.add{
|
||||
name='scroll',
|
||||
type = 'scroll-pane',
|
||||
direction = 'vertical',
|
||||
vertical_scroll_policy='auto',
|
||||
horizontal_scroll_policy='never'
|
||||
}
|
||||
player_list.vertical_scroll_policy = 'auto'
|
||||
player_list.style.maximal_height=195
|
||||
local players = getPlayers() -- list of [colour,shortHand,[playerOne,playerTwo]]
|
||||
for _,rank in pairs(players) do
|
||||
for _,player in pairs(rank[3]) do
|
||||
local flow = player_list.add{type='flow'}
|
||||
if rank[2] == '' then
|
||||
flow.add{
|
||||
type='label',
|
||||
name=player.name,
|
||||
style='caption_label',
|
||||
caption={'player-list.format-nil',tick_to_display_format(player.online_time),player.name}
|
||||
}.style.font_color = rank[1]
|
||||
else
|
||||
flow.add{
|
||||
type='label',
|
||||
name=player.name,
|
||||
style='caption_label',
|
||||
caption={'player-list.format',tick_to_display_format(player.online_time),player.name,rank[2]}
|
||||
}.style.font_color = rank[1]
|
||||
end
|
||||
if Admin.report_btn then
|
||||
if not rank:allowed('no-report') and player.index ~= frame.player_index then
|
||||
local btn = Admin.report_btn:draw(flow)
|
||||
btn.style.height = 20
|
||||
btn.style.width = 20
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
open_on_join=true
|
||||
}
|
||||
|
||||
script.on_event(defines.events.on_tick,function(event)
|
||||
if event.tick > global.update then
|
||||
Gui.left.update('player-list')
|
||||
global.update = event.tick + global.intervial
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_gui_click,function(event)
|
||||
-- lots of checks for it being valid
|
||||
if event.element and event.element.valid
|
||||
and event.element.parent and event.element.parent.parent and event.element.parent.parent.parent
|
||||
and event.element.parent.parent.parent.name == 'player-list' then else return end
|
||||
-- must be a right click
|
||||
if event.button == defines.mouse_button_type.right then else return end
|
||||
local player_list = event.element.parent.parent.parent
|
||||
-- hides the player list to show the info
|
||||
player_list.scroll.style.visible = false
|
||||
local flow = player_list.add{type='flow',direction='vertical'}
|
||||
back_btn:draw(flow)
|
||||
playerInfo(event.element.name,flow,true)
|
||||
if Game.get_player(event.element.name) and event.player_index == Game.get_player(event.element.name).index then return end
|
||||
if Admin and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_player_joined_game,queue_update)
|
||||
script.on_event(defines.events.on_player_left_game,queue_update)
|
||||
script.on_event(defines.events.rank_change,queue_update)
|
||||
|
||||
function commands:on_init()
|
||||
if loaded_modules['ExpGamingPlayer.playerInfo'] then playerInfo = require('ExpGamingPlayer.playerInfo') end
|
||||
if loaded_modules['ExpGamingAdmin'] then Admin = require('ExpGamingAdmin') end
|
||||
end
|
||||
|
||||
return {
|
||||
force_update=function() return Gui.left.update('player-list') end,
|
||||
update=queue_update
|
||||
}
|
||||
23
modules/ExpGamingPlayer/playerList/softmod.json
Normal file
23
modules/ExpGamingPlayer/playerList/softmod.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "playerList",
|
||||
"version": "4.0.0",
|
||||
"type": "Module",
|
||||
"description": "Used to display player names and online time on the top left.",
|
||||
"location": "<blank>",
|
||||
"keywords": [
|
||||
"Player List",
|
||||
"List",
|
||||
"Gui",
|
||||
"Names"
|
||||
],
|
||||
"author": "<blank>",
|
||||
"contact": "<blank>",
|
||||
"license": "<blank>",
|
||||
"dependencies": {
|
||||
"FactorioStdLib.Game": "^0.8.0",
|
||||
"ExpGamingCore.Gui": "^4.0.0",
|
||||
"ExpGamingCore.Ranking": "?^4.0.0",
|
||||
"ExpGamingAdmin.buttonFlow": "?^4.0.0",
|
||||
"ExpGamingAdmin.reports": "?^4.0.0"
|
||||
}
|
||||
}
|
||||
9
modules/ExpGamingPlayer/playerList/src/ranking.lua
Normal file
9
modules/ExpGamingPlayer/playerList/src/ranking.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
local Ranking = require('ExpGamingCore.Ranking')
|
||||
|
||||
return function()
|
||||
local rtn = {}
|
||||
for _,rank in pairs(Ranking.ranks) do
|
||||
table.insert(rtn,{rank.colour,rank.short_hand,rank:get_players(true))
|
||||
end
|
||||
return rtn
|
||||
end
|
||||
17
modules/ExpGamingPlayer/softmod.json
Normal file
17
modules/ExpGamingPlayer/softmod.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "ExpGamingPlayer",
|
||||
"version": "4.0.0",
|
||||
"type": "Collection",
|
||||
"description": "Useful collection of modules for displaying player infomation.",
|
||||
"location": "<blank>",
|
||||
"keywords": [
|
||||
"ExpGaming",
|
||||
"Player",
|
||||
"Information",
|
||||
"AFK"
|
||||
],
|
||||
"author": "Cooldude2606",
|
||||
"contact": "Discord: Cooldude2606#5241",
|
||||
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
||||
"submodules": {}
|
||||
}
|
||||
Reference in New Issue
Block a user