Author Topic: Shotgun script  (Read 2571 times)

Before I start, sorry for posting so much, just trying to learn how to mod.

Anyways, I'm working on a shotgun, but I've hit a problem; I don't know how to change the server.cs so that my weapon shoots a few bullets all at once, like a shotgun. I tried reading some tutorials, but none of them seem to relate to using Torque, or if that even changes anything. If someone could just point me towards the section in the server.cs that defines how many bullets come out at once, or something like that, I would be veeeery grateful. Thanks, in advance!

Update: I tried just using the default gun server.cs, but the shotgun won't show up when I try to spawn it. Here's the file, someone please work your magic! http://www.mediafire.com/download/0cbs2n2ev6y3yz5/Weapon_Shotgun.zip
« Last Edit: July 25, 2013, 02:00:47 PM by ArchaicModifications »

Can't help at the moment (on my iPod), but try this. Download basic shotty and look at server.cs. Spread script is at the bottom of it.

Can't help at the moment (on my iPod), but try this. Download basic shotty and look at server.cs. Spread script is at the bottom of it.
I looked and it appears to be the exact same as the default gun :/. Maybe I could just re-size the bullet and amp up the damage?

So I want to make it so that you have to wait some time between shots (Like a regular shotgun), but I'm a little bit confused. I went to the bottom, where it says StateTimeout, but I'm not sure which one to change the time of.

The line in bold is the one you want


   Statename[2]                                     = "Fire"
   stateTransitionTimeout[2]              = "Smoke"
   stateTimeoutValue[2]                  = 0.14


The lower the number goes is the shorter time in between shots.
This is based off deafault gun script

I looked and it appears to be the exact same as the default gun :/. Maybe I could just re-size the bullet and amp up the damage?
Post the script of the shotgun you downloaded. Not the datablocks, just the code under them; item data on down.

Post the script of the shotgun you downloaded. Not the datablocks, just the code under them; item data on down.
Okay, I found the script from a shotgun add-on. Here it is:
if($Sim::Time - %this.lastShot < 1)
   {
      return;
   }

   %this.lastShot = $Sim::Time;

   %obj.playThread(2, jump);
   %projectile = %this.projectile;
   %spread = 0.002;

   %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 * 1.1415926 * %spread;
   %y = (getRandom() - 0.5) * 10 * 1.1415926 * %spread;
   %z = (getRandom() - 0.5) * 10 * 1.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);
   %obj.addVelocity(vectorScale(%obj.getMuzzleVector(0), -4));
}

It doesn't work, though, and my shotgun doesn't even show up.

I also added the script to hide hands when holding the object, should I post that as well?

I also added the script to hide hands when holding the object, should I post that as well?
if it isn't working, go ahead


as for your shotgun, you forgot to put in the function, a needed part of the addon

Code: [Select]
function ShotgunImage::onFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
     
%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;
}

This is what you want to add, not the other thing.
« Last Edit: July 27, 2013, 01:35:24 PM by Aware »

if it isn't working, go ahead


as for your shotgun, you forgot to put in the function, a needed part of the addon

Code: [Select]
function ShotgunImage::onFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
     
%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;
}

This is what you want to add, not the other thing.
Thank you!

Okay, new problem. I want the sequence, "action" (The shotgun being roostered), to play after the firing sequence goes off. I tried changing stateSequence to Action, but it doesn't work. Help?
        stateName[4]         = "Reload";
   stateSequence[4]                = "Action";
   stateSound[4]                   = gunreloadSound;
   stateTransitionOnTriggerUp[4]     = "Ready";
   stateSequence[4]   = "Ready";

Edit: I tried it in-game, but the sequence doesn't play, and gunreloadSound plays randomly, during or in between firing.
« Last Edit: July 27, 2013, 02:43:06 PM by ArchaicModifications »

You are using stateSequence twice

You are using stateSequence twice
Oh. Well, now I feel stoopid, lol. Thank you!

Jesus, it's like I've got 99 problems, anyways. The animation will only play if you hold the left mouse button down until after you fire. Is there a way I can set a timeout, or make it so that the Reload animation plays after the fire animation?

Edit: I tried adding a stateTimeout and stateWaitForTimeout to [4], but all it did was make my shotty not show up in game. Do I need to change stateTransitionOnTriggerUp, or add something else?
« Last Edit: July 27, 2013, 09:39:18 PM by ArchaicModifications »

post what you have right now for all the states