mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Merge pull request #152 from Cooldude2606/feature/server-ups
Added Server UPS
This commit is contained in:
@@ -48,6 +48,7 @@ return {
|
|||||||
'modules.gui.warp-list',
|
'modules.gui.warp-list',
|
||||||
'modules.gui.task-list',
|
'modules.gui.task-list',
|
||||||
'modules.gui.player-list',
|
'modules.gui.player-list',
|
||||||
|
'modules.gui.server-ups',
|
||||||
'modules.commands.debug',
|
'modules.commands.debug',
|
||||||
-- Config Files
|
-- Config Files
|
||||||
'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins
|
'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ local default = Roles.new_role('Guest','')
|
|||||||
'command/find-on-map',
|
'command/find-on-map',
|
||||||
'command/report',
|
'command/report',
|
||||||
'command/ratio',
|
'command/ratio',
|
||||||
|
'command/server-ups',
|
||||||
'gui/player-list',
|
'gui/player-list',
|
||||||
'gui/rocket-info',
|
'gui/rocket-info',
|
||||||
'gui/science-info',
|
'gui/science-info',
|
||||||
|
|||||||
@@ -74,3 +74,5 @@ home-set=Your home point has been set to x: __1__ y: __2__
|
|||||||
return-set=Your return point has been set to x: __1__ y: __2__
|
return-set=Your return point has been set to x: __1__ y: __2__
|
||||||
home-get=Your home point is at x: __1__ y: __2__
|
home-get=Your home point is at x: __1__ y: __2__
|
||||||
|
|
||||||
|
[expcom-server-ups]
|
||||||
|
no-ext=No external source was found, cannot display server ups.
|
||||||
64
modules/gui/server-ups.lua
Normal file
64
modules/gui/server-ups.lua
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
--[[-- Gui Module - Server UPS
|
||||||
|
- Adds a server ups counter in the top right and a command to toggle is
|
||||||
|
@gui server-ups
|
||||||
|
@alias server_ups
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||||
|
local Event = require 'utils.event' --- @dep utils.event
|
||||||
|
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||||
|
|
||||||
|
--- Label to show the server ups
|
||||||
|
-- @element server_ups
|
||||||
|
local server_ups =
|
||||||
|
Gui.element{
|
||||||
|
type = 'label',
|
||||||
|
caption = 'Server UPS = 60.0'
|
||||||
|
}
|
||||||
|
:style{
|
||||||
|
font = 'default-game'
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Toggles if the server ups is visbile
|
||||||
|
-- @command server-ups
|
||||||
|
Commands.new_command('server-ups','Toggle the server ups display')
|
||||||
|
:add_alias('sups','ups')
|
||||||
|
:register(function(player)
|
||||||
|
local label = player.gui.screen[server_ups.name]
|
||||||
|
if not global.ext or not global.ext.server_ups then
|
||||||
|
return Commands.error{'expcom-server-ups.no-ext'}
|
||||||
|
end
|
||||||
|
label.visible = not label.visible
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Set the location of the label
|
||||||
|
-- 1920x1080: x=1455, y=30 (ui scale 100%)
|
||||||
|
local function set_location(event)
|
||||||
|
local player = game.players[event.player_index]
|
||||||
|
local label = player.gui.screen[server_ups.name]
|
||||||
|
local res = player.display_resolution
|
||||||
|
local uis = player.display_scale
|
||||||
|
label.location = { x=res.width-465*uis, y=30*uis }
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Draw the label when the player joins
|
||||||
|
Event.add(defines.events.on_player_created,function(event)
|
||||||
|
local player = game.players[event.player_index]
|
||||||
|
local label = server_ups(player.gui.screen)
|
||||||
|
label.visible = false
|
||||||
|
set_location(event)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Update the caption for all online players
|
||||||
|
Event.on_nth_tick(60,function()
|
||||||
|
if global.ext and global.ext.server_ups then
|
||||||
|
local caption = 'Server UPS = '..global.ext.server_ups
|
||||||
|
for _,player in pairs(game.connected_players) do
|
||||||
|
player.gui.screen[server_ups.name].caption = caption
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Update when res or ui scale changes
|
||||||
|
Event.add(defines.events.on_player_display_resolution_changed,set_location)
|
||||||
|
Event.add(defines.events.on_player_display_scale_changed,set_location)
|
||||||
Reference in New Issue
Block a user