After doing some research I thought about trying to use traceray, but I can't exactly figure out how to get the result I'm looking for.
I'm brand new to sourcepawn (like... within the last 3 hours) and I can't seem to find exactly what I'm looking for.
Inside of a "Public OnW3TakeDmgBulletPre(victim,attacker,Float:da mage)" (this is obviously a war3 mod server) I need to check if the damage dealt is penetration damage.
I figured I could accomplish this using a traceray to check if it ends at a non-player object before hitting a player, or if the first thing it encounters is a non-player object.
I'm not familiar enough with traceray to know exactly how to do it.
This is what I currently have:
Code:
Public OnW3TakeDmgBulletPre(victim,attacker,Float:damage)
{
GetClientEyePosition(client, vecClientEyePos); // Get the position of the player's eyes
GetClientEyeAngles(client, vecClientEyeAng); // Get the angle the player is looking
//Check for colliding entities
TR_TraceRayFilter(vecClientEyePos, vecClientEyeAng, MASK_SOLID, RayType_EndPoint, TraceRayDontHitSelf, client);
if(TR_DidHit(INVALID_HANDLE))
{
new TRIndex = TR_GetEntityIndex(INVALID_HANDLE);
PrintToChatAll("Entity Found %i", TRIndex);
}
}
public bool:TraceRayDontHitSelf(entity, mask, any:data)
{
if(entity == data) // Check if the TraceRay hit the itself.
{
return false // Don't let the entity be hit
}
return true // It didn't hit itself
}
One thought I had is can you use the TR_DidHit to check if it hits a hitbox?
Another thought I had is can I do two tracerays (e.g. one on hitbox and one on solids) and see if the solid ends before the hitbox (thus it must be a penetration hit).
Any help is greatly appreciated. Sorry if this is confusing in any way, I am quite tired right now.
Edit: I learned how to do handles and this is what I have now, no idea if it works or not.
It should trace a ray to a player hitbox, then trace a ray to a solid object. If the traceray doesn't hit the player hitbox, then hopefully it will work.
Code:
Public OnW3TakeDmgBulletPre(victim,attacker,Float:damage)
{
if(RaceDisabled)
{
return;
}
if(race==thisRaceID)
{
GetClientEyePosition(client, vecClientEyePos); // Get the position of the player's eyes
GetClientEyeAngles(client, vecClientEyeAng); // Get the angle the player is looking
//Check for colliding entities
TR_TraceRayFilter(vecClientEyePos, vecClientEyeAng, MASK_SOLID, RayType_Infinity, TraceRayDontHitSelf, client);
new Handle:trace = TR_TraceRayFilter(vecClientEyePos, vecClientEyeAng, CONTENTS_HITBOX, RayType_Infinity, TraceRayDontHitSelf, client);
if(!TR_DidHit(trace))
{
War3_DealDamage(victim,war3_dealdamagelevel(client,thisRaceID,Penetration),client,DMG_BURN,"stim pack",W3DMGORIGIN_SKILL);
new TRIndex = TR_GetEntityIndex(INVALID_HANDLE);
new TRIndex2 = TR_GetEntityIndex(trace);
PrintToChatAll("Entity Found %i, hitbox found %i", TRIndex, TRIndex1);
}
}
public bool:TraceRayDontHitSelf(entity, mask, any:data)
{
if(RaceDisabled)
{
return;
}
if(race==thisRaceID)
{
if(entity == data) // Check if the TraceRay hit the itself.
{
return false // Don't let the entity be hit
}
return true // It didn't hit itself
}