Author Topic: Turretted Vehicle  (Read 2369 times)

How would you go about making a vehicle with some form of turret on it?

I've got the vehicle and the turret.dts's done and seperate from eachother.

How do I slap the turret on the back?

I have a demoturret.ms3d on my computer.
Wait until the 18th.
In 12 hours, I'll give the ms3d to you.

Even if you use blender, you can learn from it.


I have a demoturret.ms3d on my computer.
Wait until the 18th.
In 12 hours, I'll give the ms3d to you.

Even if you use blender, you can learn from it.

Can I has it yet?



Is there a script to go with it? I don't want just a turret. I can do that.

I want a turret on a vehicle. I have a turret, I have a vehicle. So where's the /superglue command?

Is there a script to go with it? I don't want just a turret. I can do that.

I want a turret on a vehicle. I have a turret, I have a vehicle. So where's the /superglue command?
Code: [Select]
function WarthogVehicle::onAdd(%this,%obj)
{
   // Setup the car with some defaults tires & springs
   for(%i = 0; %i < %this.numWheels; %i++)
   {
      %obj.setWheelTire(%i, %this.defaultTire);
      %obj.setWheelSpring(%i, %this.defaultSpring);
   }

   // 4 wheel steering
   %obj.setWheelSteering(0,1);
   %obj.setWheelSteering(1,1);
   %obj.setWheelSteering(2,-1);
   %obj.setWheelSteering(3,-1);

   // 4 wheel drive
   %obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);
   %obj.setWheelPowered(2,true);
   %obj.setWheelPowered(3,true);

   // gatt
   %t = new AIPlayer()
   {
      dataBlock = WarthoggattPlayer;
   };
   MissionCleanup.add(%t);
   %obj.mountObject(%t, 2);
   %obj.gatt = %t;

   %obj.creationTime = getSimTime();
   %t.schedule(10,"riggatt");
}

function Player::riggatt(%obj)
{
   if(%obj.dataBlock !$= WarthoggattPlayer)
   return;

   if(!isObject(%obj))
   return;

   %parent = %obj.getObjectMount();
   if(!isObject(%parent))
   return;

   %obj.spawnBrick = %parent.spawnBrick;
   %obj.brickGroup = %parent.brickGroup;
}

function WarthogVehicle::onRemove(%this,%obj)
{
   if(isObject(%obj.gatt))
   %obj.gatt.delete();
}

function WarthoggattPlayer::onDriverLeave(%this,%obj)
{
   %obj.setTransform("0 0 0 0 0 0 0");
}

package WarthogPackage
{
   function serverCmdNextSeat(%client)
   {
      if(!isObject(%client.player.getObjectMount()))
         return;

      %vehicle = %client.player.getObjectMount();
      if(!%vehicle.dataBlock.rideable)
         return;

      %totalMounts =  0;
      if(isObject(%vehicle.getObjectMount()))
      {
         %totalMounts = 1;
         %mount0 = %vehicle.getObjectMount();
      }
      %mount[%totalMounts] = %vehicle;
      %totalMounts++;
      for(%i=0;%i<%vehicle.dataBlock.numMountPoints;%i++)
      {
         %mountedObject = %vehicle.getMountNodeObject(%i);
         if(%mountedObject !$= 0)
         {
            if(%mountedObject.dataBlock.rideable)
            {
               %mount[%totalMounts] = %mountedObject;
               %totalMounts++;
            }
         }
      }

      %seats = 0;
      for(%i=0;%i<%totalMounts;%i++)
      {
         %mVehicle = %mount[%i];
         for(%j=0;%j<%mVehicle.dataBlock.numMountPoints;%j++)
         {
            %mMount = %mVehicle.getMountNodeObject(%j);
            %seat[%seats] = ((%i+1)*100)+%j;
            if(isObject(%mMount))
            {
               if(%mMount $= %client.player)
                  %currSeat = %seats;
            }
            else
               %freeSeats++;
            %seats++;
         }
      }

      if(%freeSeats < 1)
         return;

      %sId = %currSeat+1;
      if(%sId >= %seats)
         %sId = 0;
      while(%foundSeat $= "")
      {
         %seatStr = %seat[%sId];
         %cVehicle = %mount[getSubStr(%seatStr,0,1)-1];
         %searchSeat = getSubStr(%seatStr,2,1);
         if(%cVehicle.getMountNodeObject(%searchSeat) $= 0)
         {
            %foundSeat = %searchSeat;
            break;
         }
         %sId++;
     
         if(%sId >= %seats)
            %sId = 0;

         %k++;
         if(%k > 100)
            return;
      }
      %cVehicle.mountObject(%client.player,%foundSeat);
   }

   function serverCmdPrevSeat(%client)
   {
      if(!isObject(%client.player.getObjectMount()))
         return;

      %vehicle = %client.player.getObjectMount();
      if(!%vehicle.dataBlock.rideable)
         return;

      %totalMounts =  0;
      if(isObject(%vehicle.getObjectMount()))
      {
         %totalMounts = 1;
         %mount0 = %vehicle.getObjectMount();
      }
      %mount[%totalMounts] = %vehicle;
      %totalMounts++;
      for(%i=0;%i<%vehicle.dataBlock.numMountPoints;%i++)
      {
         %mountedObject = %vehicle.getMountNodeObject(%i);
         if(%mountedObject !$= 0)
         {
            if(%mountedObject.dataBlock.rideable)
            {
               %mount[%totalMounts] = %mountedObject;
               %totalMounts++;
            }
         }
      }

      %seats = 0;
      for(%i=0;%i<%totalMounts;%i++)
      {
         %mVehicle = %mount[%i];
         for(%j=0;%j<%mVehicle.dataBlock.numMountPoints;%j++)
         {
            %mMount = %mVehicle.getMountNodeObject(%j);
            %seat[%seats] = ((%i+1)*100)+%j;
            if(isObject(%mMount))
            {
               if(%mMount $= %client.player)
                  %currSeat = %seats;
            }
            else
               %freeSeats++;
            %seats++;
         }
      }

      if(%freeSeats < 1)
         return;

      %sId = %currSeat-1;
      if(%sId < 0)
         %sId = %seats--;
      while(%foundSeat $= "")
      {
         %seatStr = %seat[%sId];
         %cVehicle = %mount[getSubStr(%seatStr,0,1)-1];
         %searchSeat = getSubStr(%seatStr,2,1);
         if(%cVehicle.getMountNodeObject(%searchSeat) $= 0)
         {
            %foundSeat = %searchSeat;
            break;
         }
         %sId--;
     
         if(%sId < 1)
            %sId = %seats-1;

         %k++;
         if(%k > 100)
            return;
      }
      %cVehicle.mountObject(%client.player,%foundSeat);
   }

   function Player::burn(%obj,%time)
   {
if(%obj.dataBlock $= WarthoggattPlayer)
   return;
else
   Parent::burn(%obj,%time);
   }

   function ShapeBase::setNodeColor(%obj,%node,%color)
   {
parent::setnodecolor(%obj,%node,%color);
if(isObject(%obj.gatt))
{
   %obj.gatt.setNodeColor("ALL",%color);
}
   }

   function WarthogVehicle::Damage(%this,%obj,%source,%pos,%amm,%type)
   {
      if((%obj.getDamageLevel()+%amm) >= %this.maxDamage)
      {
         if(%obj.destroyed)
            return;

         %obj.setNodeColor("ALL","0 0 0 1");
         if(isObject(%obj.gatt))
         {
            %obj.gatt.delete();
            %p = new Projectile()
            {
               dataBlock = WarthoggattExplosionProjectile;
               initialPosition = vectorAdd(%obj.getPosition(),"0 0" SPC %this.initialExplosionOffset);
               initialVelocity = "0 0 1";
               client = %obj.lastDamageClient;
               sourceClient = %obj.lastDamageClient;
            };
            MissionCleanup.add(%p);
         }
         else
         {
            %p = new Projectile()
            {
               dataBlock = WarthogExplosionProjectile;
               initialPosition = vectorAdd(%obj.getPosition(),"0 0" SPC %this.initialExplosionOffset);
               initialVelocity = "0 0 1";
               client = %obj.lastDamageClient;
               sourceClient = %obj.lastDamageClient;
            };
            MissionCleanup.add(%p);
         }
         if(%obj.destroyed)
            return;

         %obj.setDamageLevel(%this.maxDamage);
         %obj.destroyed = 1;
         %obj.schedule(%this.burnTime,"finalExplosion");
         if(isObject(%obj.spawnBrick.client.minigame))
            %respawn = %obj.spawnBrick.client.minigame.vehicleReSpawnTime;
         %obj.spawnBrick.schedule(%respawn,"spawnVehicle");
      }
      else
         Parent::Damage(%this,%obj,%source,%pos,%amm,%type);
   }

   function Player::emote(%obj,%emote)
   {
      if(%obj.dataBlock $= WarthoggattPlayer)
      return;
      Parent::emote(%obj,%emote);
   }

   function WarthoggattPlayer::onDamage(%this,%obj,%ammount)
   {
      if(%obj.dataBlock $= WarthoggattPlayer)
         return;
   Parent::onDamage(%this,%obj,%ammount);
   }

   function WarthogShellProjectile::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e)
   {
      if(%col.dataBlock.className $= "Glass" && !%col.indestructable)
      {
         %col.explode();
      }
      Parent::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e);
   }

   function WarthoggattPlayer::onDisabled(%this,%obj,%state)
   {
      %p = new Projectile()
      {
         dataBlock = WarthoggattExplosionProjectile;
         initialPosition = vectorAdd(%obj.getObjectMount().getPosition(),"0 0" SPC %obj.getObjectMount().dataBlock.initialExplosionOffset);
         initialVelocity = "0 0 1";
         client = %obj.lastDamageClient;
         sourceClient = %obj.lastDamageClient;
      };
      MissionCleanup.add(%p);
      %obj.schedule(10,"delete");
      %player = %obj.getMountedObject(0);
      if(isObject(%player))
      {
         %obj.getObjectMount().schedule(10,"mountObject",%player,2);
      }
   }

   function WarthoggattPlayer::Damage(%this,%obj,%source,%pos,%amm,%type)
   {
      //scale the damage ammount as if this was a vehicle
      %amm *= $Damage::VehicleDamageScale[%type];

      if(%obj.getDamageLevel()+%amm > %this.maxDamage)
         %obj.setDamageLevel(%this.maxDamage);
      else
         Parent::Damage(%this,%obj,%source,%pos,%amm,%type);
   }

   function armor::onMount(%this,%obj,%col,%slot)
   {
      Parent::onMount(%this,%obj,%col,%slot);
      if(%col.dataBlock $= WarthogVehicle)
      {
         if(%slot $= 2)
         {
            %obj.setLookLimits(1,0);
         }
      }
      else if(%col.dataBlock $= WarthoggattPlayer)
      {
         %client = %obj.client;
         if(isObject(%client))
            ServerCmdUnUseTool(%client);
      }

   
   }
};
activatepackage(WarthogPackage);
I do shooting seperate

