Page 1 of 1
[Modding help] Adding power output and supply area to lamp
Posted: Mon Jan 09, 2017 2:20 am
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!
Re: [Modding help] Adding power output and supply area to lamp
Posted: Mon Jan 09, 2017 5:29 am
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.
Re: [Modding help] Adding power output and supply area to lamp
Posted: Mon Jan 09, 2017 12:03 pm
by mophydeen
There is a mod:
https://mods.factorio.com/mods/Klonan/Torches
look at the code and see if you can add an electric pole