Author Topic: Laser Sights  (Read 804 times)

Ok, Space Guy told me that if I wanted more help, i'd have to make a topic in coding help.

Well, I did it.

Let's get to the point, I've used the script Space told me to.

Well, it just enables the Laser Sights when I fire the weapon.

Halp?

You have to set the state that initializes the laser sight when the weapon is mounted.

I actually did that.

Code: [Select]
//audio
datablock AudioProfile(M16FireSound)
{
   filename    = "./M16_Fire.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(M16EquipSound)
{
   filename    = "./M16_Equip.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(M16ReloadSound)
{
   filename    = "./M16_ClipOut.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(M16Reload2Sound)
{
   filename    = "./M16_ClipIn.wav";
   description = AudioClose3d;
   preload = true;
};

datablock ParticleData(M16PointParticleA)
{
   dragCoefficient      = 5;
   gravityCoefficient   = -0.0;
   inheritedVelFactor   = 1.0;
   constantAcceleration = 0.0;
   lifetimeMS           = 10;
   lifetimeVarianceMS   = 0;
   textureName          = "base/data/particles/dot";
   spinSpeed           = 0.0;
   spinRandomMin        = 0.0;
   spinRandomMax        = 0.0;
   colors[0]     = "1 1 0 0.9";
   colors[1]     = "1 0 0 0.9";
   colors[2]     = "1 0 0 0";

   sizes[0]      = 0.15;
   sizes[1]      = 0.15;
   sizes[2]      = 0.3;

   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;

   useInvAlpha = false;
};

datablock ParticleEmitterData(M16PointEmitterA)
{
   ejectionPeriodMS = 5;
   periodVarianceMS = 1;
   ejectionVelocity = 0.1;
   velocityVariance = 0.0;
   ejectionOffset   = 0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "M16PointParticleA";

   useEmitterColors = true;

   uiName = "880 Rifle Laser A";
};

datablock ParticleData(M16PointParticleB)
{
   dragCoefficient      = 0;
   gravityCoefficient   = -0.0;
   inheritedVelFactor   = 1.0;
   constantAcceleration = 0;
   lifetimeMS           = 600;
   lifetimeVarianceMS   = 0;
   textureName          = "base/data/particles/dot";
   spinSpeed           = 0.0;
   spinRandomMin        = 0.0;
   spinRandomMax        = 0.0;
   colors[0]     = "1 1 0 0.9";
   colors[1]     = "1 0 0 0.9";
   colors[2]     = "1 0 0 0";

   sizes[0]      = 0.1;
   sizes[1]      = 0.1;
   sizes[2]      = 0.1;

   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;

   useInvAlpha = false;
};

datablock ParticleEmitterData(M16PointEmitterB)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = -1.5;
   velocityVariance = 0.0;
   ejectionOffset   = 0;
   thetaMin         = 0;
   thetaMax         = 0;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "M16PointParticleB";

   useEmitterColors = true;

   uiName = "880 Rifle Laser B";
};

datablock DebrisData(M16PointDebris)
{
   emitters = "M16PointEmitterA";

    shapeFile = "base/data/shapes/empty.dts";
    lifetime = 0.02;
    minSpinSpeed = -300.0;
    maxSpinSpeed = 300.0;
    elasticity = 0.5;
    friction = 0.2;
    numBounces = 0;
    staticOnMaxBounce = true;
    snapOnMaxBounce = false;
    fade = false;

    gravModifier = 0;
};

datablock ExplosionData(M16PointExplosion)
{
   explosionShape = "";
   soundProfile = "";

   lifeTimeMS = 100;
   
   particleEmitter = "";
   particleDensity = 1;
   particleRadius = 0;
   
   debris = M16PointDebris;
   debrisNum = 0;
   debrisNumVariance = 0;
   debrisPhiMin = 0;
   debrisPhiMax = 360;
   debrisThetaMin = 0;
   debrisThetaMax = 180;
   debrisVelocity = 0.1;
   debrisVelocityVariance = 0.1;
   
   faceViewer     = true;
   explosionScale = "1 1 1";
   
   shakeCamera = false;
   
   // Dynamic light
   lightStartRadius = 5;
   lightEndRadius = 5;
   lightStartColor = "1 0 0 1";
   lightEndColor = "1 0 0 1";

   damageRadius = 10;
   radiusDamage = 0;

   impulseRadius = 0;
   impulseForce = 0;
};

AddDamageType("M16",   '<bitmap:add-ons/Weapon_Package_L4B/M16/CI_M16> %1',    '%2 <bitmap:add-ons/Weapon_Package_L4B/M16/CI_M16> %1',0.2,1);
datablock ProjectileData(M16Projectile1)
{
   projectileShapeName = "add-ons/Weapon_Gun/bullet.dts";
   directDamage        = 15;
   directDamageType    = $DamageType::M16;
   radiusDamageType    = $DamageType::M16;

   brickExplosionRadius = 0;
   brickExplosionImpact = false;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 1;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 2;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse      = 0;
   verticalImpulse   = 0;
   explosion           = gunExplosion;

   muzzleVelocity      = 200;
   velInheritFactor    = 1;

   armingDelay         = 00;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = true;
   gravityMod = 0;

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

   uiName = "M16 Bullet";
};

datablock ProjectileData(M16PointProjectileA)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 0;
   directDamageType    = $DamageType::M16;
   radiusDamageType    = $DamageType::M16;
   
   particleEmitter = M16PointEmitterA;
   
   //explosion           = M16PointExplosion;
   //explodeOnDeath = true;

   brickExplosionRadius = 0;
   brickExplosionImpact = 0;             //destroy a brick if we hit it directly?
   brickExplosionForce  = 0;             
   brickExplosionMaxVolume = 0;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 0;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)

   collideWithPlayers = true;

   muzzleVelocity      = 1;
   velInheritFactor    = 1.0;

   armingDelay         = 0;
   lifetime            = 400;
   fadeDelay           = 100;
   bounceElasticity    = 0;
   bounceFriction      = 0.00;
   isBallistic         = true;
   gravityMod          = 0.0;

   hasLight    = false;
   
   uiName = "";
};


datablock ProjectileData(M16PointProjectileB)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 0;
   directDamageType    = $DamageType::M16;
   radiusDamageType    = $DamageType::M16;
   
   particleEmitter = M16PointEmitterB;
   
   //explosion           = M16PointExplosion;
   //explodeOnDeath = true;

   brickExplosionRadius = 0;
   brickExplosionImpact = 0;             //destroy a brick if we hit it directly?
   brickExplosionForce  = 0;             
   brickExplosionMaxVolume = 0;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 0;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)

   collideWithPlayers = true;

   muzzleVelocity      = 7;
   velInheritFactor    = 1.0;

   armingDelay         = 100;
   lifetime            = 100;
   fadeDelay           = 100;
   bounceElasticity    = 0;
   bounceFriction      = 0.00;
   isBallistic         = true;
   gravityMod          = 0.0;

   hasLight    = false;
   
   uiName = "";
};

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

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

//gui stuff
uiName = "M16";
iconName = "./UI_M16";
doColorShift = true;
colorShiftColor = "0.4 0.4 0.3 1.000";

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

maxAmmo = 30;
canReload = 1;
};

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(M16Image)
{
   // Basic Item properties
   shapeFile = "./M16.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; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );

   // 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 = M16Item;
   ammo = " ";
   projectile = M16Projectile1;
   projectileType = Projectile;

   casing = GunShellDebris;
   shellExitDir        = "1.0 0.1 1.0";
   shellExitOffset     = "0 0 0";
   shellExitVariance   = 10.0;
   shellVelocity       = 5.0;

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

   doColorShift = true;
   colorShiftColor = M16Item.colorShiftColor;

   // 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.
   raycastWeaponRange = 0;
   raycastWeaponTargets =
                   $TypeMasks::PlayerObjectType |    //AI/Players
                   $TypeMasks::StaticObjectType |    //Static Shapes
                   $TypeMasks::TerrainObjectType |    //Terrain
                   $TypeMasks::VehicleObjectType |    //Terrain
                   $TypeMasks::FXBrickObjectType;    //Bricks
   raycastExplosionProjectile = GunProjectile;
   raycastExplosionBrickSound = bulletHitSound;
   raycastExplosionPlayerSound = bulletHitSound;
   raycastDirectDamage = 0;
   raycastDirectDamageType = $DamageType::M16;
   raycastSpreadAmt = 0.00001;
   raycastSpreadCount = 1;
   raycastTracerProjectile = M16PointProjectileA;
   raycastFromMuzzle = true;

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.7;
stateTransitionOnTimeout[0]       = "LoadCheckA";
stateSequence[0]                = "use";
stateSound[0] = M16EquipSound;

stateName[1]                      = "Ready";
stateTransitionOnNoAmmo[1]        = "Reload";
stateTransitionOnTriggerDown[1]  = "Fire";
stateScript[1]                  = "onLaserFire";
stateAllowImageChange[1]          = true;

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Delay";
stateTimeoutValue[2]            = 0.01;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
stateScript[2]                  = "onFire";
stateEjectShell[2]          = true;
stateEmitter[2] = gunFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateWaitForTimeout[2] = true;
stateSound[2] = M16FireSound;

stateName[3] = "Delay";
stateTransitionOnTimeout[3]     = "FireLoadCheckA";
stateTimeoutValue[3]            = 0.03;
stateEmitter[3] = gunSmokeEmitter;
stateEmitterTime[3] = 0.03;
stateEmitterNode[3] = "muzzleNode";

stateName[4] = "LoadCheckA";
stateScript[4] = "onLoadCheck";
stateTimeoutValue[4] = 0.01;
stateTransitionOnTimeout[4] = "LoadCheckB";

stateName[5] = "LoadCheckB";
stateTransitionOnAmmo[5] = "Ready";
stateTransitionOnNoAmmo[5] = "Reload";

stateName[6] = "Reload";
stateTimeoutValue[6] = 0.6;
stateScript[6] = "onReloadStart";
stateTransitionOnTimeout[6] = "Wait";
stateWaitForTimeout[6] = true;
stateSound[6] = M16ReloadSound;

stateName[7] = "Wait";
stateTimeoutValue[7] = 0.8;
stateSound[7] = M16Reload2Sound;
stateScript[7] = "onReloadWait";
stateTransitionOnTimeout[7] = "Reloaded";

stateName[8] = "FireLoadCheckA";
stateScript[8] = "onLoadCheck";
stateTimeoutValue[8] = 0.01;
stateTransitionOnTimeout[8] = "FireLoadCheckB";

stateName[9] = "FireLoadCheckB";
stateTransitionOnAmmo[9] = "Smoke";
stateTransitionOnNoAmmo[9] = "ReloadSmoke";

stateName[10] = "Smoke";
stateEmitter[10] = gunSmokeEmitter;
stateEmitterTime[10] = 0.3;
stateEmitterNode[10] = "muzzleNode";
stateTimeoutValue[10] = 0.3;
stateTransitionOnTimeout[10] = "Ready";
stateTransitionOnTriggerDown[10] = "Fire";

stateName[11] = "ReloadSmoke";
stateEmitter[11] = gunSmokeEmitter;
stateEmitterTime[11] = 0.3;
stateEmitterNode[11] = "muzzleNode";
stateTimeoutValue[11] = 0.2;
stateTransitionOnTimeout[11] = "Reload";

stateName[12] = "Reloaded";
stateTimeoutValue[12] = 0.7;
stateScript[12] = "onReloaded";
stateSequence[12]                = "use";
stateTransitionOnTimeout[12] = "Ready";
stateSound[12] = M16EquipSound;
};

