채팅창에 복붙하기만 하면 되는 예제 커맨드를 두개 만들었다.
첫번째 콘솔커맨드는 스피커와 투명 전봇대, 투명 발전기를 만드는 예제.
/silent-command
local p = game.player.surface.find_non_colliding_position( 'programmable-speaker', game.player.position, 10, 1, true )
if not p then p = game.player.position end
local speaker, powerpole, powersource
speaker = game.player.surface.create_entity{ name = 'programmable-speaker', position = p, force = game.player.force }
powersource = game.player.surface.create_entity{ name = 'hidden-electric-energy-interface', position = speaker.position, force = game.player.force }
powerpole = game.player.surface.create_entity{ name = 'crash-site-electric-pole', position = speaker.position, force = game.player.force }
for _, v in pairs(powerpole.neighbours.copper) do v.disconnect_neighbour(powerpole) end
powerpole.connect_neighbour{
wire = defines.wire_type.red,
target_entity = speaker
}
powersource.power_production = 34
powersource.electric_buffer_size = 34
speaker.parameters = {
playback_volume = 0.75,
playback_globally = true,
allow_polyphony = false
}
speaker.get_control_behavior().circuit_parameters = {
signal_value_is_pitch = false,
instrument_id = 0,
note_id = 6
}
speaker.get_control_behavior().circuit_condition = {
condition = {
comparator = '=',
first_signal = { type = 'virtual', name = 'signal-everything' },
second_signal = nil,
constant = 0
},
fulfilled = true
}
------------------------------------------------------------
첫 스피커 예제는 여기까지고,
------------------------------------------------------------
두번째 예제는 조합기 예제 종합선물세트.
파워스위치에 구리선 연결하는건 내가 해보니 안되드라. 해보고 안되면 개발자한테 보고하셈.
/silent-command
local p = game.player local pos = p.surface.find_non_colliding_position( 'rocket-silo', game.player.position, 20, 0.5, true )
if not pos then pos = p.position end
local powersource = p.surface.create_entity{name = 'electric-energy-interface', force = p.force, position = {pos.x-3,pos.y-1}}
local const = p.surface.create_entity{name = 'constant-combinator', direction = defines.direction.east, force = p.force, position = {pos.x-1,pos.y}}
local decide = p.surface.create_entity{name = 'decider-combinator', direction = defines.direction.east, force = p.force, position = pos}
local arith = p.surface.create_entity{name = 'arithmetic-combinator', direction = defines.direction.east, force = p.force, position = {pos.x+2,pos.y}}
local powerswitch = p.surface.create_entity{name = 'power-switch', force = p.force, position = {pos.x,pos.y+2}}
local pole1 = p.surface.create_entity{name = 'medium-electric-pole', force = p.force, position = {pos.x-1,pos.y-1}}
local pole2 = p.surface.create_entity{name = 'medium-electric-pole', force = p.force, position = {pos.x+4,pos.y+1}}
local lamp1 = p.surface.create_entity{name = 'small-lamp', force = p.force, position = {pos.x+4,pos.y+2}}
local lamp2 = p.surface.create_entity{name = 'small-lamp', force = p.force, position = {pos.x+2,pos.y-1}}
local lampsolo = p.surface.create_entity{name = 'small-lamp', force = p.force, position = {pos.x+1,pos.y-2}}
for _, v in pairs(pole1.neighbours.copper) do if v==pole2 then v.disconnect_neighbour(pole1) break end end
const.get_control_behavior().set_signal(
1,
{ signal = { type = 'virtual', name = 'signal-yellow' }, count = -1 }
)
const.get_control_behavior().set_signal(
2,
{ signal = { type = 'virtual', name = 'signal-red' }, count = 1 }
)
const.connect_neighbour{
wire = defines.wire_type.red,
target_entity = decide,
target_circuit_id = defines.circuit_connector_id.combinator_input,
}
const.connect_neighbour{
wire = defines.wire_type.green,
target_entity = arith,
target_circuit_id = defines.circuit_connector_id.combinator_input,
}
decide.get_control_behavior().parameters = {
parameters = {
first_signal = { type = 'virtual', name = 'signal-yellow' },
comparator = '≤',
second_signal = nil,
constant = -1,
output_signal = { type = 'virtual', name = 'signal-yellow' },
copy_count_from_input = false,
},
}
decide.connect_neighbour{
wire = defines.wire_type.red,
target_entity = decide,
source_circuit_id = defines.circuit_connector_id.combinator_output,
target_circuit_id = defines.circuit_connector_id.combinator_input,
}
decide.connect_neighbour{
wire = defines.wire_type.green,
target_entity = arith,
source_circuit_id = defines.circuit_connector_id.combinator_output,
target_circuit_id = defines.circuit_connector_id.combinator_input,
}
arith.get_control_behavior().parameters = {
parameters = {
first_signal = { type = 'virtual', name = 'signal-each' },
first_constant = nil,
operation = '*',
second_signal = { type = 'virtual', name = 'signal-red' },
second_constant = nil,
output_signal = { type = 'virtual', name = 'signal-yellow' },
},
}
arith.connect_neighbour{
wire = defines.wire_type.green,
target_entity = powerswitch,
source_circuit_id = defines.circuit_connector_id.combinator_output,
}
arith.connect_neighbour{
wire = defines.wire_type.red,
target_entity = lamp1,
source_circuit_id = defines.circuit_connector_id.combinator_output,
}
arith.connect_neighbour{
wire = defines.wire_type.red,
target_entity = lamp2,
source_circuit_id = defines.circuit_connector_id.combinator_output,
}
lamp1.get_control_behavior().use_colors = true
lamp1.get_control_behavior().circuit_condition = {
condition = {
first_signal = { type = 'virtual', name = 'signal-everything' },
comparator = '≠',
second_signal = nil,
constant = 0,
},
}
lamp2.get_control_behavior().use_colors = true
lamp2.get_control_behavior().circuit_condition = {
condition = {
first_signal = { type = 'virtual', name = 'signal-anything' },
comparator = '≥',
second_signal = nil,
constant = 1,
},
}
lampsolo.get_or_create_control_behavior().connect_to_logistic_network = true
lampsolo.get_control_behavior().logistic_condition = {
condition = {
first_signal = { type = 'item', name = 'wooden-chest' },
comparator = '=',
second_signal = { type = 'item', name = 'wooden-chest' },
constant = nil,
},
}
powerswitch.get_control_behavior().circuit_condition = {
condition = {
first_signal = { type = 'virtual', name = 'signal-yellow' },
comparator = '>',
second_signal = nil,
constant = 0,
},
}
----------------------------------------------------------------------
----------------------------------------------------------------------
LuaEntity 클래스의 get_control_behavior() 또는 get_or_create_control_behavior() 메소드를 사용해서 LuaControlBehavior 클래스를 뽑아내서 조작하면 됨.
클래스 설명은
https://lua-api.factorio.com/latest/LuaControlBehavior.html
이곳에 거의 모든 것이 다 있다.
파워스위치에다 connect_neighbour 메서드를 LuaEntity를 인수로 써서 연결하려고 하면 전봇대가 아니라고 하고, wire, target_entity 등의 키를 포함한 table을 인수로 써서 연결하려고 하면 wire = defines.wire_type.copper로 지정해서 넘기면 와이어는 빨강아님 초록만 연결할 수 있다고 뜸. 버그인듯.
버그리폿 내가 걍 씀
ㅁ..몬데.. - dc App