alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
972 stars 420 forks source link

TakeDamage should trigger TraceAttack when bypassHooks = false #2055

Open eyal282 opened 11 months ago

eyal282 commented 11 months ago

Help us help you

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 commented 11 months ago

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 ] )

Mikusch commented 11 months ago

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.

eyal282 commented 11 months ago

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