Blockland Forums > Suggestions & Requests
Fallout-style hit detection
<< < (3/5) > >>
Crystalwarrior:
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.

--- Code: ---// 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" );


--- End code ---

To use hitboxes, in your projectile's damage:


--- Code: ---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.
   }
}

--- End code ---

Most of the credit goes to our magician Port. He gave me the original support script
Mounds Bar:
*pauses game*
*Aims at person while they are immobilized*
*Fires many shots in slow motion which decapitates them*
Cargøn:

--- Quote from: Mounds Bar on December 07, 2012, 11:00:18 PM ---*pauses game*
*Aims at person while they are immobilized*
*Fires many shots in slow motion which decapitates them*

--- End quote ---
Congratulations. You can read the word "fallout" but not an op.
John Freeman:

--- Quote from: Cargøn on December 08, 2012, 01:45:43 AM ---Congratulations. You can read the word "fallout" but not an op.


--- End quote ---
Shell:

--- Quote from: Cargøn on December 08, 2012, 01:45:43 AM ---Congratulations. You can quote posts while contributing absolutely nothing to the topic.

--- End quote ---
Navigation
Message Index
Next page
Previous page

Go to full version