Author Topic: Random bullet projectiles  (Read 867 times)

How can I add random bullet projectiles to this?


Code: [Select]
// Script

function RifleImage::onFire(%this,%obj,%slot)
{
   if(%obj.getDamagePercent() < 1.0)
      %obj.playThread(2, shiftAway);
   parent::onFire(%this, %obj, %slot);
}

... What?

Your sentence does not translate literally in English. You're requesting random bullets. That's it. I don't even know in what way they're random.

I want the projectile direction to become random/inaccurate.

I assume you mean like Kaje's old Minigun.
This is its codeblock.

Code: [Select]
function minigunImage::onFire(%this,%obj,%slot)
{
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-1")));

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

Yes that but I don't know how to add it into the current codeblock. If I try I end up having something broken.

Yes that but I don't know how to add it into the current codeblock. If I try I end up having something broken.
It's always good to save a copy of the original so you can forget it up and not worry about it.

All you have to do is the following:
   -Paste Blastdown's code at the bottom (position doesn't matter though)
   -Change all instances of "minigun" to "rifle"
   -Change the number after %spread to whatever you want
   -Add the following two lines, after the first { and before %obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-1")));
Code: [Select]
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, plant);


Note: if you don't want recoil, remove this line completely:
Code: [Select]
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-1")));

Code: [Select]
// Script

function RifleImage::onFire(%this,%obj,%slot)
{
   if(%obj.getDamagePercent() < 1.0)
      %obj.playThread(2, shiftAway);
   parent::onFire(%this, %obj, %slot);
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, plant);
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-1")));
}

This?
« Last Edit: April 23, 2011, 07:09:05 PM by Lørd Tøny »

It still doesn't randomize the projectile.


   -Paste Blastdown's code at the bottom (position doesn't matter though)
   -Change all instances of "minigun" to "rifle"
   -Change the number after %spread to whatever you want

Looks like you missed 75% of the steps, tony.

Well now I just get nothing but syntax errors.

Code: [Select]
// Script

function SFRevolverImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
%projectile = %this.projectile;
%spread = 0.00185;
%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;
« Last Edit: April 24, 2011, 06:58:58 PM by Lørd Tøny »

missing end bracket  :cookieMonster:

Code: [Select]
// Script

function SFRevolverImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
%projectile = %this.projectile;
%spread = 0.00185;
%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;
}