Adding wires and cables to a new entity

Place to get help with not working mods / modding interface.
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Adding wires and cables to a new entity

Post 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
Rseding91
Factorio Staff
Factorio Staff
Posts: 15984
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Adding wires and cables to a new entity

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Adding wires and cables to a new entity

Post 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?
Lilly
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Mon Apr 11, 2016 6:42 pm
Contact:

Re: Adding wires and cables to a new entity

Post 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.
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Adding wires and cables to a new entity

Post 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
Lilly
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Mon Apr 11, 2016 6:42 pm
Contact:

Re: Adding wires and cables to a new entity

Post 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)
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Adding wires and cables to a new entity

Post by Hermios »

oh, sounds great, many thanks!
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Adding wires and cables to a new entity

Post by aubergine18 »

A good example mod to look at is Concrete Lampposts.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”