Torch Light


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

Tweaks
1 year, 8 months ago
0.17 - 1.1
611

i Please add character.is_flashlight_enabled() check

Ultrawup β˜†
1 year, 9 months ago

Hello,

I really like this mod, but sadly when the player's flashlight is disabled (such as by FlashlightOnOff or some other flashlight toggle mod), the torchlight remains on. It'd make a lot more sense if turning off the flashlight also turned off the torchlight.
This could easily be fixed by adding a check for the character.is_flashlight_enabled() condition to the on_tick() function in the script, so the torchlight only gets drawn on frames when the player's flashlight is also turned on.
Could you add this to the mod? Thanks a lot in advance!

PS: It would also be really nice if TorchLight automatically used the fancy HD light beam sprite from RealisticFlashlight if that's installed. I overwrote the tl-light sprite with it in data.raw using another mod, and it looks really good :D

1 year, 9 months ago

Can you please fix it?

Ultrawup β˜†
1 year, 9 months ago
(updated 1 year, 9 months ago)

These are the changes. A bit scuffed in a forum post like this, but it saves me from having to reupload the whole mod xD

--==[ control.lua ]==--

function on_tick()
  for player_index, player in pairs (game.connected_players) do
    local character = player.character
    if character then

      -- EDIT: added check to see if the player's flashlight is enabled, otherwise don't draw the spotlight
      if character.is_flashlight_enabled() then


        local target = player.selected or global.selected[player_index] or nil

        if target and target.valid and (character.surface.index == target.surface.index) then
          global.selected[player_index] = target
          local surface = player.surface

          local pos1 = character.position
          local pos2 = target.position
          local orientation = get_orientation (pos1, pos2)
          local distance = (((pos2.x-pos1.x)^2+(pos2.y-pos1.y)^2)^0.5)
          if distance > 0 then -- 0 is too few
            local intensity=0.8
            if distance > 10 then
              intensity=0.8 / (distance/10)^2
            end
            local scale = distance/10

            rendering.draw_light{sprite="tl-light", orientation=orientation, scale = scale, target=target, intensity=intensity, surface=surface, time_to_live=(UPDATE_TICKS+1)}
          end
        end
      end
    end
  end
end



--==[ data-updates.lua ]==--

-- Update light cone with enhanced texture if RealisticFlashlight is installed
if mods["RealisticFlashlight"] then
    local cone = data.raw.sprite["tl-light"] 
    cone.filename = "__RealisticFlashlight__/graphics/lightcone_enhanced.png"
    cone.width = 350
    cone.height = 370
end
Ultrawup β˜†
1 year, 8 months ago

Done :D

1 year, 8 months ago

Thanks!

New response