BiusArt Light poles

by BiusArt

Adds light poles with different lighting

Tweaks
4 years ago
0.17 - 0.18
33

i Xmas version

5 years ago

hi, any chance of an xmas version of these light poles that each pole cycles though a series of colours ?

5 years ago

Version: 1.1.0
Date: 18. 11. 2019.
Changes:
- Added light poles random color

5 years ago

The latest version with the random light color option alternates between 0.014 ups and then spikes to 1.5. Causing a lag spike every couple of seconds.

5 years ago

A UPS saving idea .. Rather than search the surface for strobes, you could store the strobes in a global list using the entity.unit_number as a key. global.strobe.random_strobe[entity_number] = {intensity = 0.9, size = 28, color = {r = 255, g = 0, b = 0}}

On build add the strobe to the global list
On delete set the list entry to nil .. global.lights.random_strobe[entity_number] = nil
On tick period .. for loop though the colour list and perform your action.

For the random strobe,
it might be possible to just have one lamp and change its individual colour setting
https://wiki.factorio.com/Prototype/Lamp#light

When I get home from work I can look into this more .. is this code checked into Github ?

5 years ago
(updated 5 years ago)

Hello! Thanks for the help, I will try to do as you said, but I will be very glad if you help. I'm not on GitHub, but you can leave the modified files on drive.google.com or in any other storage convenient for you.

Unfortunately, I do not have programming languages, and some things are difficult for me, for example, in DiscoScience the same principle described by you, but I still did not understand how everything works and could not apply

by the way, you can write the necessary part of the code in the dialog)

5 years ago

This is my replacement for your control.lua, sorry it took longer than I said.

A global list keeps a track of each strobe as its placed, along with the lamp thats linked to it. Every 120 ticks it will destroy the old lamp and assign a new random lamp to the entity.

A lamp has its colour set in the DATA phase, the only way I can find to change the color of a lamp in game is using a combinator to send a virtual signal which causes the colour to be applied.

TODO .. To improve it further, either we use invisible combinators or batch the updates so 100 lamps are update each time the nth_tick event it called.

LAMPS = {"lamp-o", "lamp-b", "lamp-r" , "lamp-g"}

local function create_lamp(strobe, lamp_name)
    local surface = strobe.surface
    local direction = strobe.direction
    local surface = strobe.surface
    local force = strobe.force
    local position = strobe.position

    local lamp = surface.create_entity{
        name = lamp_name,
        position = {x = position.x, y = position.y},
        direction = direction,
        force = force
    }
    lamp.destructible = false
    lamp.minable = false
    return lamp
end

local function On120Ticks(current_tick)
    for idx, record in pairs(global.strobe) do
        if record.strobe.name == "stolb-r" then
            record.lamp.destroy()
            record.lamp = create_lamp(record.strobe, LAMPS[math.random(1,#LAMPS)])
        end
    end
end

local function OnStartup()
    global.strobe = global.strobe or {}
    global.strobe_queue = global.strobe_queue or {}
end

local function on_built(event)
    local entity = event.created_entity
    if not (entity and entity.valid) then return end

    local lamp_name = nil

    if entity.name == "stolb" then lamp_name = "lamp-w" end
    if entity.name == "stolb-2" then lamp_name = "lamp-r" end
    if entity.name == "stolb-3" then lamp_name = "lamp-g" end
    if entity.name == "stolb-4" then lamp_name = "lamp-o" end
    if entity.name == "stolb-5" then lamp_name = "lamp-b" end
    if entity.name == "stolb-r" then lamp_name = LAMPS[math.random(1,#LAMPS)] end

    if lamp_name then
        local direction = entity.direction
        local surface = entity.surface
        local force = entity.force
        local lamp = create_lamp(entity, lamp_name)
        global.strobe[entity.unit_number] = {strobe=entity, lamp=lamp}
        table.insert(global.strobe_queue, entity.unit_number)
    end
end

script.on_event(defines.events.on_built_entity, on_built)
script.on_event(defines.events.on_robot_built_entity, on_built)
script.on_event(defines.events.script_raised_built, on_built)

function del(event)
    local entity = event.entity
    if not (entity and entity.valid) then return end

    if global.strobe[entity.unit_number] then
        global.strobe[entity.unit_number].lamp.destroy()
        global.strobe[entity.unit_number] = nil
    end
end

script.on_event(defines.events.on_player_mined_entity, del)
script.on_event(defines.events.on_entity_died, del)
script.on_event(defines.events.on_robot_mined_entity, del)
script.on_event(defines.events.script_raised_destroy, del)

script.on_init(OnStartup)
script.on_nth_tick(120, On120Ticks)
5 years ago

Thank you for the work done, I will apply it now.
You not only helped, but also taught me something new, I am very grateful for that).

5 years ago

Version: 1.2.0
Date: 25. 11. 2019.
Changes:
- UPS optimization, thanks billbo99 for invaluable help

Now truly Xmas version)

4 years ago

how do i enable the random colors? It just stays white (RGB pole)?

4 years ago

we take the RGB light pole, put it on the ground, connect the electricity, and that's it, let’s do it at night. I just checked it works. In the settings on the map you can specify how long the colors will change, by default 2 seconds

New response