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

Solved [L4D2] How should I hook melee damage?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-19-2018 , 03:17   [L4D2] How should I hook melee damage?
Reply With Quote #1

I discovered it's a pain in the ass to hook melee damage, a single melee weapon can produce 3 damage types that aren't included in the default damage types. How to hook melee damage?

Last edited by eyal282; 01-21-2018 at 00:24.
eyal282 is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-19-2018 , 04:17   Re: [L4D2] How should I hook melee damage?
Reply With Quote #2

Are you wanting to hook damage only of the knife to another player or does it have to include entity objects and world? If it's just for other players you can hook player_hurt game event and check against the weapon name to see if it was a weapon_knife.

Edit: didn't see it was for l4d2, I'm not sure if they use the event system for weapon events in a similar way or not so my bad.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.

Last edited by backwards; 01-19-2018 at 04:28.
backwards is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 01-19-2018 , 16:56   Re: [L4D2] How should I hook melee damage?
Reply With Quote #3

Not really sure,

Try using SDKHooks OnTakeDamage

and checking this prop data of the melee weapon they are using
m_strMapSetScriptName (Offset 6116) (Save|Key)(4 Bytes) - melee_script_name

GetEntPropString(iWeapon, Prop_Data, "m_strMapSetScriptName", sBuffer, sizeof(sBuffer));


And i think this is where the weapons them self
Because checking the entity classname will always return weapon_melee
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D

Last edited by Lux; 01-19-2018 at 16:56.
Lux is offline
Uncle Jessie
Member
Join Date: May 2016
Location: Mind Prison
Old 01-20-2018 , 13:25   Re: [L4D2] How should I hook melee damage?
Reply With Quote #4

It does not matter traceattack or takedamage. It's just what I'm using

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

static const String:ENTPROP_MELEE_STRING[]    = "m_strMapSetScriptName";
static const 
String:CLASSNAME_MELEE_WPN[]     = "weapon_melee";

/*
public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damageType, &weapon, Float:damageForce[3], Float:damagePosition[3]) 
{
    if (!IsSurvivor(victim) || !IsSurvivor(attacker))
        return Plugin_Continue;

    decl String:meleeweapon[128];
    GetEdictClassname(inflictor, meleeweapon, sizeof(meleeweapon)); 
    
    if (StrEqual(meleeweapon, "weapon_melee"))
    {
        GetEntPropString(GetPlayerWeaponSlot(attacker, 1), Prop_Data, "m_strMapSetScriptName", meleeweapon, sizeof(meleeweapon));
    }
    
    if(StrEqual(meleeweapon, "baseball_bat"))
    {
        damage = 600.0;
        return Plugin_Changed;
    }
    
    return Plugin_Continue;
}
*/

public OnClientPostAdminCheck(client)
{
    
SDKHook(clientSDKHook_TraceAttackOnTraceMeleeAttack);
}

public 
OnClientDisconnect(client)
{
    
SDKUnhook(clientSDKHook_TraceAttackOnTraceMeleeAttack);
}

public 
Action:OnTraceMeleeAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup)
{
    if (!
IsSurvivor(victim) || !IsSurvivor(attacker) || IsFakeClient(attacker))
        return 
Plugin_Continue;
    
    
decl String:meleeweapon[128];
    
GetEdictClassname(inflictormeleeweaponsizeof(meleeweapon));
    
    if (
StrEqual(meleeweaponCLASSNAME_MELEE_WPN))
    {
        
GetEntPropString(GetPlayerWeaponSlot(attacker1), Prop_DataENTPROP_MELEE_STRINGmeleeweaponsizeof(meleeweapon));
    }
    
    if (
hitgroup 0
    {
        if(
StrEqual(meleeweapon"baseball_bat")) 
        {
            
damage 9000.0;
            return 
Plugin_Changed;
        }
    }
    
    return 
Plugin_Continue;
}

stock bool:IsSurvivor(client)
{
    if (
client && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2)
    {
        return 
true;
    }
    return 
false;


Last edited by Uncle Jessie; 01-21-2018 at 13:53.
Uncle Jessie is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-20-2018 , 19:00   Re: [L4D2] How should I hook melee damage?
Reply With Quote #5

Solved, found it in player_hurt event:

Code:
new String:WepName[50];	
GetEventString(hEvent, "weapon", WepName, sizeof(WepName));

if(StrEqual(WepName, "melee"))
{
// Do stuff
}
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Reply



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 21:24.


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