View Single Post
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 10-31-2021 , 13:47   Re: [L4D2] Inject Adrenaline to your Teammates
Reply With Quote #2

Nice plugin!

Some suggestions:

It might be better to use SDKHook_WeaponSwitchPost to detect when holding adrenaline - (instead of using SDKHook_WeaponSwitchPost's "weapon" variable use this instead: weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); to detect the weapon correctly, sometimes the "weapon" variable SDKHooks returns is not actually current one and causes issues, e.g. I think on Ladders).

That optimizes it instead of constantly checking "IsCurrentWeaponAdrenaline". Also the current method is constantly creating "char szClassName[32];" which would be better to set as "static char szClassName[32];", but if you switch to SDKHooks method that would be even better.

Because "OnPlayerRunCmd" is called for every client connected practically every frame, it is required to optimize this as best as possible. For example check if they're pressing the key before validating the client, the else statement looks good because you're checking if IN_USE was pressed already.

You have this:
PHP Code:
        if(!IsNearby(clienttarget)) return Plugin_Continue;
            
        
// Client let go of button. Abort. 
I think that should be "if(IsNearby())" continue, otherwise it will reset if they are still nearby and not reset when they have moved far away. Not really gone over the logic in detail to know the full intention.

Your "Inject_Adrenaline" function could be optimized, and probably elsewhere, I haven't checked the whole plugin. For example in this function you return when "if(g_bInUse[client] == false)" - this should be at the top before you start using more expensive native calls etc such as in the function "IsValidInjector".

These optimizations become important on servers with many plugins/players/slow hardware. These types of optimizations become noticeable especially when more plugins are optimized like that.
__________________
Silvers is offline