sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

TakeDamage should trigger TraceAttack when bypassHooks = false

Open eyal282 opened this issue 2 years ago • 3 comments

Help us help you

  • [ x] I have checked that my issue doesn't exist yet.
  • [ x] I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
  • [ x] I can always reproduce the issue with the provided description below.

Problematic Code (or Steps to Reproduce)

Plugin A ( RPG-Perks, a damage handling plugin )


// I suspect fall damage is fully ignored in these functions.
public Action Event_TakeDamage(int victim, int& attacker, int& inflictor, float& damage, int& damagetype)
{		
	if(RPG_Perks_GetZombieType(victim) == ZombieType_Invalid)
		return Plugin_Continue;

	else if(damage == 0.0)
		return Plugin_Continue;

	else if(!SurvivorVictimNextBotAttacker(victim, attacker) && !(damagetype & DMG_BURN) && !(damagetype & DMG_FALL) && !IsDamageToSelf(victim, attacker) && !IsPinDamage(victim, attacker))
		return Plugin_Continue;


	float fFinalDamage = damage;

	Action rtn = RPG_OnTraceAttack(victim, attacker, inflictor, fFinalDamage, damagetype, 0, 0);

	damage = fFinalDamage;

	return rtn;
	
}

// Trace Attack does not trigger with common on survivor violence. ACCOUNT FOR IT.
public Action Event_TraceAttack(int victim, int& attacker, int& inflictor, float& damage, int& damagetype, int& ammotype, int hitbox, int hitgroup)
{	
	if(RPG_Perks_GetZombieType(victim) == ZombieType_Invalid)
		return Plugin_Continue;

	else if(damage == 0.0)
		return Plugin_Continue;

	else if(SurvivorVictimNextBotAttacker(victim, attacker) || damagetype & DMG_BURN || damagetype & DMG_FALL || IsDamageToSelf(victim, attacker) || IsPinDamage(victim, attacker))
		return Plugin_Continue;

	float fFinalDamage = damage;

	Action rtn = RPG_OnTraceAttack(victim, attacker, inflictor, fFinalDamage, damagetype, hitbox, hitgroup);

	damage = fFinalDamage;

	// Only on trace attack
	if(rtn == Plugin_Continue)
		rtn = Plugin_Changed;

	return rtn;
}

Plugin B, a damage sending plugin

SDKHooks_TakeDamage(pinner, inflictor, attacker, damage, damagetype, _, _, _, false);

TraceAttack is generally more useful to catch involving player on player violence on things like blood, slow, etc..., so swapping to TakeDamage is not very good ( I also want to increase the chances my plugin goes first when detecting and modifying damage )

I need one of three things:

  1. Ability to tell on "SDKHook_TakeDamage" when bypassHooks was used with the sending function (SDKHooks_TakeDamage)
  2. SDKHook_TakeDamageBypassHooks
  3. Make bypass hooks also send a TraceAttack with as many relevant parameters as possible ( hitgroup & hitbox set to 0 = "GENERIC")

eyal282 avatar Oct 01 '23 10:10 eyal282

Note: I obviously don't want every plugin on earth to be fully compatible with my damage handling plugin via natives and forwards, but this interaction messes with me in a special way.

Second note: If your plugin tries to detect a TraceAttack ( because Plugin B attempts to replicate a charger punching a jockey [ SDKHooks_TakeDamage is exclusively meant to replicate client damaging another ] )

eyal282 avatar Oct 01 '23 10:10 eyal282

This isn't going to happen, since the call order doesn't make sense. TraceAttack usually calls OnTakeDamage, not the other way around. You could SDKCall CBaseEntity::DispatchTraceAttack manually to achieve what you want.

Mikusch avatar Oct 01 '23 13:10 Mikusch

This isn't going to happen, since the call order doesn't make sense. TraceAttack usually calls OnTakeDamage, not the other way around. You could SDKCall CBaseEntity::DispatchTraceAttack manually to achieve what you want.

It is unreasonable to ask a developer to do this. If this won't happen in Sourcemod the devs are screwed basically.

When I said "Make bypass hooks also send a TraceAttack with as many relevant parameters as possible ( hitgroup & hitbox set to 0 = "GENERIC")

I meant also. Means on top of sending a TakeDamage, it will also send a TraceAttack. Because you said the obvious, indeed TraceAttack calls TakeDamage, this means SDKHooks_TakeDamage will call TraceAttack, then immediately afterwards call TakeDamage

eyal282 avatar Oct 02 '23 10:10 eyal282