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

[L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]


Post New Thread Reply   
 
Thread Tools Display Modes
Author
dcx2
Senior Member
Join Date: Sep 2011
Plugin ID:
3066
Plugin Version:
1.3
Plugin Category:
Gameplay
Plugin Game:
Left 4 Dead
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Prevents friendly fire under certain circumstances
    Old 07-07-2012 , 21:32   [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #1

    DESCRIPTION

    There are some instances where a Survivor should not suffer the consequences of friendly fire. This plugin attempts to account for these situations.




    BLOCKING DAMAGE

    1) Too Close - When two players are very close to each other, the end of the first player's gun model's barrel could be in front of the second player's body, and yet the game will still register friendly fire. This type of friendly fire should be undone, since the bullet never really traveled through the survivor.

    In the screenshot above, you can see that Rochelle is "inside" of Nick, and she has just pulled the trigger on a military sniper on expert. Without this plugin, that shot would have done 45 damage to Nick. It's unreasonable for Nick to take 45 damage in this situation.

    2) Charger Carry - When a Survivor is pinned by a smoker, hunter, or jockey, the game will prevent friendly fire. When a charger is pummeling a survivor, it also prevents friendly fire. But if a charger is carrying a survivor, you can still hit them with friendly fire. This type of friendly fire should be undone, because a carry should be like a pin.

    3) Stupid Bot - Sometimes when you friendly fire, the game will determine who is guilty and if it was the fault of the survivor who got hurt, it will display a message like "don't walk into the line of fire". If the game determines a bot is guilty of a friendly fire event, it should be undone, because bots shouldn't be able to friendly fire.


    This plugin allows all of these situations to be accounted for. Each of the three scenarios can be individually enabled using enable bit flags.

    Additionally, type 1 FF ("Too Close") distances have been calibrated on a per-gun basis using trial-and-error with one client watching another friendly firing a third client, to see at what distance the tip of the gun is not colliding with the third client's model. (CS weapons are "assumed" based on similar weapon classes, although they haven't been specifically tested) These values are hard-coded and cannot be changed unless you recompile.

    melee, pistol, chainsaw = 25.0
    smg, smg_silenced, smg_mp5, pistol_magnum, grenade_launcher = 30.0
    pumpshotgun, autoshotgun, rifle, hunting_rifle, sniper_scout, sniper_awp, shotgun_spas, shotgun_chrome, rifle_sg552, rifle_desert, rifle_ak47 = 37.0
    sniper_military = 42.0
    rifle_m60 = 47.0

    Friendly fire events that are undone are completely blocked with SDKHooks. This prevents it from counting in the final stat crawl, and it also prevents them from vocalizing friendly fire lines.


    BLOCKING 0-DAMAGE EFFECTS

    Additionally, you may be surprised to see how often the engine itself reduces friendly fire to 0 damage. These 0-damage friendly fires are also blocked. UPDATE (v1.2): By default this only happens on non-Easy difficulties, because all friendly fire damage is 0 on Easy so you would have no way to know how bad your friendly fire actually is. However, there is a cvar that can disable blocking 0 damage altogether, or it can disable it for all difficulties including easy.

    UPDATE (v1.3): When a survivor bot shoots you a human, the human's vision recoils. By default this is now blocked. This is a bit flag that is added to the existing cvar


    ANNOUNCEMENTS

    When friendly fire happens, it can optionally be announced in either the chat or the console (configurable via cvar), so that you know who hit who, from what distance, if it was undone and why. Announcing in the console has been provided as an option for those who dislike chatty plugins, but unfortunately console announcements don't have the pretty colors like chat announcements do. Announcements can also be entirely disabled as well.


    UNDO DAMAGE

    This plugin also creates a new admin command, sm_undodamage. It keeps track of the last 16 hits against a survivor, and allows an admin to undo them. It can undo any type of damage, not just friendly fire, so when e.g. a zombie hits you through the side of a truck, you can sm_undodamage on yourself. It can undo incaps. UPDATE (v1.3): It can also undo a health kit being used, restoring the pre-health kit perm and temp health, and spawning the a weapon_first_aid_kit to compensate for the undone health kit.


    FRACTIONAL DAMAGE TRANSFER

    Finally, this plugin can also transfer a percentage of damage from permanent health to temporary health. Normally I would put such a different feature into another plugin, but in order to work properly with sm_undodamage, it must reside in the same plugin.

    Allow me to use an example. Let's say you have 50 perm and 50 temp health, and you get shot by a sniper on expert (45 damage). Typically, and by default with this plugin, it would deal 45 damage to perm health and 0 damage transferred to temp health, leaving you with 5/50. If you set the permdmgfrac to 0.5, then half (round down) of the damage would be transferred to temp health, meaning 23 perm damage and 22 temp damage, leaving you with 27/28 instead of 5/50. If you set permdmgfrac to 0.0, then all 45 damage would be transferred to temp health before being done to permanent health, leaving you with 50/5.


    CVARS

    // Bit flag: Enables plugin features (add together): 1=too close, 2=Charger carry, 4=guilty bots, 7=all, 0=off
    l4d2_undoff_enable "7"

    // Bit flag: Block 0 damage friendly fire effects like recoil and vocalizations/stats (add together): 4=bot hits human block recoil, 2=block vocals/stats on ALL difficulties, 1=block vocals/stats on everything EXCEPT Easy (flag 2 has precedence), 0=off
    l4d2_undoff_blockzerodmg "5"

    // Bit flag: Enable damage announcements: 2=chat, 1=console, 0=off
    l4d2_undoff_announce "2"

    // Minimum fraction of damage applied to permanent health
    l4d2_undoff_permdmgfrac "1.0"

    // Print debug output (1023=all)
    l4d2_undoff_debug "0"


    ADMIN COMMANDS

    sm_undodamage [client/#userid] - ADMFLAG_SLAY - undoes the last attack's damage to client (optional parameter, default is @me)


    CONFIG

    [game]/cfg/sourcemod/L4D2UndoFF.cfg

    If upgrading from a previous version, I recommend using SilverShot's Cvar Configs Updater plugin to update because it's the easiest solution. Or you can add any new cvars to this file yourself. Or backup this file, delete it and it will be automatically recreated and then you can restore your backed up settings.

    Another upgrade warning, for v1.3 the default value for l4d2_undoff_blockzerodmg has changed from 1 to 5. This change is not automatically updated so you may need to go into the file config file and change it manually if you want enable blocking bot-on-human friendly fire recoil.


    HISTORY

    v1.1 - fixed sm_undodamage bug

    v1.2 - Cleaned up the code a little more
    fixed announce bug (0 would still print to console)
    announce 0-damage melee attacks
    1x stacked attacks do not show 1x multiplier
    stacked attacks that incap a survivor announce only one message instead of two
    added cvar for blocking 0-damage attacks
    calls give health before undoing an incap and resetting health (better way to get survivors up)

    v1.3 - Cleaned up the code a little more
    Block bot-on-human friendly fire recoil
    Can undodamage a health kit being used on a survivor


    INSTALLATION

    This plugin requires SDKHooks, so please DO NOT CLICK "Get Plugin", you must download the smx.
    Attached Files
    File Type: sp Get Plugin or Get Source (l4d2_undoff.sp - 1591 views - 36.7 KB)
    File Type: smx l4d2_undoff.smx (19.1 KB, 2428 views)

    Last edited by dcx2; 07-25-2012 at 01:04. Reason: update to 1.3
    dcx2 is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 07-25-2012 , 01:06   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #2

    New version bump - I hope no one minds, it's been a few weeks and I have added what I think is a pretty cool feature - bots don't cause your screen to recoil when they shoot you anymore.
    __________________
    dcx2 is offline
    Mr. Zero
    Veteran Member
    Join Date: Jun 2009
    Location: Denmark
    Old 07-25-2012 , 05:52   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #3

    A few things that could change.

    #define IS_CONNECTED_INGAME(%1) (IsClientConnected(%1) && IsClientInGame(%1))

    Once a player is in game, you do not need to check if they are also connected. The only way for them to be in game is to be connected.

    PHP Code:
    // TODO: When the plugin is reloaded, existing clients' hooks are lost
    //          How can I fix this? 
    You do that by using OnAllPluginsLoaded.

    PHP Code:
    // Account for late loading
    public OnAllPluginsLoaded()
    {
        for (new 
    client 1client <= MaxClientsclient++)
        {
            if (
    IsClientInGame(client))
            {
                
    SDKHook(clientSDKHook_OnTakeDamageOnTakeDamageUndoFF);
                
    SDKHook(clientSDKHook_TraceAttackTraceAttackUndoFF);
            }
        }

    Other than that, please notice that OnTraceAttack or OnTakeDamage also fires during god frames. Meaning while the Survivor is getting up after being attacked by SI but take no damage even through OnTakeDamage hook fires.

    Good plugin!
    Good use of stocks as well ;)

    Last edited by Mr. Zero; 07-25-2012 at 05:53.
    Mr. Zero is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 07-25-2012 , 23:32   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #4

    Thanks for the feedback! I didn't know that you could call IsClientInGame without checking IsClientConnected, that's good to know. Thanks also for the OnAllPluginsLoaded trick, it should make developing with SDKHooks a lot easier than executing "changelevel c1m1_hotel" again and again lol.

    Here are the things I learned while writing this plugin.

    1.) First TraceAttack is called. TA adjusts bullet damage based on distance, but not on any other factors. Even the bots appear to do damage to humans in TA.

    2.) OnTakeDamage is called next. OTD knows how much damage the survivor is scheduled to take - if the game reduces it to 0 (for instance, because a bot shot a human) then OTD will show 0. I'm not sure if OTD knows about any locational-based bonuses (i.e. if OTD shows 4x the value from TA when shooting an SI in the head), because survivors take 1x damage no matter where you shoot them.

    3.) OTD damage is rounded down for survivors.

    4.) In order to block the recoil effect you must block in TA. This would normally be quite problematic, as the engine hasn't had a chance to make some decisions yet, but in my case I'm using it only on bots who will never do any real damage anyway.

    5.) You can block friendly fire vocalizations and stats in OTD. This is where I prefer to block when possible, because it allows me to discriminate between whether I blocked the friendly fire or if the game reduced it to 0.

    6.) Only player_hurt knows when a player *actually* takes damage. OTD will fire in all kinds of places where you don't take damage; shooting someone being dragged by a smoker, or otherwise pinned by anyone else (except a charger carry), when getting up from a pin, when falling from certain areas like the stairs into the sewer on the Passing 2, etc.

    Unfortunately, player_hurt happens after the health has been lost, so we have no way to know how much permanent health the player had in player_hurt. That's where the coordination comes in; OTD stores the player's health so that player_hurt has all of the information that it needs.

    7.) The one time player_hurt doesn't fire is when a player is incapped. But we have player_incap_start for that, and it fires before damage is applied which is nice.

    8.) Melee attacks do multiple hits, but only one hit does damage. The others are 0 damage. Weird, huh? I haven't tried but it might be interesting to see if the melee hits are doing 0 damage in TraceAttack.

    9.) I'm not really sure on the difference between Format and FormatEx, but I think Format allows you to use the destination string as one of the arguments, for a sort of concatenating thing? But I wasn't 100% sure, so I went with different strings and FormatEx instead.

    10.) The friendly fire event doesn't actually fire that often, so it's rather unreliable at determining when it was the bot's fault for getting hit. But it's better than nothing. It also only fires once if you hit multiple times in a row, which is why there's a timer that gives the bot temporary immunity.

    11.) There's about 1 second between a charger carry ending and a charger pummel beginning.

    12.) heal_end claims to know the subject, but it's a lie! In heal_end the subject is always the healer, whether or not the health kit is used on someone else. Hence, in heal_start, I capture the subject, and then in heal_end, I capture the subject's temp health just before they lose it. In heal_success the subject is correct again (WTF?!) so we don't need it stored anymore.

    13.) Stacks, Timers, FormatEx/VFormat, ... args, three dimensional arrays, macros with arguments (add extra ()'s for protection!), mins/maxs to control for height while crouching...this was a lot of fun, actually.

    14.) Cvar hooking and multi targeting thrown in just as part of best practice.
    __________________

    Last edited by dcx2; 07-26-2012 at 00:31.
    dcx2 is offline
    ellie3535
    Junior Member
    Join Date: Jan 2011
    Old 08-07-2012 , 10:03   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #5

    Hello, the .sp file you uploaded cannot be compiled:
    Quote:
    l4d2_undoff.sp<934>:error 017: undefined symbol "GetEntityClassname"
    I compile it myself becoz I want to translate the announcement text in sp file to my own language
    ellie3535 is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 08-07-2012 , 11:00   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #6

    GetEntityClassname was introduced in Sourcemod 1.3.8. http://docs.sourcemod.net/api/index....d=show&id=959&

    Go into your server's console and type "sm version". My guess is that you are using an old version of Sourcemod.

    When you are done translating, could you please post your translations? I will try to make a proper translations file.
    __________________
    dcx2 is offline
    xjango98x
    Junior Member
    Join Date: Nov 2012
    Old 11-01-2012 , 07:40   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #7

    guys if u want to completely negate friendly fire and be able to shoot through them no matter what use this plugin but also use survivor_friendly_fire_factor_(difficulty) 0 and poof! magic! btw i love this plugin but my game crashes while im playing so how do i fix that?

    Last edited by xjango98x; 11-01-2012 at 07:41.
    xjango98x is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 11-01-2012 , 10:20   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #8

    I cannot reproduce the problem with just "it crashes". This plugin gets a lot of use on my own server, so you need to give me more details.

    What version of Sourcemod? What version of SDKHooks? What value do you have for the cvars l4d2_undoff_enable, l4d2_undoff_blockzerodmg, l4d2_undoff_announce, l4d2_undoff_permdmgfrac? What game mode? (campaign, versus?) What difficulty? (normal, expert?)

    Does the server console list any errors when it crashes? Are there any messages in the error log? Does it crash if you leave the friendly fire factor on the default values? Does it still crash if l4d2_undoff_enable is 0?
    __________________
    dcx2 is offline
    xjango98x
    Junior Member
    Join Date: Nov 2012
    Old 11-01-2012 , 18:26   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #9

    ok i have sourcemod 1.9.0 and sdkhook 1.3.0 (couldnt find another one) and it just say "left4dead2.exe has stopped working i also have the undoff with default values except for l4d2_undoff_announce 0 btw thanks for responding so quickly because i love this mod so much

    Last edited by xjango98x; 11-01-2012 at 18:30.
    xjango98x is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 11-01-2012 , 18:38   Re: [L4D2] Undo Friendly Fire (1.3) [2012-Jul-25]
    Reply With Quote #10

    Wait, "left4dead2.exe"? Are you using Sourcemod on the client, instead of using hldsupdatetool to download the dedicated server? If so, that may explain your problem. I only run the dedicated server (srcds.exe). I've heard that running Sourcemod on the client is unstable.

    If I remember right, I'm using Sourcemod 1.4.0. For the record, Sourcemod is currently at version 1.4.6, so your "1.9.0" seems wrong...did you mean metamod? http://www.sourcemod.net/

    Also for the record, SDKHooks is at 2.1. I think you need at least SDKHooks 2.0 in order to have OnTakeDamage for L4D2 (psychonic removed it in 1.3), otherwise this plugin wouldn't even work. You can find the latest SDKHooks in the link in my first post, but I'll post the link here for you again. https://forums.alliedmods.net/showthread.php?t=106748

    In case you're interested in setting up your own L4D2 dedicated server, I recommend crash2004's guide. http://forums.steampowered.com/forum....php?t=1381634

    EDIT:

    I've also been wondering...the original intention of this plugin was to preserve friendly fire in general while taking care of specific situations where a server owner may think that friendly fire shouldn't happen. If you're setting the friendly fire factor to 0, this plugin isn't of very much use, then. With the default settings, the only thing the plugin would do is blocking 0 damage effects (no vocalizations from target, no record of friendly fire in the stats, no recoil when survivor bots shoot through you).
    __________________

    Last edited by dcx2; 11-01-2012 at 18:44.
    dcx2 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 16:47.


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