Author Topic: Hammer edit always spawns emitter?  (Read 723 times)

Sorry if this is a nooby question, haven't done weapons in Blockland or even coded for it at all for some time.
I'm trying to make an edit of the hammer item, but white. Whenever I swing the hammer, it always spawns the hit emitter even if I haven't hit anything. How do I stop this? Also, it won't make any sounds.

if(!isObject(SpaceAxeItem))
{
   datablock ItemData (SpaceAxeItem : HammerItem)
   {
      uiName         = "Space Axe";
      image         = SpaceAxeImage;
      canDrop         = true;

      doColorShift   = true;
      colorShiftColor = "0.9 0.9 0.9 1";
   };

   datablock ShapeBaseImageData(SpaceAxeImage : HammerImage)
   {

      item         = SpaceAxeItem;
      showBricks = false;
      doColorShift   = true;
      colorShiftColor = "0.9 0.9 0.9 1";
   };
}

//Functions
function SpaceAxeImage::onPreFire(%this, %obj, %slot)
{
   %obj.playthread(2, armAttack);
}

function SpaceAxeImage::onStopFire(%this, %obj, %slot)
{   
   %obj.playthread(2, root);
}

function SpaceAxeImage::onHitObject(%this, %obj, %slot, %col, %pos, %normal)
{
   talk("This doesn't work :(. Can anyone figure out why? I think this only works for raycasts or something, right?");
   parent::onHitObject(%this, %obj, %slot, %col, %pos, %normal);
}

this requires the code for HammerImage::onHitObject to properly debug. Hammer code is special since it uses raycasts and kills bricks unlike other projectile weapons. Im gonna guess that something is going wrong with the raycast distance

It's probably the fact that Hammer uses a custom ::onFire function and calls the onHitObject when using its own raycast

It's probably the fact that Hammer uses a custom ::onFire function and calls the onHitObject when using its own raycast

Code: allGameScripts.cs (46 lines)
function HammerImage::onFire(%this, %player, %slot)
{
    %start = %player.getEyePoint();
    %muzzleVec = %player.getMuzzleVector(%slot);
    %muzzleVecZ = getWord(%muzzleVec, 2);

    if(%muzzleVecZ < -0.9)
        %range = 5.5;
    else
        %range = 5;

    %vec = vectorScale(%muzzleVec, (%range * getWord(%player.getScale(), 2)));
    %end = vectorAdd(%start, %vec);
    %mask =
        $TypeMasks::FxBrickAlwaysObjectType |
        $TypeMasks::PlayerObjectType |
        $TypeMasks::VehicleObjectType |
        $TypeMasks::StaticShapeObjectType |
        $TypeMasks::StaticObjectType;

    if(%player.isMounted())
        %raycast = containerRayCast(%start, %end, %mask, %player, %player.getObjectMount());
    else
        %raycast = containerRayCast(%start, %end, %mask, %player);

    if(!%raycast)
        return;

    %hitObj = getWord(%raycast, 0);
    %hitPos = getWords(%raycast, 1, 3);
    %hitNormal = getWords(%raycast, 4, 6);
    %projectilePos = vectorSub(%hitPos, vectorScale(%player.getEyeVector(), 0.25));

    %p = new Projectile() {
        datablock       = HammerProjectile;
        initialVelocity = %hitNormal;
        initialPosition = %projectilePos;
        sourceObject    = %player;
        sourceSlot      = %slot;
        client          = %client;
    };

    %p.setScale(%player.getScale());
    MissionCleanup.add(%p);
    %this.onHitObject(%player, %slot, %hitObj, %hitPos, %hitNormal);
}


this one?
« Last Edit: April 04, 2016, 07:25:45 AM by Zeblote »