Two different projectiles.

Author Topic: Two different projectiles.  (Read 1765 times)

Is there any way to make a weapon shoot two projectiles with different actions on collision at the same time? If there is, then please help me out here. I don't know that much about scripting.

Thanks.
« Last Edit: July 31, 2008, 06:56:47 PM by Patonki »

Create a new projectile datablock, add an onCollision function for it, and add code to create a projectile in the onFire function. Look at a weapon like the shotgun for code on making a projectile.

Look at a weapon like the shotgun for code on making a projectile.
This is where I run into trouble. The shotgun codes create the same projectile over again. Sorry if this sounds stupid, but could you give me an example? If my first projectile is called 'primaryprojectile' and the second 'secondaryprojectile', where in the code do I state this?

or

If it's any simplier, making the same projectile do two different actions depending on the distance from the player. I'm thinking something like
Quote
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   if(%distancefromplayer < 100)
      {
         (function1)
      }
      else
      {
         (function2)
      }
}
But how do I state that %distancefromplayer is the actual distance? Again, this may sound very newbish, sorry.
Then again, I might be wrong. Help would be appreciated.

Thanks.
« Last Edit: August 02, 2008, 07:17:29 AM by Patonki »

The shotgun script has a code for creating a projectile inside a for loop, just take the part inside the for loop.

As for the second idea, try this.

Code: [Select]
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   %distancefromplayer = VectorDist(%obj.getPosition(),%col.getPosition());
   if(%distancefromplayer < 100)
      {
         (function1)
      }
      else
      {
         (function2)
      }
}

Can you post the code, if that's not too much to ask?

Also
Quote
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   %distancefromplayer = VectorDist(%obj.getPosition(),%col.getPosition());
   if(%distancefromplayer < 100)
      {
         (function1)
      }
      else
      {
         (function2)
      }
}
Doesn't seem to work for me.

Thanks for your help so far!

The shotgun script has a code for creating a projectile inside a for loop, just take the part inside the for loop.

As for the second idea, try this.

Code: [Select]
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
 %distancefromplayer = VectorDist(%obj.getPosition(),%col.getPosition());
 if(%distancefromplayer < 100)
 {
 (function1)
 }
 else
 {
 (function2)
 }
}

Of course it wont work. You'll need to write (function1) and (function2) yourself, as well as making sure that your gun's projectile name is SimplierProjectile

I quoted that wrong.  I have my functions, and my projectile is called SimplierProjectile. Sorry, my fault.
And is this the new projectile code?
Quote
      %p = new (%this.projectileType)()
      {
         dataBlock = %projectile;
         initialVelocity = %velocity;
         initialPosition = %obj.getMuzzlePoint(%slot);
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
From the Saw-Off Shotgun by Ephialtes

I see a lot of '%this.projectile' in there, which I assume means the default projectile. What should I replace it with?

%this.projectile is the projectile variable set in the ShapeBaseImageData. ("gunImage" has it set as "gunProjectile", for instance)

You would replace %this.projectile with the projectileData name you want created: myNewGunProjectileA and myNewGunProjectileB. (then making your alternate onCollision events for each of these)

Ah, something painfully obvious must be wrong here.
Quote
function 2projectilegunImage::onFire(%this, %obj, %slot)
{

%projectile = primaryProjectile;
%projectile1 = secondaryProjectile;
%p = new (primaryProjectileType)()
      {
         dataBlock = %projectile;
         initialPosition = %obj.getMuzzlePoint(%slot);
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
};
MissionCleanup.add(%p);
%v = new (secondaryProjectileType)()
      {
         dataBlock = %projectile1;
         initialPosition = %obj.getMuzzlePoint(%slot);
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
      };
         MissionCleanup.add(%v);
}
Keep in mind, that I'm not that good at scripting. If someone would point out what to add/remove, that would be golden. Thanks.

Did you create datablocks called primaryProjectile and secondaryProjectile?

Yes. It shoots neither.

Quote
function 2projectilegunImage::onFire(%this, %obj, %slot)
{
  %projectile = primaryProjectile;
  %projectile1 = secondaryProjectile;
  %p = new Projectile()
  {
         dataBlock = %projectile;
         initialVelocity = vectorScale(%obj.getMuzzleVector(%slot),%projectile.muzzleVelocity);
         initialPosition = %obj.getMuzzlePoint(%slot);
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
  };
  MissionCleanup.add(%p);
  %v = new Projectile()
  {
         dataBlock = %projectile1;
         initialVelocity = vectorScale(%obj.getMuzzleVector(%slot),%projectile1.muzzleVelocity);
         initialPosition = %obj.getMuzzlePoint(%slot);
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
  };
  MissionCleanup.add(%v);
}

Is the name of your weaponimage actually "2projectilegunimage"?

(Fixed a few lines)

The shotgun script has a code for creating a projectile inside a for loop, just take the part inside the for loop.

As for the second idea, try this.

Code: [Select]
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   %distancefromplayer = VectorDist(%obj.getPosition(),%col.getPosition());
   if(%distancefromplayer < 100)
      {
         (function1)
      }
      else
      {
         (function2)
      }
}
That wont work because %distancefromplayer (unless the player is huge) will always be extremely short. Remember that in onCollision, %obj is refered to the projectile.
Instead you could use %obj.initialposition, however not sure if that is actually kept stored in the projectile.

Code: [Select]
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   %distancefromplayer = VectorDist(%obj.initialPosition,%col.getPosition());
   if(%distancefromplayer < 100)
      {
         (function1)
      }
      else
      {
         (function2)
      }
}

I got
Quote
function SimplierProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   %distancefromplayer = VectorDist(%obj.getPosition(),%col.getPosition());
   if(%distancefromplayer < 1)
      {
         (function1)
      }
      else
      {
         (function2)
      }
}
to almost work by stating that the client is %obj.

It only works in a certain angle.

But the function 1 comes up way too far. Even 1 isn't short enough, and if I go under, it won't work. I'd like to perform function 1 at point blank or bit farther. 

And SpaceGuy, your script dosn't work, sorry. Thanks for the help!
« Last Edit: August 04, 2008, 05:12:02 AM by Patonki »