function MeleeImage::onFire(%this, %obj, %slot)
{
%obj.setActionThread("rPunch1"); // melee animation
%this.schedule(300, "Melee_attack", %obj);
}
function MeleeImage::Melee_Attack(%this, %obj)
{
%message = "DEBUG:" SPC %obj SPC %obj.getClassName() SPC " Melee Attacks " SPC %this SPC %this.getName();
centerPrintAll( %message, 5, 1);
%Distance = 5; // was 2m
%eyeVec = %obj.getEyeVector();
%startPos = %obj.getEyePoint();
%endPos = VectorAdd(%startPos, VectorScale(%eyeVec, %Distance));
$melee_check2hit =
$TypeMasks::PlayerObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ItemObjectType |
$TypeMasks::ShapeBaseObjectType |
$TypeMasks::ForestObjectType;
%target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);
%col = firstWord(%target);
echo("Target = "@ %target );
if (%col == 0)
return;
//return the ID of what we've hit
echo("Target ID "@ %col
@" is type "@ %col
.getType() );
if (%objType & $TypeMasks::PlayerObjectType)
echo("PlayerObjectType");
else if (%objType & $TypeMasks::VehicleObjectType)
echo("VehicleObjectType");
else if (%objType & $TypeMasks::StaticShapeObjectType)
echo("StaticShapeObjectType");
else if (%objType & $TypeMasks::ItemObjectType)
echo("ItemObjectType");
else if (%objType & $TypeMasks::ShapeBaseObjectType)
echo("ShapeBaseObjectType");
else if (%objType & $TypeMasks::ForestObjectType)
echo("ForestObjectType");
else
{
echo("unknown ObjectType " SPC %objType);
return;
}
// Apply damage to the object all shape base objects
if (%col
.getType() & $TypeMasks::PlayerObjectType ) //$TypeMasks::ShapeBaseObjectType)
{
%dmg = getRandom(1,20);
%col
.damage
(%obj
, %pos, %dmg
, "melee attack");
%vpos = %col.getWorldBoxCenter();
%pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());
%pushDirection = VectorNormalize(%pushDirection);
%pushVec = VectorScale(%pushDirection,1000);
%pushVec= getwords(%pushVec,0,1);
%col.applyImpulse(%vpos, %pushVec);
}
}