Skip to content

Conversation

Bitl
Copy link
Contributor

@Bitl Bitl commented Aug 24, 2025

Description

One commonly reported Source issue is one related to melee hit registration. If you swing a bat and it hit a teammate, intending to hit the enemy behind the teammate, it will hit the teammate instead of the enemy, which makes melee weapons feel unresponsive. There was a fix for this issue introduced for MvM bots, but not for players. This code changes this line of code to ONLY hit teammates if friendly fire (mp_friendlyfire) is enabled. This uses a custom trace filter, meaning that special instances (such as Disciplinary Action hits and PASS Time steals) function as expected.

One side effect of this is that MvM bots can now use the Disciplinary Action properly as well, since the code works for both bots and player

For TF, there are multiple ways to restore the original behavior:

  1. The tf_melee_old_trace_behavior ConVar (Global)
  2. The SetOldMeleeTrace VScript function in CTFPlayer, intended to be used on the owner of the melee weapon (Player)
  3. The set_old_melee_trace_behavior static attribute (Player/Weapon)

SourceMod plugins could also hook into the CTFPlayerShared::SetOldMeleeTrace function as well.

For HL2MP, it reuses the CTraceFilterIgnoreTeammates filter from TF and implements it in a similar way.

@Bitl
Copy link
Contributor Author

Bitl commented Aug 24, 2025

note that this is a basic implementation, and doesn't consider other teammate related on hit events, so this is marked as a draft until this is fixed.

@Bitl Bitl marked this pull request as draft August 24, 2025 23:08
@Bitl
Copy link
Contributor Author

Bitl commented Aug 25, 2025

This PR now functions as expected. Here's a demo video about it!

https://www.youtube.com/watch?v=J-2n-fbAOq8
revised melee hit fix

@Bitl Bitl marked this pull request as ready for review August 25, 2025 01:41
@Bitl Bitl changed the title [TF] Fix melee hit registration [ALL] Fix melee hit registration Aug 25, 2025
@Bitl
Copy link
Contributor Author

Bitl commented Aug 25, 2025

Implemented a HL2MP version

@Gavitro
Copy link

Gavitro commented Aug 25, 2025

// In MvM, melee hits from the robot team wont hit teammates to ensure mobs of melee bots don't swarm so tightly they hit each other and no-one else
bool bDontHitTeammates = pPlayer->GetTeamNumber() == TF_TEAM_PVE_INVADERS && TFGameRules()->IsMannVsMachineMode();
CTraceFilterIgnoreTeammates ignoreTeammatesFilter( pPlayer, COLLISION_GROUP_NONE, pPlayer->GetTeamNumber() );

I would not remove or replace this code, because some plugins/vscripts abuse it in order to bypass teammates.

@Bitl
Copy link
Contributor Author

Bitl commented Aug 25, 2025

that code is no longer needed since the majority of melee weapons don't have the listed exceptions (since very few melee weapons have on hit attributes for teammates) However, I'll possibly make it so that you could switch back to the original behavior using vscript

@Bitl Bitl changed the title [ALL] Fix melee hit registration [ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) Aug 25, 2025
@Bitl
Copy link
Contributor Author

Bitl commented Aug 25, 2025

There are now 3 ways to set the old melee behavior:

  1. The tf_melee_old_trace_behavior ConVar (Global)
  2. The SetOldMeleeTrace VScript function in CTFPlayer, intended to be used on the owner of the melee weapon (Player)
  3. The set_old_melee_trace_behavior static attribute (Player/Weapon)

SourceMod plugins could also hook into the CTFPlayerShared::SetOldMeleeTrace function as well.

@JoriKos
Copy link

JoriKos commented Aug 27, 2025

This is a balance decision, not a bug. Also being able to not hit teammates anymore would be very very badly received by the community as well as make Spychecking even easier (making Spy much weaker when he already is very weak)

@Bitl
Copy link
Contributor Author

Bitl commented Aug 27, 2025

this absolutely isn't a balance decision. it's a bug. even if it isn't one, it's genuinely annoying to hit your teammates during combat. for example: if you're playing as demoknight and a teammate goes in front of you while you're charging into an enemy, the teammate will tank the sword damage, which frustrates the demoknight player. in contrast: many hitscan and projectile weapons pass through teammates, and it only makes sense that melee weapons should also be treated the same way. spychecking can already be done by shooting your teammates or using a flamethrower. this change only lines up with how teammates should react when someone's shooting projectiles.

this also wouldn't be negatively received by the community, as a bunch of larger figures have expressed the same problems. this is a reason i added a toggle convar to it, for server owners that prefer the older melee hit registration.

this PR also does not prevent every instance of teammate hits, as this PR makes it so the Disciplinary Action and PASS time mechanics will function normally, as well as the unused add_give_health_to_teammate_on_hit attribute.

@JoriKos
Copy link

JoriKos commented Aug 27, 2025

This absolutely isn't a balance decision

I don't see why it wouldn't be.

it's genuinely annoying to hit your teammates during combat.

It's annoying but necessary, the same applies to autobalance and projectiles being consumed by teammates. It would be stupid to suddenly be hit by a projectile that you physically couldn't see coming, similar to being hit by melee you can't even see. It's just something necessary, but annoying.

spychecking can already be done by shooting your teammates or using a flamethrower

Exactly, so why make it even easier to check? I've had times with people have hit me once and then because I didn't react they didn't think I was suspicious. Now it would be really obvious because you hear the melee sound that otherwise doesn't play.

a bunch of larger figures have expressed the same problems

Doesn't mean they're right though, they just say it's annoying but removing hits on teammates would 100% be a very unpopular decision that gets removed within a week. Some community figures also call for Quickplay back but they're objectively wrong when they say it's an improvement. Just because someone has a large subscriber/view count doesn't mean they are more correct.

this PR also does not prevent every instance of teammate hits

Those aren't the hits I'm talking about. Not having teammate hits actually removes a lot of silly interactions.

@Bitl
Copy link
Contributor Author

Bitl commented Aug 27, 2025

With some re-evaluation, yeah this is a balance change. I'll mark this PR as a modding resource for those who want to implement this functionality in their mods

@Bitl Bitl changed the title [ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) [SDK modding resource - ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) Aug 27, 2025
@Bitl Bitl changed the title [SDK modding resource - ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) [Modding Resource - ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) Aug 27, 2025
@Bitl
Copy link
Contributor Author

Bitl commented Sep 8, 2025

I decided to revert the modding resource tag and decided to stick with my original opinion and it won't be changed any longer

@Bitl Bitl changed the title [Modding Resource - ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) [ALL] Fix melee hits erroneously hitting teammates (with support for on hit attributes) Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants