Author Topic: setImageAmmo not working  (Read 951 times)

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

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

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Smoke";
stateTimeoutValue[2]            = 0.14;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "trigger";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = CarbonShotgunFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = CarbonShotgunShotSound;


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

stateName[4] = "Reload";
    stateTransitionOnNoAmmo[4] = "PreReload";
stateTransitionOnAmmo[4]     = "Ready";
stateTimeoutValue[4]            = 0.65;
stateSequence[4]                = "load";
    stateSound[4] = CarbonShotgunReloadSound;

stateName[5] = "PreReload";
    stateWaitForTimeout[5] = true;
stateTransitionOnTimeout[5]      = "Reload";
stateTimeoutValue[5]             = 0.2;


    stateName[6]                     = "AmmoCheck";
stateScript[6]                  = "onAmmoCheck";
   stateTransitionOnAmmo[6] = "Ready";
    stateTransitionOnNoAmmo[6] = "PreReload";
    stateAllowImageChange[6]         = true;
   
statename[7] = "shellpump";
stateScript[7]                  = "onPump";
stateSequence[7] = "pump";
stateSound[7] = CarbonShotgunPumpSound;
stateWaitForTimeout[7] = true;
stateTimeoutValue[7]            = 0.2;
stateEjectShell[7]       = true;
stateTransitionOnTimeout[7]     = "AmmoCheck";



};

function CarbonShotgunImage::onFire(%this, %obj, %slot)
{
%obj.playThread(2, shiftAway);

if(%obj.CarbonShotgunAmmo < 1)
{
%obj.CarbonShotgunAmmo --;

%projectile = CarbonShotgunProjectile;
%spread = 0.007;
%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 Projectile()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
else
{
%obj.setImageAmmo(%slot, 0);
}
}



function CarbonShotgunImage::onReload(%this, %obj, %slot)
{
if(%obj.CarbonShotgunAmmo == 6)
    {
%obj.setImageAmmo(%slot, 1);
%obj.playThread(2, shiftRight);
}
else
{
   %obj.CarbonShotgunAmmo++;
}
}

function CarbonShotgunImage::onAmmoCheck(%this, %obj, %slot)
{
   if(%obj.CarbonShotgunAmmo < 1)
      %obj.setImageAmmo(%slot, 0);
}

function CarbonShotgunImage::onPump(%this, %obj, %slot)
{
%obj.playThread(2, plant);
}
This isn't working
It is supposed to load 6 shells when you run out, then be able to fire 6 more, then load, etc.
BUT
It just lets you fire infinitely. Help!

For starters, you have a backwards if statement in onFire making sure you have less than one shells loaded to fire. You may also want to set it up to transition from ready onTriggerDown to ammoCheck, then from there to either fire or reload. Also, images are mounted with ammo set to 1, so you may want to put your ammo check script in a few other places as well.

For starters, you have a backwards if statement in onFire making sure you have less than one shells loaded to fire. You may also want to set it up to transition from ready onTriggerDown to ammoCheck, then from there to either fire or reload. Also, images are mounted with ammo set to 1, so you may want to put your ammo check script in a few other places as well.
I did what you said. It is broken and now plays no sound nor the reload animation, and fires nothing
Code: [Select]
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = CarbonShotgunDrawSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "AmmoCheck";
stateTransitionOnNoAmmo[1] = "AmmoCheck";
stateAllowImageChange[1]         = true;

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Smoke";
stateTimeoutValue[2]            = 0.14;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "trigger";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = CarbonShotgunFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = CarbonShotgunShotSound;


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

stateName[4] = "Reload";
    stateTransitionOnNoAmmo[4] = "PreReload";
stateTransitionOnAmmo[4]     = "Ready";
stateTimeoutValue[4]            = 0.65;
stateSequence[4]                = "load";
    stateSound[4] = CarbonShotgunReloadSound;

stateName[5] = "PreReload";
    stateWaitForTimeout[5] = true;
stateTransitionOnTimeout[5]      = "Reload";
stateTimeoutValue[5]             = 0.2;


    stateName[6]                     = "AmmoCheck";
stateScript[6]                  = "onAmmoCheck";
   stateTransitionOnAmmo[6] = "Fire";
    stateTransitionOnNoAmmo[6] = "PreReload";
    stateAllowImageChange[6]         = true;
   
statename[7] = "shellpump";
stateScript[7]                  = "onPump";
stateSequence[7] = "pump";
stateSound[7] = CarbonShotgunPumpSound;
stateWaitForTimeout[7] = true;
stateTimeoutValue[7]            = 0.2;
stateEjectShell[7]       = true;
stateTransitionOnTimeout[7]     = "Ready";



};

