forked from billbo99/train-pubsub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp.lua
46 lines (45 loc) · 1.88 KB
/
bp.lua
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
script.on_event(defines.events.on_player_setup_blueprint, function(event)
-- game.print("In BP setup")
global.player = global.player or {}
global.player[event.player_index] = global.player[event.player_index] or {}
global.player[event.player_index].bp = {}
for idx,entity in pairs(event.mapping.get()) do
if entity.name == "train-publisher" then
global.player[event.player_index].bp = global.player[event.player_index].bp or {}
global.player[event.player_index].bp[idx] = entity
-- game.print(entity.unit_number)
end
end
end)
script.on_event(defines.events.on_player_configured_blueprint, function(event)
-- game.print("In BP configured")
local status,err = pcall(function()
local player = game.players[event.player_index]
local stack = player.cursor_stack
if stack.valid == true then
if stack.is_blueprint == true then
-- game.print("BP held")
for idx,bp_entity in pairs(global.player[event.player_index].bp) do
-- game.print(idx .. " : " .. bp_entity.unit_number)
for i,entity in pairs(global.newpublishers[player.surface.name]) do
for j,res_entity in pairs(entity) do
if res_entity.entity.unit_number == bp_entity.unit_number then
-- game.print("entity = bp entity")
stack.set_blueprint_entity_tags(idx, {
resource = res_entity.priority.resource,
id = res_entity.priority.id,
hide = res_entity.hide,
proc_priority = res_entity.proc_priority
})
break
end
end
end
end
end
end
end)
if not status then
game.print("Blueprint changed - Requester's details not saved")
end
end)