This is for shooting
Code: [Select]
$TP::Version=1.1; //Version number, do NOT change this unless you know what you are doing.

if($Support::ShootOnClick<$Prop::Version) {return;} //Newer version already loaded.
$Support::ShootOnClick=$TP::Version;

package ShootOnClick_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="Player")
{
if(%slot==0)
{
if(%val)
{
if($Sim::Time<%obj.client.SOC_LastFireTime)
{
return;
}
}
%client = %obj.client;
%obj.SOC_Shoot(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(ShootOnClick_Pack);

function repeatedVectorAddwithScale(%vecs)
{
%vec="0 0 0";
%cnt=getFieldCount(%vecs);
for(%i=0;%i<%cnt;%i++)
{
%fld=getField(%vecs,%i);
%tvec=getWords(%fld,0,3);
%scale=getWord(%fld,3);
%svec=vectorScale(%tvec,%scale);
%vec=vectorAdd(%vec,%svec);
}
return %vec;
}

function SimObject::getLeftVector(%obj)
{
return vectorCross(%obj.getEyeVector(),%obj.getUpVector());
}

function SimObject::getRightVector(%obj)
{
return vectorScale(%obj.getLeftVector(%obj),-1);
}

function Player::SOC_Shoot(%obj,%slot,%val)
{
if(!%val) {cancel(%obj.SOC_reshoot);return;}

%mnt= %obj.getObjectMount();
if(!isObject(%mnt))
{
return;
}

%data= %mnt.getDatablock();

%mountObj= %mnt.getMountNodeObject(%data.shootOnClick_RequiredSlot);
if(%mountObj!$=%Obj) {return;}

if(%data.shootOnClick)
{
//Checks OK, shoot it all.
%cnt=%data.shootOnClick_ProjectileCount;
for(%i=0;%i<%cnt;%i++)
{
%client = %obj.client;
%pos= %mnt.getPosition();
%PVec= %data.ShootOnClick_Position[%i];
%VVec= %data.ShootOnClick_Velocity[%i];
%iPos= repeatedVectorAddwithScale(
%mnt.getEyeVector() SPC getWord(%PVec,0) TAB
%mnt.getLeftVector() SPC getWord(%PVec,1) TAB
%mnt.getUpVector() SPC getWord(%PVec,2)
);
%iVel= repeatedVectorAddwithScale(
%mnt.getEyeVector() SPC getWord(%VVec,0) TAB
%mnt.getLeftVector() SPC getWord(%VVec,1) TAB
%mnt.getUpVector() SPC getWord(%VVec,2)
);
%scale=%data.ShootOnClick_Scale[%i];
if(%scale$="") {%scale="1 1 1";}
%p= new Projectile()
{
dataBlock= %data.ShootOnClick_Projectile[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %obj;
client= %obj.client;
sourceSlot= %slot;
scale= %scale;
};
ServerCmdUnUseTool(%client);
missionCleanup.add(%p);
}
serverPlay3d(%data.ShootOnClick_Sound,%pos);

//If hold, schedule.
if(%data.ShootOnClick_Hold)
{
//Delay according to datablocks.

%obj.SOC_reshoot= %obj.schedule(%data.ShootOnClick_ReshootDelay,SOC_Shoot,%slot,%val);

}
%obj.client.SOC_LastFireTime=$Sim::Time+%data.ShootOnClick_ShootDelay/1000;
}
}

Then add this to you turret datablock
Code: [Select]
ShootOnClick=1;
ShootOnClick_Hold=1;
ShootOnClick_ShootDelay=120;
ShootOnClick_ReShootDelay=120;
ShootOnClick_ProjectileCount=1;
ShootOnClick_RequiredSlot=0;
ShootOnClick_Sound=gunshot1Sound;

ShootOnClick_Projectile[0]=WarthogShellProjectile;
ShootOnClick_Position[0]="2.5 0 1.2";
ShootOnClick_Velocity[0]="200 0 0";
ShootOnClick_Scale[0]="1 1 1";
And mess around with the values

I'd rather take advice from Pandan. Your attempt at my Pelican makes me wonder if you're actually right.

Quote from: Default Tank Script
function TankVehicle::onAdd(%this,%obj)
{
   // Setup the car with some defaults tires & springs
   for(%i = 0; %i < %this.numWheels; %i++)
   {
      %obj.setWheelTire(%i, %this.defaultTire);
      %obj.setWheelSpring(%i, %this.defaultSpring);
   }

   // 4 wheel steering
   %obj.setWheelSteering(0,1);
   %obj.setWheelSteering(1,1);
   %obj.setWheelSteering(2,-0.8);
   %obj.setWheelSteering(3,-0.8);

   // 4 wheel drive
   %obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);
   %obj.setWheelPowered(2,true);
   %obj.setWheelPowered(3,true);

   // turret
   %t = new AIPlayer()
   {
      dataBlock = TankTurretPlayer;
   };
   MissionCleanup.add(%t);
   %obj.mountObject(%t, 2);
   %obj.turret = %t;

   %obj.creationTime = getSimTime();
   %t.schedule(10,"rigTurret");
}

Bold is what mountpoint# you mount it to.

You still need the turret code as well.
This is just the part to mount it on there.

If you need help further, contact me on steam. (westomopresto)
« Last Edit: December 22, 2009, 05:01:45 PM by MtnDew »

Thanks again for the turret bones, but I was wondering how to animate. The joints move, but I can't get the model to move with it.

I'd rather take advice from Pandan. Your attempt at my Pelican makes me wonder if you're actually right.
I was the one who got it to work, not you.
Also, count how many turreted vehicle I made.
How many of those vehicles have broken turrets?
« Last Edit: December 23, 2009, 02:20:25 PM by heedicalking »

I was the one who got it to work, not you.
Did you get my pm?

EDIT:: IRONY
« Last Edit: December 23, 2009, 02:24:38 PM by iownu424 »

Thanks again for the turret bones, but I was wondering how to animate. The joints move, but I can't get the model to move with it.
Assign the model to the rotating turret100 or w/e.