-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrol.lua
More file actions
52 lines (46 loc) · 1.93 KB
/
control.lua
File metadata and controls
52 lines (46 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local build_entity_ghost = require("modules.build_ghost")
local fill_request_proxies = require("modules.fill_request_proxies")
local mine_entity = require("modules.mine_entity")
local ghost_builder_enabled = {}
local function set_ghost_builder_enabled(player, value)
ghost_builder_enabled[player.index] = value
pcall(function()
player.set_shortcut_toggled("ghost-builder-toggle", value)
end)
end
local function get_ghost_builder_enabled(player)
local enabled = ghost_builder_enabled[player.index]
if enabled ~= nil then return enabled end
enabled = true
pcall(function()
enabled = player.is_shortcut_toggled("ghost-builder-toggle")
end)
return enabled
end
local function toggle_ghost_builder(player)
local enabled = not get_ghost_builder_enabled(player)
set_ghost_builder_enabled(player, enabled)
player.print(enabled and "Auto Ghost Builder enabled" or "Auto Ghost Builder disabled")
end
-- Event for checking and building ghosts
script.on_event(defines.events.on_player_pipette, function(event)
local player = game.get_player(event.player_index)
if not player then return end
if not get_ghost_builder_enabled(player) then return end
-- Check if the player is hovering over a ghost entity
local hovered_entity = player.selected
if not hovered_entity then return end
if hovered_entity.name == "entity-ghost" then
local has_build=build_entity_ghost(player, hovered_entity)
if has_build then player.clear_cursor() end
else
local has_fill=fill_request_proxies(player, hovered_entity)
local has_mine=mine_entity(player, hovered_entity)
if has_fill or has_mine then player.clear_cursor() end
end
end)
commands.add_command("toggle-ghost-builder", "toggle gover ghost builder", function(event)
local player = game.get_player(event.player_index)
if not player then return end
toggle_ghost_builder(player)
end)