Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Place to get help with not working mods / modding interface.
Glsl2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Sep 18, 2023 1:33 am
Contact:

Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by Glsl2 »

Hello everyone, I am trying to experiment with an idea I had for a mod. In the mod, I want a beacon-like device to give a slowdown effect (negative speed) to machines around it. Another specification I have is that the machine must have no module slots.

After looking through the documentation I cannot figure out how to do this or if this can even be done. Any advice on this matter would be greatly appreciated.
sparr
Smart Inserter
Smart Inserter
Posts: 1462
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by sparr »

I'm not sure about negative effects, but a common way to achieve the other sort of behavior you're describing is to have a visible dummy entity, and then an invisible entity that does the real work, which would be a beacon with a module in it, all handled transparently by the mod so the player only ever interacts with the dummy entity.
Glsl2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Sep 18, 2023 1:33 am
Contact:

Re: Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by Glsl2 »

I see. But how do I attach a invisible entity to the visible entity? Is it done in the control.lua file?
User avatar
BrainGamer_
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Sun Nov 14, 2021 9:52 pm
Contact:

Re: Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by BrainGamer_ »

Glsl2 wrote: Fri Nov 03, 2023 10:06 am I see. But how do I attach a invisible entity to the visible entity? Is it done in the control.lua file?
Yes you would need to use runtime scripting for this behaviour
Glsl2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Sep 18, 2023 1:33 am
Contact:

Re: Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by Glsl2 »

Can you advise me on how to do this. I have limited experience with the control.lua file.

So after a bit of trial and error I have figured out how to create an invisible entity at the location of the visible entity. How do I use the visible entity to configure the invisible entity?
sparr
Smart Inserter
Smart Inserter
Posts: 1462
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by sparr »

You would need to register event handlers for when the visible entity gets built, and create the invisible entity. And when the visible entity is destroyed/mined, remove the invisible entity.

Configuring the invisible entity could happen when they player opens the GUI for the visible entity, just create your own GUI next to it. https://mods.factorio.com/mod/combinator-text is a mod of mine that adds a GUI alongside the vanilla combinator GUI, and there are many other examples in other mods.
Glsl2
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Sep 18, 2023 1:33 am
Contact:

Re: Allow beacons-like machine to give an effect without any modules in it to surrounding machines

Post by Glsl2 »

Erm. While trying to place a machine that creates the invisible entity I got a crash. It's not very descriptive, it says something is wrong with the fluid box, "requestedCount <= prototypes.size() was not true." I have attached the log file below. I assume something is wrong with my fluid box prototype declaration, but I can't figure it out.

Code: Select all

    name = "heat-distributer-visible",
    type = "assembling-machine",
    icon = "filepath"/heat_distribution_plate.png",
    icon_size = 64,
    gui_title_key = "heat-distributer-visible",
    
    fixed_recipe = "use-steam-to-heat",
    energy_usage = "300W",
    crafting_categories = {"crafting"},
    crafting_speed = 1,

    tile_width = 2,
    tile_height = 2,
    collision_box = {{-1.2, -1.2}, {1.2, 1.2}},
    selection_box = {{-1.5, -1.5}, {1.5, 1.5}},

    energy_source = {
        type = "fluid",
        scale_fluid_usage = false,
        fluid_usage_per_tick = 3,
        fluid_box = {
            base_area = 1,
            height = 2,
            base_level = -1,
            pipe_covers = pipecoverspictures(),
            burns_fluid = false,
            pipe_connections =
            {
                {type = "input", position = {1.5, 0.5}, filter = "super-heated-steam"},
                {type = "input", position = {-1.5, 0.5}, filter = "super-heated-steam"}
            },
            production_type = "input"
        }
        
    },

    minable = {mining_time = 0.5, result = "heat-distributer-visible"}
factorio-current.log
(8.68 KiB) Downloaded 38 times

Edit: I have fixed the crash by changing the type to generator and changed energy_source to electric and added fluid_box
Post Reply

Return to “Modding help”