function M16Image::onFire(%this,%obj,%slot) //call this in fire states
{
   if(%obj.laserfire)
   {
      %this.raycastWeaponRange = 3000;
      Parent::onFire(%this,%obj,%slot);
      %this.raycastWeaponRange = 3000;
      return;
   }

%projectile = M16Projectile1;

if(vectorLen(%obj.getVelocity()) < 0.1)
{
%spread = 0.00001;
}
else
{
%spread = 0.0025;
}

%obj.lastShotTime = getSimTime();
%shellcount = 1;

%obj.playThread(2, plant);
%shellcount = 1;
%obj.toolAmmo[%obj.currTool]--;

for(%shell=0; %shell<%shellcount; %shell++)
{
%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) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}

function M16Image::onReloadStart(%this,%obj,%slot)
{
%obj.toolAmmo[%obj.currTool] = 0;
%obj.playThread(2, wrench);
}

function M16Image::onReloadWait(%this,%obj,%slot)
{
%obj.playThread(2, activate);
%obj.playThread(3, plant);
}

function M16Image::onReloaded(%this,%obj,%slot)
{
%obj.toolAmmo[%obj.currTool] = %this.item.maxAmmo;
%obj.setImageAmmo(%slot,1);
}

function M16Image::onUnMount(%this,%obj,%slot)
{
%obj.playThread(2, root);
}

