1. function MeleeImage::onFire(%this, %obj, %slot)
  2. {
  3.     %obj.setActionThread("rPunch1"); // melee animation
  4.  
  5.     %this.schedule(300, "Melee_attack", %obj);
  6. }
  7.  
  8. function MeleeImage::Melee_Attack(%this, %obj)
  9. {
  10.    %message = "DEBUG:" SPC %obj SPC %obj.getClassName() SPC " Melee Attacks " SPC %this SPC %this.getName();
  11.    centerPrintAll( %message, 5, 1);
  12.    
  13.    %Distance = 5; // was 2m
  14.    
  15.    %eyeVec = %obj.getEyeVector();
  16.  
  17.    %startPos = %obj.getEyePoint();
  18.    %endPos = VectorAdd(%startPos, VectorScale(%eyeVec, %Distance));
  19.      
  20.   $melee_check2hit =
  21.     $TypeMasks::PlayerObjectType |
  22.     $TypeMasks::VehicleObjectType |    
  23.     $TypeMasks::StaticShapeObjectType |
  24.     $TypeMasks::ItemObjectType |
  25.     $TypeMasks::ShapeBaseObjectType |
  26.     $TypeMasks::ForestObjectType;
  27.      
  28.    %target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);
  29.    %col = firstWord(%target);
  30.  
  31.    echo("Target = "@ %target );
  32.      
  33.     if (%col == 0)
  34.         return;
  35.    
  36.    //return the ID of what we've hit
  37.    echo("Target ID "@ %col @" is type "@ %col.getType() );
  38.    
  39.    %objType = %col.getType();
  40.    if (%objType & $TypeMasks::PlayerObjectType)
  41.      echo("PlayerObjectType");    
  42.    else if (%objType & $TypeMasks::VehicleObjectType)
  43.      echo("VehicleObjectType");
  44.    else if (%objType & $TypeMasks::StaticShapeObjectType)
  45.      echo("StaticShapeObjectType");        
  46.    else if (%objType & $TypeMasks::ItemObjectType)
  47.      echo("ItemObjectType");
  48.    else if (%objType & $TypeMasks::ShapeBaseObjectType)
  49.      echo("ShapeBaseObjectType");    
  50.    else if (%objType & $TypeMasks::ForestObjectType)
  51.      echo("ForestObjectType");
  52.    else
  53.    {
  54.      echo("unknown ObjectType " SPC %objType);    
  55.      return;
  56.    }
  57.          
  58.       // Apply damage to the object all shape base objects
  59.     if (%col.getType() & $TypeMasks::PlayerObjectType ) //$TypeMasks::ShapeBaseObjectType)
  60.     {
  61.        %dmg = getRandom(1,20);
  62.         %col.damage(%obj, %pos, %dmg, "melee attack");   
  63.            
  64.         %vpos = %col.getWorldBoxCenter();
  65.         %pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());
  66.         %pushDirection = VectorNormalize(%pushDirection);
  67.  
  68.         %pushVec = VectorScale(%pushDirection,1000);
  69.         %pushVec= getwords(%pushVec,0,1);
  70.         %col.applyImpulse(%vpos, %pushVec);
  71.     }
  72. }