Author Topic: everytime i fire the weapon my game crashes  (Read 1889 times)

/title
Code: [Select]
datablock DebrisData(popcornsmallDebris)
{
shapeFile = "./POPCORNSMALL.dts";
lifetime = 2.0;
minSpinSpeed = -500.0;
maxSpinSpeed = 400.0;
elasticity = 0.5;
friction = 0.05;
numBounces = 5;
staticOnMaxBounce = false;
snapOnMaxBounce = false;
fade = true;

gravModifier = 2;
};

datablock ExplosionData(popcornsmallExplosion)
{

   debris = popcornsmallDebris;
   debrisNum = 6;
   debrisNumVariance = 0;
   debrisPhiMin = 0;
   debrisPhiMax = 360;
   debrisThetaMin = 0;
   debrisThetaMax = 180;
   debrisVelocity = 10;
   debrisVelocityVariance = 10;
   lifeTimeMS = 250;

   //particleEmitter = RagingBullExplosionChunkEmitter;
   //particleDensity = 5;
   //particleRadius = 0.2;
   
   //emitter[0] = RagingBullExplosionChunkEmitter;
   //emitter[1] = RagingBullExplosionChunkEmitter;

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

   shakeCamera = true;
   camShakeFreq = "5.0 6.0 5.0";
   camShakeAmp = "2.0 6.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 3.0;

   // Dynamic light
   lightStartRadius = 10;
   lightEndRadius = 1;
   lightStartColor = "0.5 0.5 0 1";
   lightEndColor = "0.3 0.1 0.0 1";

   damageRadius = 0;
   radiusDamage = 0;

   impulseRadius = 0;
   impulseForce = 0;
};

AddDamageType("assaultrifle",   '<bitmap:add-ons/Weapon_assault_rifle/CI_assaultriflenew> %1',    '%2 <bitmap:add-ons/Weapon_assault_rifle/CI_assaultriflenew> %1',0.2,1);
datablock ProjectileData(shotgun2Projectile)
{
   projectileShapeName = "./POPCORN.dts";
   directDamage        = 999;
   directDamageType    = $DamageType::Shotgun;
   radiusDamageType    = $DamageType::Shotgun;

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

   impactImpulse      = 1200;
   verticalImpulse     = 1000;
   explosion           = popcornsmallExplosion;

   muzzleVelocity      = 75;
   velInheritFactor    = 1;

   armingDelay         = 0;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;

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


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

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

//gui stuff
uiName = "keem automatic";
iconName = "./icon_assaultriflenew";
doColorShift = true;
colorShiftColor = "1 1 1 1.000";

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(assaultrifleImage)
{
   // Basic Item properties
   shapeFile = "./POPCORNAUTO.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 = assaultrifleItem;
   ammo = " ";
   projectile = shotgun2Projectile;
   projectileType = Projectile;

casing = gunShellDebris;
shellExitDir        = "2.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;

   doColorShift = true;
   colorShiftColor = assaultrifleItem.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";
stateTimeoutValue[0]             = 0.1;
stateTransitionOnTimeout[0]       = "Ready";

stateSound[0] = activateSound;

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

stateSequence[1] = "Ready";

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





stateName[3] = "Smoke";
stateEmitter[3] = gunSmokeEmitter;
stateEmitterTime[3] = 0;
stateEmitterNode[3] = "muzzleNode";
stateTimeoutValue[3]            = 0.0;
        stateTransitionOnTimeout[3]     = "Reload";



stateName[4] = "Reload";
stateAllowImageChange[4]        = false;
stateTimeoutValue[4]            = 0.000;
stateWaitForTimeout[4] = true;
stateTransitionOnTimeout[4]     = "Check";
//stateTransitionOnTriggerUp[4]     = "Ready";


stateName[5] = "Check";
stateTransitionOnTriggerUp[5] = "StopFire";
stateTransitionOnTriggerDown[5] = "Ready";

stateName[6]                    = "StopFire";
stateTransitionOnTimeout[6]     = "Ready";
stateTimeoutValue[6]            = 0.01;
stateAllowImageChange[6]        = false;
stateWaitForTimeout[6]     = true;

stateScript[6]                  = "onStopFire";
};

function assaultrifleImage::onFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();

%projectile = %this.projectile;
%spread = 0.050;
%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;
}

Only thing I can think of is that it might be a problem with the model for the projectile.

Give us a console log.

Only thing I can think of is that it might be a problem with the model for the projectile.

Give us a console log.
http://pastebin.com/GFDkPeUN

Code: [Select]
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
what do you have %p = new (%this.projectileType)() for o.o

this isnt really my code
i copied pasted it as a test
but for some reason it crashes my game

this isnt really my code
i copied pasted it as a test
but for some reason it crashes my game
thers ur problem
never do that without like.... al of the neccesary recorses....

that is wrong
what are you crazy???
i used a old assault_rifle code
i got everything i need, item and weapon model
projectile model
litteraly everything

what do you have %p = new (%this.projectileType)() for o.o
::onFire is supposed to return the projectile.



Why do people do a shellcount loop of 1?
The loop might as well not even exist.

Why do people do a shellcount loop of 1?
The loop might as well not even exist.
I think it might stem from ephi's shotgun, and then just copied/pasted from there to present

Start a game with it enabled and then type trace(1); in the console before you shoot it, then post the new console.log as the one you posted didn't show anything other than missing datablocks which shouldn't crash it.

alright
i tried using the trace command and i got something interesting
my entire console log got spammed with
Code: [Select]
Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255847
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255848)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255848
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255849)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255849
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255850)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255850
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255851)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255851
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255852)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255852
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255853)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255853
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255854)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255854
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255855)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255855
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255856)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255856
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255857)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255857
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255858)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255858
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255859)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255859
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255860)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255860
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255861)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255861
Entering assaultrifleImage::onFire(755, 20835, 0)
   Entering Projectile::onAdd(255862)
   Leaving Projectile::onAdd() - return 264.895 -92.093 1.0653
Leaving assaultrifleImage::onFire() - return 255862
Entering assaultrifleImage::onFire(755, 20835, 0)
the scroll bar was smaller than |

Maybe it's because all your states have a timeout of 0? Just a guess.

Maybe it's because all your states have a timeout of 0? Just a guess.
holy stuff that fixed it
alright thanks!