function M16Image::onLaserFire(%this,%obj,%slot) //call this when in idle/ready states
{
   %obj.laserfire = 1;
   M16Image::onFire(%this,%obj,%slot);
   %obj.laserfire = 0;
}
Space helped me a lot with the script.

The "Ready" state only happens once so you get a laser appearing for one tenth of a second and then it goes away.

The "Ready" state only happens once so you get a laser appearing for one tenth of a second and then it goes away.
So, I'd have to make a relay of it?
Like,

Code: [Select]
stateTransitionOnTimeout[1]       = "Ready";
stateTransitionOnTimeout[1]       = "Ready";

That and set a (short) timeout value.

For now it's working.

But another problem now, the Laser explosion is the gunexplosion.

Like, it doesn't shows a dot, instead of a dot, it shows the Gun Explosion.

Also, do I have to include this in the script?

Code: [Select]
function ColtImage::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
   if(!isObject(%col))
      return;
  
   if(!%obj.fireTrace)
      return Parent::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit);

   %scaleFactor = getWord(%obj.getScale(), 2);
   %vec = vectorNormalize(vectorSub(%obj.getEyePoint(),%pos));

   %projectile = ColtPointProjectileA; //gunProjectile;
   %p = new Projectile()
   {
      dataBlock = %projectile;
      initialPosition = vectorAdd(%pos,vectorScale(%normal,0.05));
      initialVelocity = "0 0 0";
      sourceObject = %obj;
      client = %obj.client;
      sourceSlot = 0;
      originPoint = %pos;
   };
   MissionCleanup.add(%p);
   %p.setScale(%scaleFactor SPC %scaleFactor SPC %scaleFactor);
  
   %projectile = ColtPointProjectileB; //gunProjectile;
   %p = new Projectile()
   {
      dataBlock = %projectile;
      initialPosition = vectorAdd(%pos,vectorScale(%normal,0.05));
      initialVelocity = vectorScale(%vec,0.4);
      sourceObject = %obj;
      client = %obj.client;
      sourceSlot = 0;
      originPoint = %pos;
   };
   MissionCleanup.add(%p);
   %p.setScale(%scaleFactor SPC %scaleFactor SPC %scaleFactor);
   //%p.explode();
}
I took this from my and yndaaa's Colt. It's laser does work, but the projectile doesn't
« Last Edit: May 08, 2010, 10:02:14 AM by Khain »

IT'S WORKING YEY!!!!!!!!!!!!!