Check out my Glock18 and Musket, they already have hitbox detection that can detect practically any bodypart.
Here's the code with isLegShot and isHeadShot, looking at %test variable will give you an idea on how to add new functions.
// Hitbox Detection
function isHeadShot( %list )
{
%list = "\t" @ %list @ "\t";
%test = "plume triPlume septPlume visor helmet pointyHelmet flareHelmet scoutHat bicorn copHat knitHat headSkin";
%cnt = getWordCount( %test );
for ( %i = 0 ; %i < %cnt ; %i++ )
{
%word = "\t" @ getWord( %test, %i ) @ "\t";
if ( striPos( %list, %word ) >= 0 )
{
return true;
}
}
return false;
}
//I'm thinking of modifying it a little bit so it returns which hitbox has been hit instead of just returning "true" so it only would require one function.
function isLegShot( %list )
{
%list = "\t" @ %list @ "\t";
%test = "rshoe rpeg lshoe lpeg pants skirtHip skirtTrimRight skirtTrimLeft";
%cnt = getWordCount( %test );
for ( %i = 0 ; %i < %cnt ; %i++ )
{
%word = "\t" @ getWord( %test, %i ) @ "\t";
if ( striPos( %list, %word ) >= 0 )
{
return true;
}
}
return false;
}
function Player::getLastImpactPosition( %this )
{
return $_detectHitboxPosition;
}
function getLastImpactPosition()
{
return $_detectHitboxPosition;
}
function getHitbox( %obj, %col, %pos )
{
$_detectHitboxActive = true;
$_detectHitboxList = "";
$_detectHitboxPosition = %pos;
paintProjectile::onCollision( "", %obj, %col, "", %pos, "" );
cancel( %col.tempColorSchedule );
%list = trim( $_detectHitboxList );
deleteVariables( "$_detectHitbox*" );
if ( ( %col.getType() & $TypeMasks::PlayerObjectType ) && isObject( %cl = %col.client ) )
{
%cl.applyBodyColors();
%cl.applyBodyParts();
}
return %list;
}
package hitboxDetection
{
function shapeBase::setNodeColor( %this, %node, %color )
{
if ( $_detectHitboxActive )
{
$_detectHitboxList = trim( $_detectHitboxList TAB %node );
return;
}
parent::setNodeColor( %this, %node, %color );
}
};
activatePackage( "hitboxDetection" );
To use hitboxes, in your projectile's damage:
function FlyingPigsProjectile::damage(%this, %obj, %col, %fade, %pos, %normal)
{
%damage = %this.directDamage;
%headshot = isHeadShot( getHitbox( %obj, %col, %pos ) );
%legshot = isLegShot( getHitBox( %obj, %col, %pos ) );
//add those two at the beginning for convenience.
if ( %headshot )
{
%damageType = $DamageType::CarrotHeadshot;
%col.playThread( "headUp" );
%damage *= 3;
}
else
if ( %legshot )
{
%damage /= 1.5;
// tumble(%col);
}
%col.damage( %obj, %pos, %damage, %this.directDamageType );
if ( %headshot && %col.getState() $= "Dead" )
{
%col.setNodeColor( "headSkin", "1 0 0 1" );
//colors the head red, duh.
}
}
Most of the credit goes to our magician Port. He gave me the original support script