Author Topic: Weapon script--need help please  (Read 1989 times)

Im trying to make a fictional weapon, which is an automatic rifle, and everything is going fine so far. Right now i'm stuck on finding out what part of the .cs script controls the animation of the arm that swings the model making it look like recoil. Im asking this because I hope to make the recoil lower than the default pistol, and im sure that part of the script is wedged in there somewhere as i've seen weapons with no recoil at all.

I appreciate your help!

That would be this function right at the very end of the .cs (After Weapon Image, right down there at the end)

Code: [Select]
function BattleRifleImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}

To get rid of recoil completely, just delete that function.

To get less recoil however, I dunno.

Thanks! You get a pixelated Nintendo  :nes:

Also, if it isnt too much, is there a part of the script that controls bullet spread? (think shotgun) I'm tired of all the guns having 100% accuracy.

for one, you could give the bullets offset or gravity
or for the shotgun use this
Code: [Select]
function shotgunImage::onFire(%this,%obj,%slot)
{
%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;
}
that has 3 bullets,if you only want one use
Code: [Select]
function shotgunImage::onFire(%this,%obj,%slot)
{
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
%obj.playThread(2, shiftAway);

%projectile = %this.projectile;
%spread = 0.0015;
%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;
}
if you want a bigger spread change the %spread
credit to ephi


Wow, seriously thanks! Its beautiful but the only thing is that I cannot find the part of the segment of code you gave me that controls how you get kicked back a little bit.

This would be the kick-back effect
Where the "-3" is, change it to get more-less kickback, or give it a positive value for pull
Code: [Select]
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
Also this controls Bullet Spreadage (how wide of a spread is determined by how high the number is)

Code: [Select]
%spread = 0.0015;
And finally, this determines how many bullets are fired

Code: [Select]
%shellcount = 1;


Wasn't this weapon already posted?  This should probably be locked.