onDartHit projectile event not registering.

Author Topic: onDartHit projectile event not registering.  (Read 737 times)

Currently no errors found in console. It just doesn't trigger any events when I hit a brick with a dart projectile

Quote
registerInputEvent("fxDTSBrick", "onDartHit", "Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "MiniGame MiniGame");

function fxDTSBrick::onDartHit(%b, %pl, %cl, %pos, %vec) {
   $InputTarget_["Self"] = %b;
   $InputTarget_["Player"] = %pl;
   $InputTarget_["Client"] = %cl;
   $InputTarget_["MiniGame"] = getMiniGameFromObject(%cl);

   %b.processInputEvent("onDartHit", %cl);
}

//Axe & Pickaxe Packages
package onDartHit
{
        //Start Anim
        function WeaponImage::onPreFire(%data,%obj,%slot)
        {
                if(%data.isthrowingdartdirect) //if weapon is one of the new axe's or pickaxe's
                        %obj.playthread(2,armattack); //anim
        }
        //Stop Anim
        function WeaponImage::onStopFire(%data,%obj,%slot)
        {       
                if(%data.isthrowingdartdirect) //if weapon is one of the new axe's or pickaxe's
                        %obj.playthread(2,root); //stop anim
        }
        //Events hook
        function ProjectileData::onCollision(%data,%obj,%col,%fade,%pos,%normal)
        {
                Parent::onCollision(%data,%obj,%col,%fade,%pos,%normal);
                if((%data.isthrowingdartdirect) && %col.getClassName() $= "fxDTSBrick") //if projectile is from one of the new axe's or pickaxe's, and col is a brick
                {
                        $InputTarget_["Self"] = %col;
                        $InputTarget_["Player"] = %obj.client.player;
                        $InputTarget_["Client"] = %obj.client;
                        if($Server::LAN)
                                $InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
                        else
                        {
                                if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
                                        $InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
                                else
                                        $InputTarget_["MiniGame"] = 0;
                        }
                        %name = getWord(%data.uiName,1); //axe/pickaxe type (e.g. Gold)
                        if(%data.isthrowingdartdirect) //if axe
                                eval(%col @ ".processInputEvent(onB" @ %name @ "throwingdartdirect,%obj.client);"); //call axe event
                   
                }
        }
};activatePackage(onDartHit);

This is the whole script.

Quote
//ThrowingDart.cs


datablock AudioProfile(ThrowingDartStickSound)
{
   filename    = "./dartHit.wav";
   description = AudioClosest3d;
   preload = true;
};
datablock AudioProfile(ThrowingdartFireSound)
{
   filename    = "./dartFire.wav";
   description = AudioClosest3d;
   preload = true;
};


//spear trail
datablock ParticleData(ThrowingdartTrailParticle)
{
    dragCoefficient        = 3.0;
    windCoefficient        = 0.0;
    gravityCoefficient    = 0.0;
    inheritedVelFactor    = 0.0;
    constantAcceleration    = 0.0;
    lifetimeMS        = 600;
    lifetimeVarianceMS    = 0;
    spinSpeed        = 10.0;
    spinRandomMin        = -50.0;
    spinRandomMax        = 50.0;
    useInvAlpha        = true;
    animateTexture        = false;
    //framesPerSec        = 1;

    textureName        = "base/data/particles/ring";
    //animTexName        = " ";

    // Interpolation variables
    colors[0]    = "0.75 0.75 0.75 0.3";
    colors[1]    = "0.75 0.75 0.75 0.2";
    colors[2]    = "1 1 1 0.0";
    sizes[0]    = 0.15;
    sizes[1]    = 0.35;
    sizes[2]    = 0.05;
    times[0]    = 0.0;
    times[1]    = 0.5;
    times[2]    = 1.0;
};

datablock ParticleEmitterData(ThrowingdartTrailEmitter)
{
   ejectionPeriodMS = 5;
   periodVarianceMS = 0;

   ejectionVelocity = 0; //0.25;
   velocityVariance = 0; //0.10;

   ejectionOffset = 0;

   thetaMin         = 0.0;
   thetaMax         = 90.0; 

   particles = ThrowingdartTrailParticle;

   useEmitterColors = true;
   uiName = "Throwing dart Trail";
};


//effects
datablock ParticleData(ThrowingdartExplosionParticle)
{
    dragCoefficient      = 8;
    gravityCoefficient   = -0.3;
    inheritedVelFactor   = 0.2;
    constantAcceleration = 0.0;
    lifetimeMS           = 500;
    lifetimeVarianceMS   = 300;
    textureName          = "base/data/particles/cloud";
    spinSpeed        = 10.0;
    spinRandomMin        = -50.0;
    spinRandomMax        = 50.0;
    colors[0]     = "0.5 0.5 0.5 0.9";
    colors[1]     = "0.5 0.5 0.5 0.0";
    sizes[0]      = 0.45;
    sizes[1]      = 0.0;

   useInvAlpha = true;
};

datablock ParticleEmitterData(ThrowingdartExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 3;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "ThrowingdartExplosionParticle";

   useEmitterColors = true;

   uiName = "Throwing dart Smoke";
};

datablock ParticleData(ThrowingdartExplosionParticle 2)
{
    dragCoefficient      = 5;
    gravityCoefficient   = 0.1;
    inheritedVelFactor   = 0.2;
    constantAcceleration = 0.0;
    lifetimeMS           = 500;
    lifetimeVarianceMS   = 300;
    textureName          = "base/data/particles/chunk";
    spinSpeed        = 10.0;
    spinRandomMin        = -50.0;
    spinRandomMax        = 50.0;
    colors[0]     = "0.9 0.9 0.6 0.9";
    colors[1]     = "0.9 0.5 0.6 0.0";
    sizes[0]      = 0.25;
    sizes[1]      = 0.0;
};

datablock ParticleEmitterData(ThrowingdartExplosionEmitter2)
 {
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 80;
   thetaMax         = 80;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "ThrowingdartExplosionParticle 2";

   useEmitterColors = true;
};

datablock ExplosionData(ThrowingdartExplosion)
{
   //explosionShape = "";
   lifeTimeMS = 150;

   soundProfile = ThrowingdartStickSound;

   particleEmitter = ThrowingdartExplosionEmitter2;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = "";

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 2;
       lightEndRadius = 0;
       lightStartColor = "1 0 0";
       lightEndColor = "0 0 0";

   //impulse
   impulseRadius = 0;
   impulseForce = 100;

   //radius damage
   radiusDamage        = 0;
   damageRadius        = 0;
};

datablock ExplosionData(ThrowingdartExplosion2)
{
    //explosionShape = "";
   lifeTimeMS = 150;

   emitter[0] = ThrowingdartExplosionEmitter;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "7.0 8.0 7.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 15.0;

   // Dynamic light
       lightStartRadius = 0;
       lightEndRadius = 1;
       lightStartColor = "0.3 0.6 0.7";
       lightEndColor = "0 0 0";

   //impulse
   impulseRadius = 0;
   impulseForce = 100;

   //radius damage
   radiusDamage        = 0;
   damageRadius        = 0;
};



//projectile
AddDamageType("ThrowingdartDirect",   '<bitmap:add-ons/Weapon_Throwing_dart/CI_dart> %1',       '%2 <bitmap:add-ons/Weapon_Throwing_dart/CI_dart> %1',1,1);

datablock ProjectileData(ThrowingdartProjectile)
{
   projectileShapeName = "./dartProjectile.dts";

   directDamage        = 1;
   directDamageType    = $DamageType::ThrowingdartDirect;

   radiusDamage        = 0;
   damageRadius        = 0;
   radiusDamageType    = $DamageType::ThrowingdartDirect;

   explosion             = ThrowingdartExplosion2;
   stickExplosion        = ThrowingdartExplosion;
   bloodExplosion        = ThrowingdartExplosion2;
   particleEmitter       = ThrowingdartTrailEmitter;
   explodeOnPlayerImpact = true;
   explodeOnDeath        = true; 

   armingDelay         = 8000;
   lifetime            = 8000;
   fadeDelay           = 8000;

   isBallistic         = true;
   bounceAngle         = 170; //stick almost all the time
   minStickVelocity    = 10;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;   
   gravityMod = 1;


   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 0 0.5";

   muzzleVelocity      = 14;
   velInheritFactor    = 1;

   uiName = "Dart";
};

package ThrowingdartPackage
{
   
    function ThrowingdartProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
    {
        serverPlay3D(ThrowingdartExplosionSound,%obj.getTransform());
        parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
    }
    function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
    {
        if(%col.dataBlock $= "ThrowingdartItem" && %col.canPickup)
        {
            for(%i=0;%i<%this.maxTools;%i++)
            {
                %item = %obj.tool[%i];
                if(%item $= 0 || %item $= "")
                {
                    %freeSlot = 1;
                    break;
                }
            }

            if(%freeSlot)
            {
                %obj.pickup(%col);
                return;
            }
        }
        Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
    }
};
activatePackage(ThrowingdartPackage);

//////////
// item //
//////////
datablock ItemData(ThrowingdartItem)
{
    category = "Weapon";  // Mission editor category
    className = "Weapon"; // For inventory system

     // Basic Item Properties
    shapeFile = "./dart.dts";
    mass = 1;
    density = 0.2;
    elasticity = 0.2;
    friction = 0.6;
    emap = true;

    //gui stuff
    uiName = "Throwing Dart";
    iconName = "./icon_Throwing_dart";
    doColorShift = true;
    colorShiftColor = "0.400 0.196 0 1.000";

     // Dynamic properties defined by the scripts
    image = ThrowingdartImage;
    canDrop = true;
};

//function dart::onUse(%this,%user)
//{
//    //mount the image in the right hand slot
//    %user.mountimage(%this.image, $RightHandSlot);
//}

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(ThrowingdartImage)
{
   // Basic Item properties
   shapeFile = "./dart.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   //eyeOffset = "0.1 0.2 -0.55";

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = ThrowingdartItem;
   ammo = " ";
   projectile = ThrowingdartProjectile;
   projectileType = Projectile;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;

   //casing = " ";
   doColorShift = true;
   colorShiftColor = "0.400 0.196 0 1.000";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
        stateName[0]            = "Activate";
    stateTimeoutValue[0]        = 0.1;
    stateTransitionOnTimeout[0]    = "Ready";
    stateSequence[0]        = "ready";
    stateSound[0]                    = weaponSwitchSound;

    stateName[1]            = "Ready";
    stateTransitionOnTriggerDown[1]    = "Charge";
    stateAllowImageChange[1]    = true;
   
    stateName[2]                    = "Charge";
    stateTransitionOnTimeout[2]    = "Armed";
    stateTimeoutValue[2]            = 0.7;
    stateWaitForTimeout[2]        = false;
    stateTransitionOnTriggerUp[2]    = "AbortCharge";
    stateScript[2]                  = "onCharge";
    stateAllowImageChange[2]        = false;
   
    stateName[3]            = "AbortCharge";
    stateTransitionOnTimeout[3]    = "Ready";
    stateTimeoutValue[3]        = 0.3;
    stateWaitForTimeout[3]        = true;
    stateScript[3]            = "onAbortCharge";
    stateAllowImageChange[3]    = false;

    stateName[4]            = "Armed";
    stateTransitionOnTriggerUp[4]    = "Fire";
    stateAllowImageChange[4]    = false;

    stateName[5]            = "Fire";
    stateTransitionOnTimeout[5]    = "Done";
    stateTimeoutValue[5]        = 0.5;
    stateFire[5]            = true;
    stateSequence[5]        = "fire";
    stateScript[5]            = "onFire";
    stateWaitForTimeout[5]        = true;
    stateAllowImageChange[5]    = false;

    stateName[6]                    = "Done";
    stateScript[6]                    = "onDone";


};

function ThrowingdartImage::onCharge(%this, %obj, %slot)
{
    %obj.playthread(2, spearReady);
    %obj.ThrowingdartSlot = %obj.currTool;
}

function ThrowingdartImage::onAbortCharge(%this, %obj, %slot)
{
    %obj.playthread(2, root);

}

function ThrowingDartImage::onDone(%this,%obj,%slot)
{
    %obj.unMountImage(%slot);
}

function ThrowingdartImage::onFire(%this, %obj, %slot)
{
    %obj.playthread(2, ThrowingdartThrow);
    serverPlay3D(ThrowingdartFireSound, %obj.getTransform());
 
    %currSlot = %obj.ThrowingdartSlot;
    %obj.tool[%currSlot] = 0;
    %obj.weaponCount--;
    messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
    serverCmdUnUseTool(%obj.client);

//spread
%projectile = throwingDartprojectile;
%spread = 0.0055;
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x SPC %y SPC %z);
%velocity = MatrixMulVector(%mat, %velocity);
%p = new Projectile()
{
    dataBlock = %projectile;
    initialVelocity = %velocity;
    initialPosition = %obj.getMuzzlePoint(%slot);
    sourceObject = %obj;
    sourceSlot = %slot;
    client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}


Not sure why it's not working.


Does no one know? I'm trying to do it myself but if I don't know how to fix it then I can't fix it.

Your problem is probably at the eval line