function CarbonShotgunImage::onFire(%this, %obj, %slot)
{

if(%obj.CarbonShotgunAmmo >= 1)
{
%obj.CarbonShotgunAmmo --;
%obj.playThread(2, shiftAway);
%projectile = CarbonShotgunProjectile;
%spread = 0.007;
%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 Projectile()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
else
{
%obj.setImageAmmo(%slot, 0);
}
}



function CarbonShotgunImage::onReload(%this, %obj, %slot)
{
if(%obj.CarbonShotgunAmmo == 6)
    {
%obj.setImageAmmo(%slot, 1);
%obj.playThread(2, shiftRight);
}
else
{
   %obj.CarbonShotgunAmmo++;
}
}

function CarbonShotgunImage::onAmmoCheck(%this, %obj, %slot)
{
   if(%obj.CarbonShotgunAmmo < 1)
      %obj.setImageAmmo(%slot, 0);
}

function CarbonShotgunImage::onPump(%this, %obj, %slot)
{
%obj.playThread(2, plant);
}

Oh, overlooked that onReload is never called. Need to set it as the state script.

Oh, overlooked that onReload is never called. Need to set it as the state script.
Did that, still not working. You take the shotgun out, and you click, and you play the "plant" animation and you can do nothing after that
Code: [Select]
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = CarbonShotgunDrawSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "AmmoCheck";
stateTransitionOnNoAmmo[1] = "AmmoCheck";
stateAllowImageChange[1]         = true;

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Smoke";
stateTimeoutValue[2]            = 0.14;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "trigger";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = CarbonShotgunFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = CarbonShotgunShotSound;


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

stateName[4] = "Reload";
    stateScript[4]                  = "onReload";
stateTransitionOnNoAmmo[4] = "PreReload";
stateTransitionOnAmmo[4]     = "Ready";
stateTimeoutValue[4]            = 0.65;
stateSequence[4]                = "load";
    stateSound[4] = CarbonShotgunReloadSound;

stateName[5] = "PreReload";
    stateWaitForTimeout[5] = true;
stateTransitionOnTimeout[5]      = "Reload";
stateTimeoutValue[5]             = 0.2;


    stateName[6]                     = "AmmoCheck";
stateScript[6]                  = "onAmmoCheck";
   stateTransitionOnAmmo[6] = "Fire";
    stateTransitionOnNoAmmo[6] = "PreReload";
    stateAllowImageChange[6]         = true;
   
statename[7] = "shellpump";
stateScript[7]                  = "onPump";
stateSequence[7] = "pump";
stateSound[7] = CarbonShotgunPumpSound;
stateWaitForTimeout[7] = true;
stateTimeoutValue[7]            = 0.2;
stateEjectShell[7]       = true;
stateTransitionOnTimeout[7]     = "Ready";



};

function CarbonShotgunImage::onFire(%this, %obj, %slot)
{

if(%obj.CarbonShotgunAmmo >= 1)
{
%obj.CarbonShotgunAmmo --;
%obj.playThread(2, shiftAway);
%projectile = CarbonShotgunProjectile;
%spread = 0.007;
%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 Projectile()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
else
{
%obj.setImageAmmo(%slot, 0);
}
}



function CarbonShotgunImage::onReload(%this, %obj, %slot)
{
if(%obj.CarbonShotgunAmmo == 6)
    {
%obj.setImageAmmo(%slot, 1);
%obj.playThread(2, shiftRight);
}
else
{
   %obj.CarbonShotgunAmmo++;
}
}

function CarbonShotgunImage::onAmmoCheck(%this, %obj, %slot)
{
   if(%obj.CarbonShotgunAmmo < 1)
      %obj.setImageAmmo(%slot, 0);
}

function CarbonShotgunImage::onPump(%this, %obj, %slot)
{
%obj.playThread(2, plant);
}

This still isn't working, I need help ASAP.