Raised This Month: $12 Target: $400
 3% 

[L4D2] Realism Flashlight 1.2.4 [Nov-19-2023]


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Iciaria
Member
Join Date: Aug 2022
Plugin ID:
8335
Plugin Version:
1.2.4
Plugin Category:
Fun Stuff
Plugin Game:
Left 4 Dead
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Weapons not equipped with a flashlight will not be able to turn on the flashlight, optionally enable the flashlight battery system (dying torch vs blinking light).
    Old 12-24-2022 , 16:28   [L4D2] Realism Flashlight 1.2.4 [Nov-19-2023]
    Reply With Quote #1

    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


    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

    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.
    Attached Files
    File Type: cfg l4d2_RealismFlashlight.cfg (5.7 KB, 71 views)
    File Type: sp Get Plugin or Get Source (l4d2_RealismFlashlight.sp - 119 views - 38.5 KB)
    __________________
    Sorry,my english not good

    Last edited by Iciaria; 11-19-2023 at 04:15. Reason: Update to version 1.2.4
    Iciaria is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 12-24-2022 , 17:28   Re: [L4D2] Realism Flashligh 1.0 [25-Dec-2022]
    Reply With Quote #2

    Thanks for the release!

    Suggestions:

    - "Require_L4D2" should be replaced with checking game type in "AskPluginLoad2" with "GetEngineVersion", you can view any of my L4D2 specific plugins for example.

    - You could replace using "OnGameFrame" with "OnPlayerRunCmd" and detect impulse 100 when the flashlight is turned on/off. Or to detect the state like "Dynamic Light" or "Glare" plugins.

    - You are using timers with "client" as the optional arg but you should be using the clients userid and verifying that in the callback otherwise you're likely to affect the wrong client. You could view any of my plugins that pass a client index to timers to see how it should be done.

    - "public" can be removed from all custom named callbacks, only required for those from SM or 3rd party plugins.

    - In this case you don't need strncmp for the compare, strcmp would cover it just fine.

    - I think the "SetEntData" and "GetEntData" stuff should be replaced with "GetEntProp" / "SetEntProp" for "m_fEffects" the Prop_Send is not 1 byte length, this is an error in the code. It's 10 bits according to the netprops dump.

    - The "round_start", "round_end", "map_transition" and "finale_win" hooks could be "EventHookMode_PostNoCopy", there is no need for "EventHookMode_Pre" this is not the reason for using those hook types.

    - You're constantly calling FindConVar("sv_minupdaterate"); when a client connects, there is no need for this, you're not retrieving the value but simply finding the cvar handle. This should only be done in "OnPluginStart". If you want the value, add a changehook to the cvar and retrieve it's value, you can store that in a variable to use instead of calling GetConVarInt everytime you need it. That would optimize the plugin a bunch. You could do the same for all the cvars to store their value in a variable.

    - I've only skimmed through the plugin, so I don't know exactly why you have g_iflashlightState set to 8. Looks like you're only accounting for 8 players with flashlights. There are servers with more players. I think g_iflashlightState should be set to MAXPLAYERS + 1 and you should account for all possible clients. Then you can dispense with storing the client index in that array.
    __________________

    Last edited by Silvers; 12-24-2022 at 17:37.
    Silvers is offline
    Iciaria
    Member
    Join Date: Aug 2022
    Old 12-25-2022 , 18:11   Re: [L4D2] Realism Flashligh 1.0 [25-Dec-2022]
    Reply With Quote #3

    Quote:
    Originally Posted by Silvers View Post
    Thanks for the release!

    Suggestions:

    - "Require_L4D2" should be replaced with checking game type in "AskPluginLoad2" with "GetEngineVersion", you can view any of my L4D2 specific plugins for example.

    - You could replace using "OnGameFrame" with "OnPlayerRunCmd" and detect impulse 100 when the flashlight is turned on/off. Or to detect the state like "Dynamic Light" or "Glare" plugins.

    - You are using timers with "client" as the optional arg but you should be using the clients userid and verifying that in the callback otherwise you're likely to affect the wrong client. You could view any of my plugins that pass a client index to timers to see how it should be done.

    - "public" can be removed from all custom named callbacks, only required for those from SM or 3rd party plugins.

    - In this case you don't need strncmp for the compare, strcmp would cover it just fine.

    - I think the "SetEntData" and "GetEntData" stuff should be replaced with "GetEntProp" / "SetEntProp" for "m_fEffects" the Prop_Send is not 1 byte length, this is an error in the code. It's 10 bits according to the netprops dump.

    - The "round_start", "round_end", "map_transition" and "finale_win" hooks could be "EventHookMode_PostNoCopy", there is no need for "EventHookMode_Pre" this is not the reason for using those hook types.

    - You're constantly calling FindConVar("sv_minupdaterate"); when a client connects, there is no need for this, you're not retrieving the value but simply finding the cvar handle. This should only be done in "OnPluginStart". If you want the value, add a changehook to the cvar and retrieve it's value, you can store that in a variable to use instead of calling GetConVarInt everytime you need it. That would optimize the plugin a bunch. You could do the same for all the cvars to store their value in a variable.

    - I've only skimmed through the plugin, so I don't know exactly why you have g_iflashlightState set to 8. Looks like you're only accounting for 8 players with flashlights. There are servers with more players. I think g_iflashlightState should be set to MAXPLAYERS + 1 and you should account for all possible clients. Then you can dispense with storing the client index in that array.
    - For timer callbacks:
    I have done a check on the client index before creating the timer.
    Maybe the timer doesn't work like I thought it would?

    - For "OnGameFrame"
    I didn't know that "OnPlayerRunCmd" could work like "OnGameFrame" when I wrote this plugin, until I looked at the source code of "Dynamic Light" plugin, I will try to rewrite this plugin in a later version.(Because I need some way to fix the compatibility of this plugin with other related plugins)

    - For "g_ifashlightState"
    I bind the relevant values to the player's character, not the client index/id, for servers with more players, maybe try binding their "Steam id".(I don't want the player to be able to reinitialize his battery in any way)

    Thanks for all your suggestions!
    __________________
    Sorry,my english not good

    Last edited by Iciaria; 12-25-2022 at 18:12.
    Iciaria is offline
    Grey83
    Veteran Member
    Join Date: Dec 2014
    Location: Ukraine
    Old 12-26-2022 , 10:36   [L4D2] Realism Flashlight 1.1.1 [26-Dec-2022]
    Reply With Quote #4

    Changes 1.1.1 [26-Dec-2022]:
    • All plugin code has been rewritten to the new syntax (also compatible with SM 1.8 - 1.10)
    • Added ConVar bounds
    • Fixed timer tOnClientPutInServer
    • Slightly optimize performance and simplify code
    PHP Code:
    //// l4d2_RealismFlashlight 1.1.1.sp
    //
    // Code size:         17960 bytes
    // Data size:         8284 bytes
    // Stack/heap size:      16724 bytes
    // Total requirements:   42968 bytes
    //
    // Compilation Time: 0,41 sec
    // ----------------------------------------

    //// l4d2_RealismFlashlight 1.1.sp
    //
    // Code size:         20672 bytes
    // Data size:         8476 bytes
    // Stack/heap size:      16724 bytes
    // Total requirements:   45872 bytes
    //
    // Compilation Time: 0,41 sec
    // ---------------------------------------- 
    UPD Fixed line 372
    Attached Files
    File Type: sp Get Plugin or Get Source (l4d2_RealismFlashlight 1.1.1.sp - 282 views - 21.2 KB)
    __________________

    Last edited by Grey83; 12-26-2022 at 11:41.
    Grey83 is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 12-26-2022 , 11:09   Re: [L4D2] Realism Flashligh 1.1 [26-Dec-2022]
    Reply With Quote #5

    PHP Code:
    if((client GetClientOfUserId(client)) && IsClientInGame(client)) SetClientFlashLight(GetClientOfUserId(client)); 
    Should be:

    PHP Code:
    if((client GetClientOfUserId(client)) && IsClientInGame(client)) SetClientFlashLight(client); 
    __________________
    Silvers is offline
    Grey83
    Veteran Member
    Join Date: Dec 2014
    Location: Ukraine
    Old 12-26-2022 , 11:40   Re: [L4D2] Realism Flashligh 1.1 [26-Dec-2022]
    Reply With Quote #6

    Silvers, fixed and reuploaded
    __________________
    Grey83 is offline
    sonic155
    Senior Member
    Join Date: Mar 2019
    Old 12-26-2022 , 17:09   Re: [L4D2] Realism Flashligh 1.1 [26-Dec-2022]
    Reply With Quote #7

    Maybe add a cvar to allow it to recharge over time when its not active?
    sonic155 is offline
    Grey83
    Veteran Member
    Join Date: Dec 2014
    Location: Ukraine
    Old 12-27-2022 , 11:41   Re: [L4D2] Realism Flashligh 1.1 [26-Dec-2022]
    Reply With Quote #8

    Quote:
    Originally Posted by sonic155 View Post
    Maybe add a cvar to allow it to recharge over time when its not active?
    How are the batteries in real life?
    __________________
    Grey83 is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 12-27-2022 , 11:45   Re: [L4D2] Realism Flashligh 1.1 [26-Dec-2022]
    Reply With Quote #9

    Quote:
    Originally Posted by Grey83 View Post
    How are the batteries in real life?
    There are flashlights which recharge by moving/shaking them.
    __________________
    Silvers is offline
    Grey83
    Veteran Member
    Join Date: Dec 2014
    Location: Ukraine
    Old 12-27-2022 , 13:16   Re: [L4D2] Realism Flashligh 1.1 [26-Dec-2022]
    Reply With Quote #10

    Quote:
    Originally Posted by Silvers View Post
    There are flashlights which recharge by moving/shaking them.
    These are flashlights with electricity generators (like this: http://www.ogsolutions.it/Electropla...flashlight.php).
    __________________
    Grey83 is offline
    Reply


    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 07:42.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode