About:
@Mr.Zero's plugin is having issues on my server,
players can still sometimes turn on the flashlight when holding a *not allowed item*.
I have long wanted to fix his plugin,
and have been trying to understand the source code of the "[L4D2] Block Flashlight (1.2, 18/10-2011)" plugin,
maybe the bug with this plugin is caused by something extra(Turn off the flashlight when on a ladder or ...).
But this plugin is so old I actually started writing my own plugin after learning how to set the Flashlight state.
I just need "can turn on flashlight when holding a firearm".
And
When I was testing on the server, some players asked me: Why not add a battery system to the flashlight?
(the server's map lighting style is very dark, and the player's flashlight is disabled until this plugin is complete
).
So...
This plugin can optionally activate the battery system.
Also, the flashlight will flash at different frequencies depending on the battery level.
Feature list:
- The player can only turn on the flashlight while holding a gun.
- Optionally turn on the battery system and set the flashing frequency of the lights.
- Optionally limit survivor bots' flashlights and set how fast they drain battery power.
- Optionally allows the player to recharge the battery, Otherwise, only replenished at the start of the campaign.
This plugin is designed for 4 player realism, but maybe it will work on 8 player servers (without repeating characters, but not tested),
on more than 8 player servers, this addon will not work properly.
Credit:
[email protected] ([L4D2] Block Flashlight (1.2, 18/10-2011))
First idea to learn how to control a flashlight light, something I've always wanted.
--@Silvers ([L4D2] Swap Character (1.2) [21-Mar-2020])
Learn how to get a client's character and check them.
--@ConnerRia. Fork. by Dragokas & KoMiKoZa ([L4D2] Saferoom Naps: Spawn Next Map With 50 HP)
Learn how to use the "map_transition" event.
--@All the players who helped me with the test
Natives:
Spoiler
PHP Code:
/**
* @brief Get the character's flashlight status.
* @remarks This plugin currently works through the "OnGameFrame()" function
* which may cause issues with other light related plugins.
*
* @param character Target character.
* @param index Array index.
*
*
* @return Specified value.
*/
native int RealismFlashlight_GetStatus(int character, int index);
Console commands:
Requires the "z" flag.
Code:
sm_rfl_view [character] [Any] //View the flashlight status of the specified characte.
// 0~7: Bill,Zoey,Francis,Louis,Nick,Rochelle,Coach,Ellis If present, the output of this command is visible to all.
sm_rfl_set [character] [Value] //Sets the flashlight battery level of the specified character.
// 0~7: Bill,Zoey,Francis,Louis,Nick,Rochelle,Coach,Ellis Value to set
Convar:
Spoiler
PHP Code:
// This file was auto-generated by SourceMod (v1.11.0.6933)
// ConVars for plugin "l4d2_RealismFlashlight.smx"
// Should the survivor robot's flashlight drain battery?
// 1 = Yes, 0 = No
// No matter what this value is set to, survivor bots will never be able to turn on the flashlight while holding a *disallowed weapon*.
// -
// Default: "1"
l4d2_RealismFlashLight_Bot "1"
// If 'l4d2_RealismFlashLight_Bot' has a value of 1, How many server frames must pass before the flashlight power of the survivor robot is consumed by one unit?
// Int Value.
// -
// Default: "4"
l4d2_RealismFlashLight_Bot_Buff "4"
// Enable debug mode?
// 0 = Disabled, 1 = Enabled
// If enabled, If enabled, check chat output when firing.
// -
// Default: "0"
l4d2_RealismFlashLight_Debug "0"
// Enabled This plugin?
// 0 = Disabled, 1 = Enabled
// -
// Default: "1"
l4d2_RealismFlashLight_Enabled "1"
// When the power is lower than a few percent of 'l4d2_RealismFlashLight_PowerMax', the light flashing interval set by 'lv0' is applied
// Percentage, Float Value.
// 0.00 = Disabled.
// -
// Default: "0.8"
l4d2_RealismFlashLight_FlashThreshold_lv0 "0.8"
// The maximum interval between each flash of the flashlight light
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "160"
l4d2_RealismFlashLight_FlashThreshold_lv0_Off_Max "160"
// The minimum interval between each flash of the flashlight light
// 0.1 Second, Int Value.
// 0 = Disabled.
// -
// Default: "10"
l4d2_RealismFlashLight_FlashThreshold_lv0_Off_Min "10"
// The slowest time after the flashlight is turned off to turn on automatically.
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "6"
l4d2_RealismFlashLight_FlashThreshold_lv0_On_Max "6"
// The fastest time after the flashlight is turned off to turn on automatically.
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "1"
l4d2_RealismFlashLight_FlashThreshold_lv0_On_Min "1"
// When the power is lower than a few percent of 'l4d2_RealismFlashLight_PowerMax', the light flashing interval set by 'lv1' is applied
// Percentage, Float Value.
// 0.00 = Disabled.
// -
// Default: "0.30"
l4d2_RealismFlashLight_FlashThreshold_lv1 "0.30"
// The maximum interval between each flash of the flashlight light
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "120"
l4d2_RealismFlashLight_FlashThreshold_lv1_Off_Max "120"
// The minimum interval between each flash of the flashlight light
// 0.1 Second, Int Value.
// 0 = Disabled.
// -
// Default: "2"
l4d2_RealismFlashLight_FlashThreshold_lv1_Off_Min "2"
// The slowest time after the flashlight is turned off to turn on automatically.
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "12"
l4d2_RealismFlashLight_FlashThreshold_lv1_On_Max "12"
// The fastest time after the flashlight is turned off to turn on automatically.
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "1"
l4d2_RealismFlashLight_FlashThreshold_lv1_On_Min "1"
// When the power is lower than a few percent of 'l4d2_RealismFlashLight_PowerMax', the light flashing interval set by 'lv2' is applied
// Percentage, Float Value.
// 0.00 = Disabled.
// -
// Default: "0.00"
l4d2_RealismFlashLight_FlashThreshold_lv2 "0.00"
// The maximum interval between each flash of the flashlight light
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "80"
l4d2_RealismFlashLight_FlashThreshold_lv2_Off_Max "80"
// The minimum interval between each flash of the flashlight light
// 0.1 Second, Int Value.
// 0 = Disabled.
// -
// Default: "2"
l4d2_RealismFlashLight_FlashThreshold_lv2_Off_Min "2"
// The slowest time after the flashlight is turned off to turn on automatically.
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "14"
l4d2_RealismFlashLight_FlashThreshold_lv2_On_Max "14"
// The fastest time after the flashlight is turned off to turn on automatically.
// 0.1 Second, Int Value.
// 0 = Disabled, 1 = Enabled.
// -
// Default: "1"
l4d2_RealismFlashLight_FlashThreshold_lv2_On_Min "1"
// Enable battery system?
// The flashlight will blink on low battery and disable when the battery is depleted.
// 0 = Disabled, 1 = Enabled
// -
// Default: "0"
l4d2_RealismFlashLight_PowerEnabled "0"
// The maximum flashlight battery level that can be set when the battery is initialized.
// Second, Int Value.
// -
// Default: "400"
l4d2_RealismFlashLight_PowerMax "400"
// The minimum flashlight battery level that can be set when the battery is initialized.
// Second, Int Value.
// -
// Default: "200"
l4d2_RealismFlashLight_PowerMin "200"
// Server Minimum tickrate, reference value for battery timer.
// Int Value
// 0 =Auto, Other Value = Value to Set
// -
// Default: "0"
l4d2_RealismFlashLight_ServerTickrate "0"
// When switch from a weapon without a flashlight to a weapon with a flashlight,
// Does it automatically restore the flashlight to its previously turned-on state if it was on?
// -
// Default: "0"
l4d2_RealismFlashlight_AutoFlashlight "0"
// If 'l4d2_RealismFlashLight_PowerEnabled' has a value of 1, Should players be allowed to charge flashlight batteries?
// 0 = No, 1 = Yes
// Survivor bot never recharges flashlight battery.
// -
// Default: "0"
l4d2_RealismFlashlight_Charge "0"
// Print a message in the chat box if the battery is full?
// 0 = No, 1 = Yes
// -
// Default: "1"
l4d2_RealismFlashlight_Charge_Hint "1"
// If the value of 'l4d2_RealismFlashLight_Bot_Buff' is 1, what button is used to charge?
// 0 = Shove only, 1 = Shove + Duck.
// -
// Default: "1"
l4d2_RealismFlashlight_Charge_Key "1"
// If the value of 'l4d2_RealismFlashLight_Bot_Buff' is 1, How much power is charged every time you press it (or hold it every 1.2 seconds)?
// Int Value, Second.
// -
// Default: "1"
l4d2_RealismFlashlight_Charge_Second "1"
Changelog:
Code:
1.2.4 (Nov-19-2023)
- Add Cvar: "l4d2_RealismFlashlight_AutoFlashlight", When switching from a weapon without a flashlight to a weapon with a flashlight, if the flashlight was previously in the ON state, it will automatically be restored. Requested by “Automage” And "swiftswing1".
1.2.3 (Oct-05-2023)
- Fixed: If a player dies during a map transition, battery status will be locked.
1.2.2(Feb-27-2023)
- Fixed: Plugin no longer work after chapter transitions.
- Fixed: Battery levels sometimes had incorrect values when round restarts or map changes.
- Fixed: When changing the value of cvar "l4d2_RealismFlashLight_Bot_Buff" in the game, if the new value is greater than or equal to the old value. The bot's battery will no longer be drained.
- Add plugin native "RealismFlashlight_GetStatus".
1.2.1(Feb-11-2023)
- Fix the problem that the charging function is invalid. Thanks to "sonic155" for report and help tested.
- It is now not possible to charge the battery above 100%.
- New Cvars: l4d2_RealismFlashlight_Charge_Hint, Used to control whether to print a message in the chat box to remind the player when the battery is fully charged.
- Various changes to the code.
1.2 (Feb-09-2023)
- The plugin now uses a new way to initialize the battery and check the client's correspondence with the character every server frame, This fixes some issues caused by players idle or changer characters.
- Fixed "Exception reported: Entity X (X) is invalid" being thrown when a player joins a server.Thanks to "sonic155" for reporting.
- New feature: hold down "duck + shove" or "shove" buttons to charge the battery. Requested by "sonic155".
- New feature: Optionally limit survivor bots' flashlights and batteries as well, and set how quickly they drain.
- New Cvars: l4d2_RealismFlashLight_Bot, l4d2_RealismFlashLight_Bot_Buff, l4d2_RealismFlashlight_Charge,l4d2_RealismFlashlight_Charge_Key, l4d2_RealismFlashlight_Charge_Second.
- Add console commands: sm_rfl_view sm_rfl_set, Use them to view and set the character's flashlight battery status.
- Various changes to the code.
1.1.2 (Dec-28-2022)
- Fix a problem: when Cvar changes, the value of "fPower" is always 0, causing the plugin to not work properly.
- The error only occurs when the battery system is enabled.
1.1 (Dec-26-2022)
- Now use "GetEngineVersion" in "AskPluginLoad2" to detect game type.
- Use "strcmp" instead of "strncmp" to check weapon names.
- Use "Get/SetEntProp" instead of "Get/SetEntData" to control the state of the flashlight.
- Now use the new way to pass the value of Cvar.
- Thanks to "Silvers" for suggestions.
- Changed default value of Cvars, on older versions, had wrong value (FlashThreshold_lv*).
- Survivor bots' flashlights are now also restricted.
- Various changes to the code.
- Optimize performance and simplify code.
1.0 (Dec-25-2022)
- Initial release.
Related plugins:
Version 1.2.2:
For the "Dynamic Light" and "glare" plugins, it is recommended to use my version, this will avoid the dynamic light created by these two plugins to appear when *flashlight is disabled*
Dynamic Light
glare
[L4D & L4D2] Dynamic Light (1.10) [07-Feb-2022]
I suggest @Toranks' version
[L4D & L4D2] Dynamic Muzzle Flash
[L4D & L4D2] Glare (2.14) [28-Aug-2022]
[L4D & L4D2] Weather Control (1.15) [05-Jul-2022]
Dynamic lights/muzzle flashes may cause map textures to flicker(After installing the "Weather Control" plugin).
This problem has nothing to do with my plugin.
Install:
For versions prior to 1.2.4, please delete the "l4d2_RealismFlashlight" file and let the plugin regenerate it, or manually add new cvars.
1.Click "Get Plugins" and put the "l4d2_RealismFlashlight.smx" file in "../left4dead2/addons/sourcemod/plugins/".
2.Download the "l4d2_RealismFlashlight.cfg" file and put it in "../left4dead2/cfg/sourcemod/".
You may need to tweak the "l4d2_RealismFlashlight.cfg" file.