Raised This Month: $62 Target: $400

[L4D2]Witch Adrenaline Booster

Post New Thread Reply   
Thread Tools Display Modes
New Member
Join Date: Jan 2018
Location: California
Plugin ID:
Plugin Version:
Plugin Category:
Plugin Game:
Left 4 Dead
Plugin Dependencies:
    Servers with this Plugin:
    Plugin Description:
    Instakill witch after shooting up adrenaline
    Old 05-23-2019 , 01:55   [L4D2]Witch Adrenaline Booster
    Reply With Quote #1

    Description: If a (non-bot) player deals damage to the witch with any weapon_melee, and shot up adrenaline within the last 10 seconds, the witch will be instakilled.

    This is my first plugin after lurking these forums for a couple years, so this was mostly just a POC for myself to dip my feet in the water. I appreciate any feedback/suggestions! For one, if anyone could point me towards a better way to kill an an entity than
    PHP Code:
    then let me know and I can change it.

    Attached Files
    File Type: sp Get Plugin or Get Source (l4d2_wab.sp - 77 views - 3.8 KB)
    backflip9 is offline
    Senior Member
    Join Date: Jan 2019
    Old 05-23-2019 , 05:03   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #2

    You can try to use some concept from Mr.Zero's [L4D2] Witch Melee Fix plugin.
    Instead of "kill" the entity you can get the Current HP from the witch and set it with in the OnTakeDamage event.
    Don't know if mine suggestion is the best solution but may work too.
    Marttt is offline
    Senior Member
    Join Date: Sep 2011
    Old 05-23-2019 , 06:20   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #3

    Some improvements you should do:

    You created an array that is MAXPLAYERS+1 but pass in the userid instead of the client index. This works currently until the userid go beyond MAXPLAYERS+1.

    You never validate if the attacker is actually a player before calling GetClientName. (Common Infected can attack the witch if biled, which then causes errors because of an invalid client index being passed to GetClientName).

    Unless you really need the userid there is no need to save it in a variable.

    You do not reset hasAdrenaline properly on join (OnClientPutInServer) or disconnect (OnClientDisconnect).

    You reset hasAdrenaline when you hit any common infected regardless of weapon or if its a witch or not.

    You should be using %N instead of GetClientName for printing message purposes (requires a client index).

    I'm not 100% on this one but I believe that GetClientSerial requires an client index not a userid. (This could be wrong)

    Again you do not validate the return of GetClientFromSerial before calling GetClientName. When the player disconnects before the timer runs out you will access a player that is no longer there causing errors.

    Optional stuff I would do is:
    - Check if we hit a witch first before caring about the weapon type.
    - Disable any debug messages for public release.
    - Add a chat message letting the player know that it is active after using adrenaline.
    - Add a chat message when the 10 second timer passes to let the player know its no longer active.

    You also could not add any message for the little surprise if it works / no longer works but thats up to you.

    PS: Instead of AcceptEntityInput(victim,"Kill"); you can use SDKHooks_TakeDamage (requires #include <sdkhooks>)

    Last edited by xerox8521; 05-23-2019 at 06:23. Reason: Added info about SDKHooks_TakeDamage.
    xerox8521 is offline
    AlliedModders Donor
    Join Date: Aug 2010
    Location: SpaceX
    Old 05-23-2019 , 09:01   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #4

    PHP Code:
    void HurtEntity(int targetint client)
    char sTemp[16];

    int entity CreateEntityByName("point_hurt");
    Format(sTempsizeof(sTemp), "dmg%d%d"EntIndexToEntRef(entity), client);
    AcceptEntityInput(entity"Hurt"client client : -1);

    Silvers is offline
    New Member
    Join Date: Jan 2018
    Location: California
    Old 05-23-2019 , 21:51   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #5

    Thanks for the feedback! I've implemented most of Xerox's suggestions but I'm a little hung up on the jargon. I tried to index my array by the client index, but that wasn't working until I started indexing it with the userid instead. However I still don't know the difference between those two things. Is the client index specific to the current connection to the server, whereas the userid is unique to the steam account that connects to the server? Could you point me to some documentation on those terms? I think I'd understand the suggestions that concern client index vs userid better that way:

    Originally Posted by xerox8521 View Post
    You created an array that is MAXPLAYERS+1 but pass in the userid instead of the client index. This works currently until the userid go beyond MAXPLAYERS+1.
    @Silvers Thanks for that code snippet, I think that'll make my code much cleaner. I'll try it out once I can sort of understand what it's doing. The terminology is also limiting me a bit there. I can't find anywhere that explains the difference between an entity and an edict? Links to documentation would be appreciated.

    Last edited by backflip9; 05-23-2019 at 21:52.
    backflip9 is offline
    Senior Member
    Join Date: Sep 2011
    Old 05-24-2019 , 07:32   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #6

    Client Indices range from 1 to MaxClients (inclusive). Which are assigned and unassigned when a player connects / disconnects.
    Client Indices are also Entity Indices because players are also entities but not all entity indices are valid client indices. Hence you need to verfiy that the client index you get is in the valid range. Usually its enough to check if IsClientInGame returns true / false and do actions based on that result.

    UserID is not tied to the steam account.
    UserID go from 1 to 65536 (could be 65535 not sure) where they increase each time a player connects until they reset hitting the max value.

    Example: I have client index 3 assigned now i disconnect and you join means you get the client index 3. Where as the userid simply increases eg from 3 to 4.

    When you want to pass a player around a delayed or asychronus function you should either use the userid or GetClientSerial the player can disconnect and a new one joines before the function is called potentionally affecting a player that which is not intended.

    PS: You should really use SDKHooks_TakeDamage there is absolutely no reason to create an entity to damage the witch.
    xerox8521 is offline
    Join Date: Dec 2017
    Location: Russia
    Old 05-27-2019 , 10:42   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #7

    Good idea! This definitely needs a switch between witch instakill/stumble.
    KoMiKoZa is offline

    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:10.

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