Author Topic: How to make a bullets direction vary?  (Read 1573 times)

I need help with making the bullets go in different places, can someone tell me where in the code this is found, or where to put it? I need to know!

Can someone post an edited version of this script that has a bit of spread?
Code: [Select]
//Raider.cs

//audio
datablock AudioProfile(RaiderShot1Sound)
{
   filename    = "./NerfFire.wav";
   description = AudioClose3d;
   preload = true;
};
datablock AudioProfile(RaiderBulletHitSound)
{
   filename    = "./bulletHit.wav";
   description = AudioClose3d;
   preload = true;
};
datablock AudioProfile(RaiderroosterSound)
{
   filename    = "./Nerfrooster.wav";
   description = AudioClose3d;
   preload = true;
};

datablock ExplosionData(RaiderExplosion)
{
   //explosionShape = "";
soundProfile = RaiderBulletHitSound;

   lifeTimeMS = 150;

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

};


AddDamageType("Raider",   '<bitmap:add-ons/Weapon_Raider/CI_Raider> %1',    '%2 <bitmap:add-ons/Weapon_Raider/CI_Raider> %1',0.2,1);
datablock ProjectileData(RaiderProjectile)
{
   projectileShapeName = "./Dart.dts";
   directDamage        = 5;
   directDamageType    = $DamageType::Raider;
   radiusDamageType    = $DamageType::Raider;

   brickExplosionRadius = 0;
   brickExplosionImpact = false;          //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

      explosion             = RaiderExplosion;
   stickExplosion        = RaiderExplosion;
   bloodExplosion        = RaiderExplosion;
   particleEmitter       = RaiderEmitter;
   explodeOnPlayerImpact = true;
   explodeOnDeath        = true; 

   armingDelay         = 4000;
   lifetime            = 4000;
   fadeDelay           = 4000;

   isBallistic         = true;
   bounceAngle         = 170; //stick almost all the time
   minStickVelocity    = 10;
   bounceElasticity    = 0.2;
   bounceFriction      = 0.01;   
   gravityMod = 0.40;

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

   muzzleVelocity      = 30;
   velInheritFactor    = 1;

   uiName = "Nerf Dart";

};

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

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

//gui stuff
uiName = "Nerf Raider";
iconName = "./icon_Raider";
doColorShift = true;
colorShiftColor = "0.25 0.25 0.25 1.000";

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(RaiderImage)
{
   // Basic Item properties
   shapeFile = "./Raider.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 = BowItem;
   ammo = " ";
   projectile = RaiderProjectile;
   projectileType = Projectile;

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

   doColorShift = true;
   colorShiftColor = RaiderItem.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.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

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

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Reload";
stateTimeoutValue[2]            = 0.10;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateSound[2] = RaiderShot1Sound;

stateName[4] = "Reload";
stateSequence[4]                = "Reload";
stateTransitionOnTimeout[4]     = "Reload2";
stateSound[4] = RaiderroosterSound;
stateTimeoutValue[4]            = 0.38;

stateName[5] = "Reload2";
stateSequence[5]                = "Ready";
stateTransitionOnTriggerUp[5]     = "Ready";
stateTimeoutValue[5]            = 0.10;

};

function RaiderImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}
« Last Edit: August 13, 2010, 03:25:35 AM by RFW2 »

Manually spawn a projectile in onFire
Look at a shotgun script.

getRandom is your new friend

getRandom is your new friend
but my friend is function

i don't want getRandom :(

Thanks


EDIT: Looked at the shotgun script, but my gun is a single shot not a shotgun, what should I change?
« Last Edit: August 13, 2010, 03:15:56 AM by RFW2 »

%shellCount in the firing script, or just remove the for() loop entirely.

%shellCount in the firing script, or just remove the for() loop entirely.

I did, it didnt work, it just stayed the same, can you edit the script in the op to give it spread, Ill give you creds in the Add-on btw.

Post your current script. I meant "the firing script" as in the one in the Shotgun, not the one in the first post.

Post your current script. I meant "the firing script" as in the one in the Shotgun, not the one in the first post.


Its in the OP and I know, I edited the shotguns script and it failed

None of the shotgun's firing script is in the first post.

None of the shotgun's firing script is in the first post.

I know, what Im askng is for someone to edit the script in the OP so the bullet direction varies.

Having the answers spoon-fed to you really won't help in future. Look at the Shotgun script and try to interpret what each part does. If you show me which parts you are trying to change then I can help.

Having the answers spoon-fed to you really won't help in future. Look at the Shotgun script and try to interpret what each part does. If you show me which parts you are trying to change then I can help.

Id like to have this one done so I know for the future aswell. If someone could find a Pistol that has spread that would be fine. But I cant think of one. I have interpreted what most of it does, but I did what you said and it didnt work.

Id like to have this one done so I know for the future aswell. If someone could find a Pistol that has spread that would be fine. But I cant think of one. I have interpreted what most of it does, but I did what you said and it didnt work.
*spoonfeed*
Quote
function shotgunImage::onFire(%this,%obj,%slot)
{
   if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
      return;
   %obj.lastFireTime = getSimTime();
     
   %obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
   %obj.playThread(2, shiftAway);

   %projectile = %this.projectile;
   %spread = 0.0015;
   %shellcount = 3;

   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;
}
You change that to this: %shellcount = 1;
How could you have failed at doing that? Show us your attempt.

*spoonfeed*You change that to this: %shellcount = 1;
How could you have failed at doing that? Show us your attempt.

Oh, Ill have to do it again, I deleted it.