Raised This Month: $32 Target: $400
 8% 

[L4D2]Witch Adrenaline Booster


Post New Thread Reply   
 
Thread Tools Display Modes
Author
backflip9
New Member
Join Date: Jan 2018
Location: California
Plugin ID:
6577
Plugin Version:
0.0
Plugin Category:
Gameplay
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
    AcceptEntityInput(victim,"Kill")
    then let me know and I can change it.


    Github

    Cvars:
    l4d_wab_cooldown: Number of seconds the boost lasts.

    Spoiler
    Attached Files
    File Type: sp Get Plugin or Get Source (l4d2_wab.sp - 676 views - 5.9 KB)

    Last edited by backflip9; 08-29-2019 at 00:46.
    backflip9 is offline
    Marttt
    Veteran Member
    Join Date: Jan 2019
    Location: Brazil
    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
    xerox8521
    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
    Silvers
    SourceMod Plugin Approver
    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);
        
    DispatchKeyValue(target"targetname"sTemp);
        
    DispatchKeyValue(entity"DamageTarget"sTemp);
        
    DispatchKeyValue(entity"Damage""99999");
        
    DispatchKeyValue(entity"DamageType""128");
        
    DispatchSpawn(entity);
        
    AcceptEntityInput(entity"Hurt"client client : -1);
        
    RemoveEdict(entity);

    __________________
    Silvers is offline
    backflip9
    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:

    Quote:
    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
    xerox8521
    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
    KoMiKoZa
    Senior Member
    Join Date: Dec 2017
    Location: Thy old times.
    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
    backflip9
    New Member
    Join Date: Jan 2018
    Location: California
    Old 08-28-2019 , 14:25   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #8

    Found some free time to update the code to use client indices and suppress debug output. Debug output on the server console can be reenabled by downloading the source code and adding:
    PHP Code:
    #define DEBUG 
    near the top of the file.

    I'll try to setup convars for the amount of cooldown time and instakill/stumble tomorrow.
    backflip9 is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 08-28-2019 , 14:37   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #9

    Quote:
    Originally Posted by backflip9 View Post
    I can't find anywhere that explains the difference between an entity and an edict? Links to documentation would be appreciated.
    for all intents and purposes they're the same.
    __________________
    Silvers is offline
    backflip9
    New Member
    Join Date: Jan 2018
    Location: California
    Old 08-29-2019 , 00:50   Re: [L4D2]Witch Adrenaline Booster
    Reply With Quote #10

    Quote:
    Originally Posted by Silvers View Post
    for all intents and purposes they're the same.
    Right, that clears up some confusion.

    --

    I added a convar so that server admins can adjust the delay of the boost. I looked into adding a convar to control whether melee weapons kill or stagger the witch when the boost is active, but couldn't find an intuitive way to manually induce an attack that yields a stagger. Any advice on how to do that would be appreciated.
    backflip9 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 08:36.


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