Author Topic: Delays  (Read 630 times)

How or what is the function for delaying functions? Is it wait(#) Where # is the number of MS to wait before continuing the script? or whatever its called. I just want a delay for the projectile loop in this script:

Code: [Select]
function M4203Image::onFire(%this,%obj,%slot)
{
%projectile = M4ACOGProjectile;
%spread = 0.0007;
%shellcount = getRandom(3,6);

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;
}

What I'm trying to do (incase you don't get everything I said) is to do a Burst fire mode. Burst fire is firing single shots that have delays but each shots fire around 3 to 6 bullets, and each bullet dont fire all at once, they fire simultaneuously  after another.

If my idea doesnt work. What else can you suggest?

Thanks for the upcoming help.

EDIT: Should I go for schedules?
« Last Edit: October 02, 2008, 06:14:41 AM by jaydee0004 »

schedule(time, 0, command,<arg1...argN>);
Would call command(<arg1...argN>); after time miliseconds.
obj.schedule(time, command, <arg1...argN>);
Would call obj.command(<arg1...argN>); after time miliseconds.

or if you would want a burst fire gun you could use states like this:

Code: [Select]
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "Fire";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Fire2";
stateTimeoutValue[2]            = 0.14;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = glockFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = glockShot1Sound;
stateEjectShell[2]       = true;

stateName[3] = "Smoke";
stateEmitter[3] = glockSmokeEmitter;
stateEmitterTime[3] = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateTimeoutValue[3]            = 0.01;
stateTransitionOnTimeout[3]     = "Reload";

stateName[4] = "Reload";
stateSequence[4]                = "Reload";
stateTransitionOnTriggerUp[4]     = "Ready";
stateSequence[4] = "Ready";

stateName[5]                    = "Fire2";
stateTransitionOnTimeout[5]     = "Fire3";
stateTimeoutValue[5]            = 0.14;
stateFire[5]                    = true;
stateAllowImageChange[5]        = false;
stateSequence[5]                = "Fire";
stateScript[5]                  = "onFire";
stateWaitForTimeout[5] = true;
stateEmitter[5] = glockFlashEmitter;
stateEmitterTime[5] = 0.05;
stateEmitterNode[5] = "muzzleNode";
stateSound[5] = glockShot1Sound;
stateEjectShell[5]       = true;

  stateName[6]                    = "Fire3";
stateTransitionOnTimeout[6]     = "Smoke";
stateTimeoutValue[6]            = 0.14;
stateFire[6]                    = true;
stateAllowImageChange[6]        = false;
stateSequence[6]                = "Fire";
stateScript[6]                  = "onFire";
stateWaitForTimeout[6] = true;
stateEmitter[6] = glockFlashEmitter;
stateEmitterTime[6] = 0.05;
stateEmitterNode[6] = "muzzleNode";
stateSound[6] = glockShot1Sound;
stateEjectShell[6]       = true;

If you're firing more than two or three bursts, it might be worth experimenting with the state transition system to get a short 'looping' phase which keeps running onFire after you click, counting upwards, and using %obj.setImageAmmo(%slot,%ammo)/stateTransitionOn[No]Ammo to cut out of the loop and back to 'Ready'.

If you're firing more than two or three bursts, it might be worth experimenting with the state transition system to get a short 'looping' phase which keeps running onFire after you click, counting upwards, and using %obj.setImageAmmo(%slot,%ammo)/stateTransitionOn[No]Ammo to cut out of the loop and back to 'Ready'.

Is there any other reference I can look upon to?

I used a system in the Gravity Gun to keep the "GravLoop" state running (and calling the script "onGrav" which I made) while you held down the left button and while you still held a valid object. (e.g. if it was knocked out of your hand or you mounted a vehicle you are holding it stopped) Try looking at that script for an example of how it's used.