Author Topic: Burst-fire weapon?  (Read 1236 times)

I'm currently working on a weapon that is supposed to burst-fire 3 shots in one click, making the last 2 with less precision than the first one. I get the feeling this involves messing with image states, and I'm not so acquaintanced to their workings. Help is requested. Thanks in advance.

Each 'state' comes with several variables to affect what it does. Explanations of each: [X is state number]

General
stateName[X] - Name of the state. This is used in the transitions between states. (see below)
stateSound[X] - Sound played when it gets to this state. Put your "gun shot" sounds here.
stateSequence[X] - Animation played in the model during this state.
stateAllowImageChange[X] - Allows you to change weapons while in this state. You might want to disable this during the "fire" states of your weapon by setting it to false.
stateScript[X] - The function run when it gets to this state. For instance, "onFire" is a pre-coded state which fires the weapon's projectile directly forwards at the speed set in the projectile datablock. You can also code your own functions.

Emitters
stateEmitter[X] - Emitter datablock used during the state. This could be the gun muzzle flash during each fire state.
stateEmitterTime[X] - How long the emitter lasts, in seconds.
stateEmitterNode[X] - Where on the weapon the emitter is shown. muzzleNode, if on the model of the gun, marks its barrel (for where projectiles normally come out), but other points can also be used.

Shell
stateEjectShell[X] - When set to true, the gun will 'eject' a shell from what is specified by the rest of the variables.
These ones don't have state___[X] in them, they are in the rest of the datablock
casing - a debrisData datablock for the shell/casing that comes out.
shellExitDir - 3-Vector Direction relative to the player the shell comes out. "0 1 0" will eject directly forwards.
shellExitOffset - Offset to the weapon's ejectPoint (I think) the shell will come out.
shellExitVariance - ?
shellVelocity - Speed at which the shell comes out.

State Transitions
stateTimeoutValue[X] - The time after which the state will 'time out' and call stateTransitionOnTimeout
stateTransitionOnTimeout[X] - The name of the state this will change to after the specified time.
stateWaitForTimeout[X] - When set to true, it forces the weapon to wait for the time before changing any state. (The ones below will happen as soon as it occurs unless this is set)
stateTransitionOnAmmo[X] - The name of the state this will change to if [holder].setImageAmmo(slot,1) was previously set or is called. This can be used for advanced state transitions.
stateTransitionOnNoAmmo[X] - The name of the state this will change to if [holder].setImageAmmo(slot,0) was previously set or is called. This can be used for advanced state transitions.



What you probably want for your weapon is instead of the normal 'Fire' state which then changes to 'Smoke' and 'Reload', to create several 'FireA' 'FireB' 'FireC' states which each have the script set as 'onFireA', 'onFireB' and 'onFireC'. You could then use a script similar to most of the other slightly inaccurate weapons (shotgun, minigun) to fire one bullet at different spread values.

Code: [Select]
datablock ShapeBaseImageData(burstGunImage)
{
 ...
 
 stateName[2] = "FireA";
 stateScript[2] = "onFireA";
 stateTransitionOnTimeout[2]     = "FireB";
 stateTimeoutValue[2]            = 0.14;
 //Add other stuff for emitters/sounds/shells/etc.
 
 stateName[3] = "FireB";
 stateScript[3] = "onFireB";
 stateTransitionOnTimeout[3]     = "FireC";
 stateTimeoutValue[3]            = 0.14;
 //Add other stuff for emitters/sounds/shells/etc.
 
 stateName[4] = "FireC";
 stateScript[4] = "onFireC";
 stateTransitionOnTimeout[4]     = "Smoke";
 stateTimeoutValue[4]            = 0.14;
 //Add other stuff for emitters/sounds/shells/etc.
 
 ...
};

function BurstGunImage::onFireA(%this,%obj,%slot)
{
 //This makes it fire a normal shot
 WeaponImage::onFire(%this,%obj,%slot);
}

function BurstGunImage::onFireB(%this,%obj,%slot)
{
 //Find the code to make it fire a 'spread' or inaccurate shot
}

function BurstGunImage::onFireC(%this,%obj,%slot)
{
 //Same as B, but make it a wider spread
}
« Last Edit: December 29, 2008, 01:01:03 PM by Space Guy »

This needs to be added to the RtB wiki.