Author Topic: How do i get this gun to fire again?  (Read 873 times)

Code: [Select]
   shapeFile = "./Colt.dts";
   emap = true;


   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0;//"0.0 1.0 -0.85";
   rotation = eulerToMatrix( "0 -45 0" );


   correctMuzzleVector = true;

   className = "WeaponImage";

   item = BowItem;
   ammo = " ";
   projectile = ColtProjectile;
   projectileType = Projectile;

casing = GunShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 0 0";
shellExitVariance   = 15.0;
shellVelocity       = 7.0;

   melee = false;
 
   armReady = true;
   LarmReady = true;

   doColorShift = true;
   colorShiftColor = ColtItem.colorShiftColor;//"0.400 0.196 0 1.000";

How do I get this gun to fire again? I rotated the gun in the player's hand  by changing rotation = eulerToMatrix, but now it doesn't fire any more.
What do i do to get this to fire again?

Can you post the rest of the code? I feel like that alone shouldn't stop anything, maybe you forgot to rename something?

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

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

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

datablock ParticleData(ColtSmokeParticle)
{
dragCoefficient      = 4;
gravityCoefficient   = -1.0;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 425;
lifetimeVarianceMS   = 55;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "0.5 0.5 0.5 0.7";
colors[1]     = "0.5 0.5 0.5 0.0";
sizes[0]      = 0.05;
sizes[1]      = 0.25;

useInvAlpha = false;
};
datablock ParticleEmitterData(ColtSmokeEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 1.0;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "ColtSmokeParticle";
};

datablock ParticleData(ColtExplosionParticle)
{
dragCoefficient      = 8;
gravityCoefficient   = -0.5;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 700;
lifetimeVarianceMS   = 400;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -50.0;
spinRandomMax = 50.0;
colors[0]     = "0.9 0.9 0.9 0.9";
colors[1]     = "0.9 0.9 0.9 0.0";
sizes[0]      = 0.25;
sizes[1]      = 1.0;

useInvAlpha = true;
};
datablock ParticleEmitterData(ColtExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "ColtExplosionParticle";
};



datablock ExplosionData(ColtExplosion)
{
   //explosionShape = "";
   soundProfile = "BulletHitSound";

   lifeTimeMS = 150;

   particleEmitter = ColtExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   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 = 1;
   lightEndRadius = 0;
   lightStartColor = "1 1 1";
   lightEndColor = "0 0 0";

   uiName = "1911 Colt";

   };



AddDamageType("Colt",   '<bitmap:add-ons/Weapon_Colt/CI_Colt> %1',    '%2 <bitmap:add-ons/Weapon_Colt/CI_Colt> %1',0.5,1);
datablock ProjectileData(ColtProjectile)
{
   projectileShapeName = "./Bullet.dts";
   directDamage        = 25;
   directDamageType    = $DamageType::Colt;
   radiusDamageType    = $DamageType::Colt;

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

   impactImpulse      = 4;
   verticalImpulse   = 3;
   explosion           = ColtExplosion;
   //particleEmitter     = "";

   muzzleVelocity      = 190;
   velInheritFactor    = 1;

    armingDelay         = 00;
   lifetime            = 30000;
   fadeDelay           = 29500;
   bounceElasticity    = 0.99;
   bounceFriction      = 0.00;
   isBallistic         = false;
   gravityMod          = 0.0;

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

   uiName = "1911 Colt";
};

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

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

//gui stuff
uiName = "'1911 Colt";
iconName = "./Icon_Colt";
doColorShift = false;
colorShiftColor = (180/255) SPC (180/255) SPC (180/255) SPC (255/255);

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


};


////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(ColtImage) // This is incredibly sensitive code. If you leave out any semi-colons, the gun will break.
{
   // Basic Item properties
   shapeFile = "./Colt.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.0 1.0 -0.85";
   rotation = eulerToMatrix( "0 -45 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 = BowItem;
   ammo = " ";
   projectile = ColtProjectile;
   projectileType = Projectile;

casing = GunShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 -45 0";
shellExitVariance   = 15.0;
shellVelocity       = 7.0;

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

   doColorShift = true;
   colorShiftColor = ColtItem.colorShiftColor;//"0.400 0.196 0 1.000";

   //casing = " ";

   // 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";
stateSequence[0] = "lock";
stateTimeoutValue[0]            = 0.3;
stateTransitionOnTimeout[0]     = "Ready";
stateSound[0] = ColtSwitchSound;

stateName[1]                    = "Ready";
stateTransitionOnTriggerDown[1] = "Fire";
stateAllowImageChange[1]        = true;
stateSequence[1] = "ready";

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "Smoke";
stateTimeoutValue[3]            = 0.25;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
//stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = gunFlashEmitter;
stateEmitterTime[3] = 0.10;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = ColtFireSound;
stateEjectShell[3]        = true;

stateName[4] = "Smoke";
stateEmitter[4] = ColtSmokeEmitter;
stateEmitterTime[4] = 0.14;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4]            = 0.35;
stateTransitionOnTimeout[4]     = "Ready";


};

function ColtImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, plant);
%projectile = %this.projectile;
%spread = 0.0006;
%shellcount = 1;

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;
}

AddDamageType("ColtS",   '<bitmap:add-ons/Weapon_Colt/CI_ColtS> %1',    '%2 <bitmap:add-ons/Weapon_Colt/CI_ColtS> %1',0.5,1);
datablock ProjectileData(ColtSProjectile)
{
   projectileShapeName = "./Bullet.dts";
   directDamage        = 27;
   directDamageType    = $DamageType::ColtS;
   radiusDamageType    = $DamageType::ColtS;

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

   impactImpulse      = 4;
   verticalImpulse   = 3;
   explosion           = ColtExplosion;
   //particleEmitter     = "";

   muzzleVelocity      = 180;
   velInheritFactor    = 1;

    armingDelay         = 00;
   lifetime            = 30000;
   fadeDelay           = 29500;
   bounceElasticity    = 0.99;
   bounceFriction      = 0.00;
   isBallistic         = false;
   gravityMod          = 0.0;

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

   uiName = "1911 Colt Silenced";
};

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

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

//gui stuff
uiName = "'1911 Colt Silenced";
iconName = "./Icon_ColtS";
doColorShift = false;
colorShiftColor = (180/255) SPC (180/255) SPC (180/255) SPC (255/255);

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


};


////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(ColtSImage)
{
   // Basic Item properties
   shapeFile = "./ColtS.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.0 1.0 -0.85"
   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 = BowItem;
   ammo = " ";
   projectile = ColtSProjectile;
   projectileType = Projectile;

casing = GunShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 0 0";
shellExitVariance   = 15.0;
shellVelocity       = 7.0;

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

   doColorShift = true;
   colorShiftColor = ColtSItem.colorShiftColor;//"0.400 0.196 0 1.000";

   //casing = " ";

   // 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";
stateSequence[0] = "lock";
stateTimeoutValue[0]            = 0.3;
stateTransitionOnTimeout[0]     = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                    = "Ready";
stateTransitionOnTriggerDown[1] = "Fire";
stateAllowImageChange[1]        = true;
stateSequence[1] = "ready";

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "Smoke";
stateTimeoutValue[3]            = 0.25;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateWaitForTimeout[3] = true;
stateScript[3]                  = "onFire";
stateEmitter[3] = gunFlashEmitter;
stateEmitterTime[3] = 0.10;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = ColtSFireSound;
stateEjectShell[3]        = true;

stateName[4] = "Smoke";
stateEmitter[4] = ColtSmokeEmitter;
stateEmitterTime[4] = 0.14;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4]            = 0.35;
stateTransitionOnTimeout[4]     = "Ready";


};

function ColtSImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, plant);
%projectile = %this.projectile;
%spread = 0.0007;
%shellcount = 1;

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;
}

This is a Colt edit if you can't tell by now.

I still need to look at it, but I'm willing to believe that because there's no state with [2] that the system doesn't work. You skipped from [1] to [3] in the states. But you're saying that the gun worked before and that adding the angle is what broke it, right? If you set the rotation back to 0 and left everything as is, would the gun work?

I still need to look at it, but I'm willing to believe that because there's no state with [2] that the system doesn't work. You skipped from [1] to [3] in the states. But you're saying that the gun worked before and that adding the angle is what broke it, right? If you set the rotation back to 0 and left everything as is, would the gun work?
Yes, it fires like normal. After titling the item, it won't fire.

Any ideas yet?

I'm gonna try setting the states 3-onwards one state back.

Edit: Editing the state system didn't do anything. It still fires, but just no bullets.
« Last Edit: January 15, 2016, 01:14:15 AM by The Subject »

Triple post, I think I figured out what's wrong. Since I put // in front of the state for OnFire, OnFire is what I think fires a bullet. Didn't think that it was changed since the default gun adds an arm animation, so I removed it for effect. Either way, I'm gonna test it, and if it works I'll lock this.
Code: [Select]
//stateScript[3]                  = "onFire";
Yup, this was my problem. Locking.
« Last Edit: January 15, 2016, 02:42:38 AM by The Subject »