1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/commands/where.lua

90 lines
2.2 KiB
Lua
Raw Normal View History

2020-07-30 19:09:18 +02:00
-- simply use /where ::LuaPlayerName to locate them
local Color = require 'utils.color_presets'
local Event = require 'utils.event'
2020-10-21 17:10:13 +02:00
local Public = {}
2020-07-30 19:09:18 +02:00
local function validate_player(player)
if not player then
return false
end
if not player.valid then
return false
end
if not player.character then
return false
end
if not player.connected then
return false
end
if not game.players[player.index] then
return false
end
return true
end
local function create_mini_camera_gui(player, caption, position, surface)
if player.gui.center['where_camera'] then
player.gui.center['where_camera'].destroy()
end
local frame = player.gui.center.add({type = 'frame', name = 'where_camera', caption = caption})
surface = tonumber(surface)
local camera =
frame.add(
{
type = 'camera',
name = 'where_camera',
position = position,
zoom = 0.4,
surface_index = surface
}
)
camera.style.minimal_width = 740
camera.style.minimal_height = 580
end
commands.add_command(
'where',
'Locates a player',
function(cmd)
local player = game.player
if validate_player(player) then
if not cmd.parameter then
return
end
local target_player = game.players[cmd.parameter]
if validate_player(target_player) then
create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index)
else
player.print('Please type a name of a player who is connected.', Color.warning)
end
else
return
end
end
)
local function on_gui_click(event)
local player = game.players[event.player_index]
2020-11-04 18:14:30 +02:00
if not (event.element and event.element.valid) then
2020-07-30 19:09:18 +02:00
return
end
local name = event.element.name
if name == 'where_camera' then
player.gui.center['where_camera'].destroy()
return
end
end
2020-10-21 17:10:13 +02:00
Public.create_mini_camera_gui = create_mini_camera_gui
2020-07-30 19:09:18 +02:00
Event.add(defines.events.on_gui_click, on_gui_click)
2020-10-21 17:10:13 +02:00
return Public