Page 1 of 1

Adding wires and cables to a new entity

Posted: Thu Aug 18, 2016 11:17 pm
by Hermios
Hi
I created a new entity based on a rail (No choice, really!). I would like to be able to connect it electricity and wires (red and green). I don't especially need to connect cable physically (ideally, cables won't be seen), just the property?
That would be great.
Many thanks

Niko

Re: Adding wires and cables to a new entity

Posted: Fri Aug 19, 2016 2:58 pm
by Rseding91
You can't add wires to entity types that don't support them in the core game.

The backing logic doesn't exist on that entity to save, load, connect, disconnect, and render the wires.

Re: Adding wires and cables to a new entity

Posted: Fri Aug 19, 2016 3:10 pm
by Hermios
Hey
Well, I had the idea of the year, the one that would make you rich :roll:
More seriously, would it be possible to add the possibility in a next version?

Re: Adding wires and cables to a new entity

Posted: Sun Sep 11, 2016 7:25 pm
by Lilly
You can possibly use scripting to create an invisible entity that does accept wires (and has no collision) on top of the rails and attach the red/green wires to that entity.

Re: Adding wires and cables to a new entity

Posted: Mon Sep 12, 2016 8:55 am
by Hermios
Hey Lilly
That's a good idea. Do you know if this is possible to actually create a new entity that would be a mix of two? Or to link two entities (For instance, If I remove my rail, the top entity shall be removed as well).
Thanks for the tipp

Niko

Re: Adding wires and cables to a new entity

Posted: Mon Sep 12, 2016 11:01 am
by Lilly
You cannot mix two types of entities, but you can link them using events. Code would look something like this:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
  if event.created_entity.name == "my-rail-type" then
    local entity = event.created_entity
    local control = entity.surface.create_entity{
      name = "my-rail-control",
      position = entity.position,
    }
  end
end)
script.on_event(defines.events.on_preplayer_mined_item, function(event)
  if event.entity.name == "my-rail-type" then
    local control = event.entity.find_entity("my-rail-control", event.entity.position)
    control.destroy()
  end
end)

Re: Adding wires and cables to a new entity

Posted: Mon Sep 12, 2016 11:13 am
by Hermios
oh, sounds great, many thanks!

Re: Adding wires and cables to a new entity

Posted: Mon Sep 12, 2016 1:28 pm
by aubergine18
A good example mod to look at is Concrete Lampposts.