Raised This Month: $ Target: $400
 0% 

Ham_TakeDamage with FF, Ham_TraceAttack not working correctly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-17-2014 , 07:02   Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #1

I'll start by copy pasting the function I have problems with. This is mostly work by Black Rose, I take very little credit.

Code:
public DelayAttack(TaskData[]) {     new Player = TaskData[0]     new Knife = TaskData[1]     new AttackType = TaskData[2]     new Entity = TaskData[3]         new KnifeData[KnifeDataStructure]     ArrayGetArray(g_Knives, Knife, KnifeData)         new Float:ViewOfs[3], Float:Start[3], Float:End[3], Float:Aim[3]         pev(Player, pev_origin, Start)     pev(Player, pev_view_ofs, ViewOfs)     xs_vec_add(Start, ViewOfs, Start)         velocity_by_aim(Player, 1, Aim)     xs_vec_mul_scalar(Aim, KnifeData[_Range][AttackType], End)     xs_vec_add(Start, End, End)         new Trace, Float:Fraction, bool:Hull                 engfunc(EngFunc_TraceLine, Start, End, DONT_IGNORE_MONSTERS, Player, Trace)     get_tr2(Trace, TR_flFraction, Fraction)             if(Fraction >= 1.0)     {         engfunc(EngFunc_TraceHull, Start, End, DONT_IGNORE_MONSTERS, HULL_HEAD, Player, Trace)         get_tr2(Trace, TR_flFraction, Fraction)         Hull = true     }         if(Fraction >= 1.0)     {           emit_sound(Player, CHAN_WEAPON, KnifeData[_WhiffSound], VOL_NORM, ATTN_NORM, 0, 94)     }     else     {         new HitPlayer = get_tr2(Trace, TR_pHit)                 if(IsPlayer(HitPlayer))         {             new Hitgroup = get_tr2(Trace, TR_iHitgroup)                         new bool:Backstab = isBackstab(Player, HitPlayer)                         new Float:Damage = AttackType == Primary ?                 g_HitgroupPrimary[Hitgroup] * (Float:KnifeData[_Damage][Primary]) :                 g_HitgroupSecondary[Hitgroup] * (Float:KnifeData[_Damage][Secondary]) * (Backstab ? 3.0 : 1.0)                         new DmgBits = KnifeData[_DmgBits][AttackType] ? KnifeData[_DmgBits][AttackType] : DMG_BULLET|DMG_NEVERGIB                         emit_sound(HitPlayer, CHAN_VOICE, g_HitFleshSound[random(sizeof g_HitFleshSound)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)                         new TraceAttack = create_tr2()             if (Hull)                 engfunc(EngFunc_TraceHull, Start, End, DONT_IGNORE_MONSTERS, HULL_HEAD, Player, TraceAttack)             else                 engfunc(EngFunc_TraceLine, Start, End, DONT_IGNORE_MONSTERS, Player, TraceAttack)                             ExecuteHam(Ham_TraceAttack, HitPlayer, Player, 1.0, Aim, TraceAttack, DmgBits)             free_tr2(TraceAttack)                                     if(AttackType == Primary)             {                 emit_sound(Player, CHAN_WEAPON, KnifeData[_SlashSound], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)                 ExecuteHam(Ham_TakeDamage, HitPlayer, Entity, Player, Damage, DmgBits)             }             else             {                 emit_sound(Player, CHAN_WEAPON, KnifeData[_StabSound], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)                 ExecuteHam(Ham_TakeDamage, HitPlayer, Entity, Player, Damage, DmgBits)             }         }     }         free_tr2(Trace) }

The most desirable solution (probably) to my problem is to completely get rid of TakeDamage. That way, I wouldn't need to calculate the hitzone by myself and the mp_friendlyfire cvar should be ignored too, but I'm not exactly sure how CBasePlayer::TraceAttack works (no idea if it calls CBasePlayer::TakeDamage or does the damage in a different fashion). The problem with this, though, is that Ham_TraceAttack alone decides to only deal either 0 or 1 damage to the player regardless of what the damage is (I changed it to 1.0 for testing purposes, but even with 100000.0, it still does 1 or 0 damage). It also looks somehow jerky - there's no animation played on the player that gets hit, etc., but worst of all, if the victim dies, there's no attacker shown in the deathmsg. I have no idea what am I doing wrong.

On the other hand, without Ham_TraceAttack, no hitzones are taken into account (which I can deal with by changing m_LastHitGroup, so that's fine) but no blood is shown, so I'd have to re-create it myself.

With my way, both Ham_TraceAttack and Ham_TraceDamage is used. This creates the blood just fine and also shows the correct hitzone (headshot) in the DeathMsg, which is weird to say the least, since it's done in TraceAttack. It more or less works fine this way, however I'm unable to get rid of the friendly fire restriction. I need knives to deal damage even if mp_friendlyfire is off, as the knives have a special property (KN_CLL_IgnoreFriendlyFire) which would be extremely useful for example on my Banhammer.

If you have any suggestion (either why TraceAttack acts stupid or how to disable the teamfire check in TakeDamage), please tell me.
Backstabnoob is offline
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-17-2014 , 07:05   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #2

PHP Code:
void ClearMultiDamage(void)
{
    
gMultiDamage.pEntity NULL;
    
gMultiDamage.amount    0;
    
gMultiDamage.type 0;
}


//
// ApplyMultiDamage - inflicts contents of global multi damage register on gMultiDamage.pEntity
//
// GLOBALS USED:
//        gMultiDamage

void ApplyMultiDamage(entvars_t *pevInflictorentvars_t *pevAttacker )
{
    
Vector        vecSpot1;//where blood comes from
    
Vector        vecDir;//direction blood should go
    
TraceResult    tr;

    if ( !
gMultiDamage.pEntity )
        return;

    
gMultiDamage.pEntity->TakeDamage(pevInflictorpevAttackergMultiDamage.amountgMultiDamage.type );

You have to call ClearMultiDamage before & ApplyMultiDamage after TraceAttack

Here are the sig :

PHP Code:
bool HookMemoryFunctions( )
{
#ifdef _WIN32
    
g_pClearMultiDamage_Addr Hooker -> MemorySearchFunc_ClearMultiDamage >( "0x33,*,0xA3,*,*,*,*,0xA3,*,*,*,*,0xA3,*,*,*,*,0xC3", ( void* )MDLL_SpawnFALSE );
    
g_pApplyMultiDamage_Addr Hooker -> MemorySearchFunc_ApplyMultiDamage >( "0x8B,*,*,*,*,*,0x85,*,0x74,*,0x8B,*,*,*,*,*,0x8B,*,0x52", ( void* )MDLL_SpawnFALSE );
#else
    
g_pClearMultiDamage_Addr Hooker -> MemorySearchFunc_ClearMultiDamage >( "_Z16ClearMultiDamagev", ( void* )MDLL_SpawnTRUE );
    
g_pApplyMultiDamage_Addr Hooker -> MemorySearchFunc_ApplyMultiDamage >( "_Z16ApplyMultiDamageP9entvars_sS0_", ( void* )MDLL_SpawnTRUE );
#endif

    
return ( g_pClearMultiDamage_Addr != NULL && g_pApplyMultiDamage_Addr != NULL );

(Take them to make the Orpheu files)
__________________

Last edited by bboygrun; 07-17-2014 at 07:09.
bboygrun is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-17-2014 , 07:08   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #3

Strange. Doesn't TraceAttack do that already?
Code:
void CBasePlayer :: TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) {     if ( pev->takedamage )     {         m_LastHitGroup = ptr->iHitgroup;         switch ( ptr->iHitgroup )         {         case HITGROUP_GENERIC:             break;         case HITGROUP_HEAD:             flDamage *= gSkillData.plrHead;             break;         case HITGROUP_CHEST:             flDamage *= gSkillData.plrChest;             break;         case HITGROUP_STOMACH:             flDamage *= gSkillData.plrStomach;             break;         case HITGROUP_LEFTARM:         case HITGROUP_RIGHTARM:             flDamage *= gSkillData.plrArm;             break;         case HITGROUP_LEFTLEG:         case HITGROUP_RIGHTLEG:             flDamage *= gSkillData.plrLeg;             break;         default:             break;         }         SpawnBlood(ptr->vecEndPos, BloodColor(), flDamage);// a little surface blood.         TraceBleed( flDamage, vecDir, ptr, bitsDamageType );         AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );     } }
Backstabnoob is offline
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-17-2014 , 07:10   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #4

Oh, i've edited my post after your post, sorry.

Look at the source code i posted @ApplyMultiDamage

EDIT : You can go here to take a look
__________________

Last edited by bboygrun; 07-17-2014 at 07:11.
bboygrun is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-17-2014 , 07:11   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #5

All that does is call TakeDamage, which I'm already doing.

CBasePlayer::TraceAttack calls AddMultiDamage(), which does this:
Code:
void AddMultiDamage( entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType) {     if ( !pEntity )         return;     gMultiDamage.type |= bitsDamageType;     if ( pEntity != gMultiDamage.pEntity )     {         ApplyMultiDamage(pevInflictor,pevInflictor); // UNDONE: wrong attacker!         gMultiDamage.pEntity    = pEntity;         gMultiDamage.amount     = 0;     }     gMultiDamage.amount += flDamage; }

So in the end TraceAttack should send TakeDamage by itself, but it doesn't. At least not correctly...
I'm not sure what Arkshine's comment means, is it bugged in the CSSDK itself? If it is, that would kinda explain why there's no killer shown in the DeathMsg.


Anyway, seeing that my way is more or less correct, the real question still exists: How to fool TakeDamage so teamplayers can attack each other even if mp_friendlyfire is off? The only solution I can think of is to set mp_friendlyfire to 1 right before the damage and back to 0 after it, but is there anything better that this? It sounds dirty.

Last edited by Backstabnoob; 07-17-2014 at 07:24.
Backstabnoob is offline
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-17-2014 , 07:25   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #6

AddMultiDamage cumulates the damage for an entity, when the entity isn't the same then it calls TakeDamage to apply all the damages cumulated, the proper way to call TraceAttack is the one i told you.
You can take a look at HLSDK, you will always see :

ClearMultiDamage --> TraceAttack --> ApplyMultiDamage

Connor already did a plugin for that if i am correct, take a look at it
__________________

Last edited by bboygrun; 07-17-2014 at 07:30.
bboygrun is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-17-2014 , 07:27   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #7

Like I said, all ApplyMultiDamage does is call TakeDamage. I can simply execute Ham_TakeDamage (like I do) and it will do the same thing plus I won't need a dependency (Orpheu). I'm doing pretty much the exactly same thing TraceAttack does. In fact, TraceAttack should do this by itself apparently, but it's bugged (it doesn't pass the attacker in the ApplyMultiDamage call).

Last edited by Backstabnoob; 07-17-2014 at 07:28.
Backstabnoob is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-17-2014 , 15:13   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #8

2 things.

1) https://github.com/Arkshine/CSSDK/bl.../wpn_knife.cpp
2)
PHP Code:
        ClearMultiDamage();

        if( 
m_flNextPrimaryAttack 0.4 UTIL_WeaponTimeBase() )
            
pEntity->TraceAttackm_pPlayer->pev20gpGlobals->v_forward, &trDMG_NEVERGIB DMG_BULLET );
        else
            
pEntity->TraceAttackm_pPlayer->pev15gpGlobals->v_forward, &trDMG_NEVERGIB DMG_BULLET );

        
ApplyMultiDamagem_pPlayer->pevm_pPlayer->pev ); 
Will go step by step.

First:
Quote:
Like I said, all ApplyMultiDamage does is call TakeDamage.
No I wont, you're not reseting ClearMultiDamage variables, so what about if you were the last attacker? The last AddMultiDamage will set your index as the last attacker, and this condition:

PHP Code:
if ( pEntity != gMultiDamage.pEntity 
Will throw false.

Second:

Quote:
I'm doing pretty much the exactly same thing TraceAttack does.
No lol, again... see above

Third:

Quote:
I'm not sure what Arkshine's comment means, is it bugged in the CSSDK itself?
It's not Arkshine's comment. As a plugin approver you must at least know some HLSDK basic coding.

dlls/weapons.cpp
PHP Code:
ApplyMultiDamage(pevInflictor,pevInflictor); // UNDONE: wrong attacker! 
*MultiDamage functions were created firstly for handling shotgun shots and any other kind of multi-fire weapon. TraceAttack won't work without these functions, or it will work buggy.

In conclusion, you'll have to use them. I use Orpheu for hooking ApplyMultiDamage and ClearMultiDamage, nothing is wrong with them, about your "dependency" it's something.

Also, if you want to make fool TakeDamage when mp_friendlyfire is 0, you'll have to done a code like FFA does. (changing m_iTeam offset)
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-17-2014 , 15:43   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #9

No I didn't have to use them. You probably didn't read my post properly, but I clearly said that using Ham_TraceAttack first and then Ham_TakeDamage works perfectly but I'm unable to deal damage to my team mates. I got around this by setting mp_friendlyfire to 0 and then back, as changing the team didn't take other effects into account (friendly fire warning, reduced damage), which I wanted to remain.

I didn't have to use ClearMultiDamage at all. I never saw anyone do that to process damage on a player. Why should my plugin be an exception? It works great as it is without it.

Quote:
It's not Arkshine's comment. As a plugin approver you must at least know some HLSDK basic coding
What the hell is that for? First off, as a plugin approver, you need to know how to approve plugins. You don't need to know if a comment in a CSSDK file was made by Valve or the guy who put the whole thing up. The whole rank is called "AMXX Plugin Approver", it's not called "AMXX Plugin Approver that perfectly knows who wrote every single comment in HLSDK and who knows how the game engine works exceptionally". Secondly, ApplyMultiDamage is called with pevInflictor twice rather than the inflictor and the attacker. Using Ham_TraceAttack alone made the player kill himself instead of properly showing the killer, which kinda makes sense if it's like that and no killer is passed.

About dependencies, yeah, it matters. You're looking at this from a programmer's perspective, not from a perspective of an average admin that just wants to have his things going without possibly breaking on CS updates. I'm not going to require Orpheu just because of one feature, especially if it works fine as it is.

In conclusion, please stop posting in my threads with that attitude. You're being overly self centered and arrogant. If you have a need to attack people constantly then feel free to, but don't do so in my threads, thanks.
Backstabnoob is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-17-2014 , 17:31   Re: Ham_TakeDamage with FF, Ham_TraceAttack not working correctly
Reply With Quote #10

Well, you are also being stubborn. Plus, I see nothing rude from him (though what you quoted was unnecessary), he's actually helping you... Maybe you should calm down a bit, and trying to review how work things.

Anyway, what he said should be correct. You may not see at first glance any problems, but at some point you are not going to have reliable damage. By calling TraceAttack, you accumulate damage for a same entity. If you call TakeDamage wihtout clearing global multi-damage, once TraceAttack is called again but with another entity, The previous entity will take most likely and again the accumulated damage with different inflictor.
This is not for nothing you have such code for the knife for example:

Code:
		ClearMultiDamage();
		pEntity->TraceAttack(m_pPlayer->pev, flDamage, gpGlobals->v_forward, &tr, DMG_NEVERGIB | DMG_BULLET);
		ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);
__________________

Last edited by Arkshine; 07-17-2014 at 17:32.
Arkshine 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 13:02.


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