Torch Light


Selected entity will be lighted with the light spot with extra flashlight

Tweaks
2 years ago
0.17 - 1.1
662

g Bugs (and optimizations)

5 years ago

Just a heads up game.connected_players does not give the player_index as the first return

for _, player in pairs (game.connected_players) do
    local character = player.character
    if character then
      local target = player.selected or global.selected[player.index] or nil
      if target and target.valid then
        global.selected[player.index] = target

Secondly performance could possibly be improved by using on_selected_entity_changed and removing on_tick and player iteration completely

5 years ago

https://lua-api.factorio.com/latest/events.html#on_selected_entity_changed

Called after the selected entity changes for a given player.
Contains:
player_index :: uint: The player whose selected entity changed.
last_entity :: LuaEntity (optional): The last selected entity if it still exists and there was one.

There is no new_entity :(

5 years ago

Ok, I have game.players[event.player_index].selected.
But how can I get how many ticks the selected entity must be lighted? Until another selection? Then I need to delete old light by player entity selection and I can't see how to do that.

5 years ago
(updated 5 years ago)

Until the selection is removed (pseduo code below)

on_selected_event(event)
  local player = game.get_player(event.player_index)
  local selected = player.selected()
  if selected then
    global.rendered_light = rendering.make_light_codes
  elseif global.rendered_light then
    rendering.destroy(global.rendered_light)
    global.rendered_light = nil
end
end
5 years ago

Thanks for yous suggestion, but then I cannot rotate light spot to set up it like the light comes from the player.

But I need some idea how to optimize the Show Unconnected, here is big UPS drop by megabases. There I check one power pole every tick and see the difference between energy supply. If nothing was changed then this power pole has no connection to power source.

New response