Author Topic: Vehicle with mounted guns  (Read 1248 times)

Can anyone help me with my script? I think v10's tank or events did something to it. Also, I have a mount1 and 2 on the model already.
Code: [Select]
datablock ProjectileData(p51gunProjectile)
{
   projectileShapeName = "./bullet.dts";
   directDamage        = 30;
   directDamageType    = $DamageType::p51gun;
   radiusDamageType    = $DamageType::p51gun;

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //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      = 400;
   verticalImpulse   = 400;
   explosion           = gunExplosion;
   particleEmitter     = ""; //bulletTrailEmitter;

   muzzleVelocity      = 120;
   velInheritFactor    = 1;

   armingDelay         = 00;
   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";


};
function P51vehicle::onadd(%this,%obj)
{
parent::onadd(%this,%obj);

%obj.setWheelTire(0, reartire);
%obj.setWheelTire(1, jeeptire);
%obj.setWheelTire(2, jeeptire);
   %obj.mountImage(p51gunimage,1);
      %obj.mountImage(p51gunn2image,2);
%obj.setWheelSpring(0, P51Spring);
%obj.setWheelSpring(1, P51Spring);
%obj.setWheelSpring(2, P51Spring);

%obj.setWheelSteering(0,1);
%obj.setWheelSteering(1,0);
%obj.setWheelSteering(2,0);

%obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);
%obj.setWheelPowered(2,true);
%obj.doorOpen = 1;
    %obj.playThread(0,spin);
}
function P51Vehicle::onTrigger(%this, %obj, %num, %cli, %wha)
{
if(%cli $= 1 && $Sim::Time > %obj.nextDoorTime)
{
if(%obj.doorOpen $= 1)
{
%obj.playThread(1,gearsdown);
%obj.doorOpen = 0;

%obj.setWheelTire(0, emptytire);
%obj.setWheelTire(1, emptytire);
%obj.setWheelTire(2, emptytire);

%obj.setWheelSpring(0, P51sSpring);
%obj.setWheelSpring(1, P51sSpring);
%obj.setWheelSpring(2, P51sSpring);

%obj.setWheelSteering(0,-1);
%obj.setWheelSteering(1,0);
%obj.setWheelSteering(2,0);

%obj.setWheelPowered(0,false);
   %obj.setWheelPowered(1,false);
%obj.setWheelPowered(2,false);
    %obj.playThread(1,spin);
}
else
{
%obj.playThread(1,gearsup);
%obj.doorOpen = 1;

%obj.setWheelTire(0, reartire);
%obj.setWheelTire(1, jeeptire);
%obj.setWheelTire(2, jeeptire);

%obj.setWheelSpring(0, P51Spring);
%obj.setWheelSpring(1, P51Spring);
%obj.setWheelSpring(2, P51Spring);

%obj.setWheelSteering(0,-1);
%obj.setWheelSteering(1,0);
%obj.setWheelSteering(2,0);

%obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);
%obj.setWheelPowered(2,true);
    %obj.playThread(1,spin);


}
%obj.nextDoorTime = $Sim::Time+1;
}
}
datablock ShapeBaseImageData(p51gunImage)
{
   // Basic Item properties
   shapeFile = "./empty.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 1;
   offset = "0 0 0";
   correctMuzzleVector = false;
   className = "WeaponImage";

   projectile = p51gunProjectile;
   projectileType = Projectile;
fireTimeout = 300;

   // Initial start up state
   stateName[0]                     = "Preactivate";
   stateTransitionOnLoaded[0]       = "Activate";
   stateTransitionOnNoAmmo[0]       = "Activate";

   // Activating the gun.  Called when the weapon is first
   // mounted and there is ammo.
   stateName[1]                     = "Activate";
   stateTransitionOnTimeout[1]      = "Ready";
   stateTimeoutValue[1]             = 0.6;
   stateSequence[1]                 = "Activate";

   // Ready to fire, just waiting for the trigger
   stateName[2]                     = "Ready";
   stateTransitionOnNoAmmo[2]       = "Activate";
   stateTransitionOnTriggerDown[2]  = "Fire";

   // Fire the weapon. Calls the fire script which does
   // the actual work.
   stateName[3]                     = "Fire";
   stateTransitionOnTimeout[3]      = "Reload";
   stateTimeoutValue[3]             = 0.2;
   stateFire[3]                     = true;
   stateRecoil[3]                   = LightRecoil;
   stateAllowImageChange[3]         = false;
   stateSequence[3]                 = "Fire";
   stateScript[3]                   = "onFire";

   // Play the relead animation, and transition into
   stateName[4]                     = "Reload";
   stateTransitionOnNoAmmo[4]       = "Activate";
   stateTransitionOnTimeout[4]      = "Ready";
   stateTimeoutValue[4]             = 0.8;
   stateAllowImageChange[4]         = false;
   stateSequence[4]                 = "Reload";
   stateEjectShell[4]               = true;

   // No ammo in the weapon, just idle until something
   // shows up. Play the dry fire sound if the trigger is
   // pulled.
   stateName[5]                     = "Activate";
   stateTransitionOnAmmo[5]         = "Reload";
   stateSequence[5]                 = "Activate";
   stateTransitionOnTriggerDown[5]  = "DryFire";

   // No ammo dry fire
   stateName[6]                     = "DryFire";
   stateTimeoutValue[6]             = 1.0;
   stateTransitionOnTimeout[6]      = "Activate";
};
datablock ShapeBaseImageData(p51gun2Image : p51gunImage)
{
   mountPoint = 2;
};

function P51::onTrigger(%data, %obj, %trigger, %state)
{
   // data = datablock
   // obj = object number
   // trigger = 0 for "fire", 1 for "jump", 3 for "thrust"
   // state = 1 for firing, 0 for not firing
   if(%trigger == 0)
   {
      switch (%state) {
         case 0:
            %obj.fireWeapon = false;
            %obj.setImageTrigger(1, false);
            %obj.setImageTrigger(2, false);
         case 1:
            %obj.fireWeapon = true;
            if(%obj.nextWeaponFire == 0) {
               %obj.setImageTrigger(1, true);
               %obj.setImageTrigger(2, false);
            }
            else {
               %obj.setImageTrigger(1, false);
               %obj.setImageTrigger(2, true);
            }
      }
   }
}

function p51gunImage::onFire(%data,%obj,%slot)
{
   Parent::onFire(%data,%obj,%slot);
   %obj.nextWeaponFire = 1;
   schedule(%data.fireTimeout, 0, "fireNextGun", %obj);   
}

function p51gun2Image::onFire(%data,%obj,%slot)
{
   Parent::onFire(%data,%obj,%slot);
   %obj.nextWeaponFire = 0;
   schedule(%data.fireTimeout, 0, "fireNextGun", %obj);
}

function p51gunImage::onTriggerDown(%this, %obj, %slot)
{
}

function p51gunImage::onTriggerUp(%this, %obj, %slot)
{
}

function fireNextGun(%obj)
{
   if(%obj.fireWeapon)
   {
      if(%obj.nextWeaponFire == 0)
      {
         %obj.setImageTrigger(1, true);
         %obj.setImageTrigger(2, false);
      }
      else
      {
         %obj.setImageTrigger(1, false);
         %obj.setImageTrigger(2, true);
      }
   }
   else
   {
      %obj.setImageTrigger(1, false);
      %obj.setImageTrigger(2, false);
   }
}

function ShapeBaseImageData::onFire(%data, %obj, %slot)
{
%projectile = p51gunprojectile;

%muzzleVector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   
   %muzzleVelocity = VectorAdd(
      VectorScale(%muzzleVector, %projectile.muzzleVelocity),
      VectorScale(%objectVelocity, %projectile.velInheritFactor));
   
   %vehicle = 0;
   
       %p = new (%data.projectileType)() {
         dataBlock        = p51gunprojectile;
         initialVelocity  = %muzzleVelocity;
         initialDirection = %obj.getMuzzleVector(%slot);
         initialPosition  = %obj.getMuzzlePoint(%slot);
         sourceObject     = %obj;
         sourceSlot       = %slot;
         vehicleObject    = %vehicle;
      };
 
   if (isObject(%obj.lastProjectile) && %obj.deleteLastProjectile)
      %obj.lastProjectile.delete();

   %obj.lastProjectile = %p;
   %obj.deleteLastProjectile = %data.deleteLastProjectile;
   
   MissionCleanup.add(%p);
 
   return %p;
}



This isn't working for me ever, which sucks because I can't release the new version of the military jeep until it does. If anyone wants to look at it; Vehicle_MilitaryJeep.cs


shoulnt all the } have an ; after them,i dont know vehicle code but every script ive seen has an ; after the }

I think that only closes datablocks



Code: [Select]
function P51vehicle::onadd(%this,%obj)
{
parent::onadd(%this,%obj);

%obj.setWheelTire(0, reartire);
%obj.setWheelTire(1, jeeptire);
%obj.setWheelTire(2, jeeptire);
   %obj.mountImage(p51gunimage,1);
      %obj.mountImage([b]p51gunn2image[/b],2);
%obj.setWheelSpring(0, P51Spring);
%obj.setWheelSpring(1, P51Spring);
%obj.setWheelSpring(2, P51Spring);

%obj.setWheelSteering(0,1);
%obj.setWheelSteering(1,0);
%obj.setWheelSteering(2,0);

%obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);
%obj.setWheelPowered(2,true);
%obj.doorOpen = 1;
    %obj.playThread(0,spin);
}
You've spelt p51gun2image wrong.

Here's some crappy code that might help you:
Code: [Select]
package MountedGunFire {
function Armor::onTrigger(%this, %obj, %triggerNum, %val)
{
%pmount = %obj.getObjectMount();
if(isobject(%pmount)){
if(%pmount.getdatablock().getname() $= "<vehicle>" && %triggerNum == 0){
%pmount.setimagetrigger(1,1);
%pmount.setimagetrigger(2,1);
%pmount.client = %obj.client;
cancel(%obj.fightsch);
%obj.fightsch = schedule(1000,0,"Untrigger",%pmount,2);
}
}
parent::onTrigger(%this, %obj, %triggerNum, %val);
}
};
activatepackage(MountedGunFire);

function untrigger(%obj, %trigger)
{
%obj.setimagetrigger(1,0);
%obj.setimagetrigger(2,0);
}
Not sure if it works or not, that's your job to find out.

shoulnt all the } have an ; after them,i dont know vehicle code but every script ive seen has an ; after the }
Faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaail.