Better Flashlight

If you liked this item, please rate it up on Steam Workshop page.

Author: Liokindy

Last revision: 15 Feb, 2025 at 04:20 UTC

File size: 374.01 KB

On Steam Workshop

Description:

A simple script to enhance the HL2 flashlight, in third person the flashlight will always come from the player’s view instead of the player model’s hand, gives players the ability to choose a custom color and texture for it (if allowed by the server), and some more

For Developers

This addon overrides the behavior of the default flashlight, but I made sure you can still check for the player’s flashlight.

Instead of using Player:FlashlightIsOn() you can use Player:GetNWBool("FlashlightIsOn"), Player:FlashlightIsOn() will always return false if the user is using this addon

The addon respects the Player:CanUseFlashlight() property and runs the PlayerSwitchFlashlight event to check if the player can switch it’s flashlight on or off.

As for sound, it does not use or add a custom sound, it uses the default HL2 soundscript "HL2Player.FlashLightOn" and "HL2Player.FlashLightOff", so basic sound replacements should work.

Client Console Variables
Name
Default
Purpose

cl_flashlight_only_local_shadows
1
If set to 1, only the local player’s flashlight will cast shadows, having a lot of shadow-casting flashlights can become really expensive on performance (there’s a limit on how many projected textures (i.e flashlights and other fancy lights) that cast shadows can exist at once, read more here: https://developer.valvesoftware.com/wiki/Env_projectedtexture#Caveats_and_Fixes in GMod this limit is 8)

cl_flashlight_hl2_obstruction_check
1
If set to 1, while in first person the flashlight will "pullback" when too close to a wall or object

cl_flashlight_follows_viewpunch
1
If set to 1, the flashlight will follow a player’s viewpunch (view nudges when shooting or getting hit)

cl_flashlight_thirdperson_near_z
46
The higher this value, the further away shadows from a player’s flashlight will start in third person. This prevents the player’s arms or weapons from casting shadows

cl_flashlight_firstperson_angle_lerp
0
If set to a number above 0, while in first person the flashlight’s angle will smoothly turn instead of being locked to the player’s view angles

cl_flashlight_thirdperson_glow_follows_bone
""
The glow and beam of the flashlight while in third person will try to follow the bone specified. Empty means they will follow the player’s view position. You can see common bone names here: https://wiki.facepunch.com/gmod/ValveBiped_Bones

cl_flashlight_config_color
255 255 255
The custom color used for your flashlight, if custom colors are allowed. There are 3 convars for each color component, r, g and b. A 4th convar exists for alpha but it is not used, it is there for technical reasons

cl_flashlight_config_texture
"effects/flashlight001"
The custom texture used for your flashlight, if custom textures are allowed

cl_flashlight_thirdperson_show_glow
1
If set to 1, while in third person a player’s flashlight will emit a bright glow when looked at like the lamps spawned by the lamp tool

cl_flashlight_thirdperson_show_beam
1
If set to 1, while in third person a player’s flashlight will emit a beam

cl_flashlight_thirdperson_beam_max_alpha
100
The maximum alpha reached by a player’s flashlight beam, the beam fades away when looking at the flashlight directly and gets more visible when looked at from the side

Server Console Variables
Name
Default
Purpose

sv_flashlight_override_default
1
Enable or disable overriding the default flashlight

sv_flashlight_allow_colors
1
Allow if players can set their own flashlight’s color (if not allowed, the default flashlight color will be used)

sv_flashlight_allow_textures
1
Allow if players can set their own flashlight’s texture (if not allowed, the default flashlight texture will be used)

sv_flashlight_default_color
255 255 255
The default color used for flashlights if custom colors are not allowed. There are 3 convars for each color component, r, g and b. A 4th convar exists for alpha but it is not used, it is there for technical reasons

sv_flashlight_default_texture
"effects/flashlight001"
The default texture used for flashlights if custom textures are not allowed