[Modding help] Adding power output and supply area to lamp

Place to get help with not working mods / modding interface.
kamikazehighland
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sun Jan 08, 2017 7:13 pm
Contact:

[Modding help] Adding power output and supply area to lamp

Post by kamikazehighland »

I'm trying to figure out how to mod objects. I've been attempting something I thought would be simple - making lamps a power source with a supply area [before adding fuel slots and consumption]. I've tried copying code from the steam engine and from electric poles but it's ignored in-game. I assume it's because lamps aren't the same type of object but I don't see where type="lamp" is defined so that I can add "supply_area_distance", "radius_visualisation_picture" and so on to a lamp type object.

Is it even possible to add both properties to a lamp? If it is any help would be appreciated!
Yoyobuae
Filter Inserter
Filter Inserter
Posts: 511
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: [Modding help] Adding power output and supply area to lamp

Post by Yoyobuae »

kamikazehighland wrote:Is it even possible to add both properties to a lamp? If it is any help would be appreciated!
Unluckily no, each entity has a fixed set of properties it uses and ignores the rest.

What mods usually do is create additional hidden entities to combine their functionalities. So in your case you would have:
  • lamp entity: to produce light
  • electric pole entity: to have electric supply area
  • steam engine entity: to produce power
The player would place only one entity, say the lamp. Then in control.lua you detect when the lamp entity is built, and additionally place hidden electric pole and steam engine entities. Also need to detect when the lamp is removed or destroyed in order to remove the extra entities.

The script events you need to handle are:

Code: Select all

script.on_event(defines.events.on_robot_built_entity, function(event) OnBuilt(event.created_entity) end)
script.on_event(defines.events.on_built_entity, function(event) OnBuilt(event.created_entity) end)

script.on_event(defines.events.on_preplayer_mined_item, function(event) OnRemoved(event.entity) end)
script.on_event(defines.events.on_robot_pre_mined, function(event) OnRemoved(event.entity) end)
script.on_event(defines.events.on_entity_died, function(event) OnRemoved(event.entity) end)
Suggest you look at code from other mods to see how they do it.
Post Reply

Return to “Modding help”