Author Topic: OnTrigger package won't do anything. At all.  (Read 703 times)

Code: [Select]
package TF2MinigunAltFire
{
function Armor::onTriggerDown(%this,%obj,%slot,%val)
{
if(%obj.getMountedImage(0) $= TF2MinigunIdleImage.getID() && %slot $= 4 && %val)
{
%obj.TF2MinigunTriggerdown = 1;
%obj.setImageAmmo(0, 0);
schedule(500,0,TF2MinigunTriggerDown,%obj);
}
if(%obj.getMountedImage(0) $= TF2MinigunIdleImage.getID() && %slot $= 4 && %val $= 0)
{
%obj.TF2MinigunTriggerdown = 0;
%obj.setImageAmmo(0, 1);
}
if(%obj.getMountedImage(0) $= TF2MinigunImage.getID() && %slot $= 4 && %val)
{
%obj.TF2MinigunTriggerdown = 1;
%obj.setImageAmmo(0, 0);
schedule(500,0,TF2MinigunTriggerDown,%obj);
}
if(%obj.getMountedImage(0) $= TF2MinigunImage.getID() && %slot $= 4 && %val $= 0)
{
%obj.TF2MinigunTriggerdown = 0;
%obj.setImageAmmo(0, 1);
}     
Parent::onTriggerDown(%this,%obj,%slot,%val);
}

};
activatePackage(TF2MinigunAltFire);

function TF2MinigunTriggerDown(%obj)
{
if(%TF2MinigunTriggerDown == 1)
{
%obj.setImageAmmo(0, 0);
schedule(500,0,TF2MinigunTriggerDown,%obj);
}
if(%TF2MinigunTriggerDown == 0)
{
%obj.setImageAmmo(0, 1);
}
}
Yes, I know there was a better way to organize the different if statements, as they had very similar characteristics, but it's not what I am talking about. It's just that whatever I do, whatever I put in there, I am certain that this script simply does nothing. Is there something someone can please tell me that I am doing wrong?

Isn't it armor::onTrigger() not armor::onTriggerDown()?


Ya, I think that the definition of location is one of the variables to the function, and not part of the function name.

Ya, I think that the definition of location is one of the variables to the function, and not part of the function name.
If I understand what you mean, %val is it.

My script is currently fully functional. Thank you for your help.
However, the ammo system it uses apparently only works in reverse, which looks a bit odd in the code.
Code: [Select]
AddDamageType("TF2Minigun",   '<bitmap:add-ons/Weapon_TF2Minigun/CI_Minigun> %1',    '%2 <bitmap:add-ons/Weapon_TF2Minigun/CI_Minigun> %1',0.5,1);

datablock DecalData(TF2MinigunCI)
{
    textureName = "./CI_Minigun";
};    

datablock DecalData(TF2minigunicon)
{
    textureName = "./icon_TF2minigun";
};    

datablock ParticleData(TF2MinigunFlashParticle)
{
   dragCoefficient = 0;
   gravityCoefficient = 0;
   inheritedVelFactor = 1;
   constantAcceleration = 0;
   lifetimeMS = 30;
   lifetimeVarianceMS = 0;
   //textureName = "./muzzle";
   textureName = "base/data/particles/cloud";
   spinSpeed = 10;
   spinRandomMin = -500;
   spinRandomMax = 500;
   colors[0] = "1 1 0.5 0.5";
   colors[1] = "1 0.5 0 0.5";
   colors[2] = "1 0 0 0.5";
   sizes[0] = 0.9;
   sizes[1] = 0;
   sizes[2] = 0;
   useInvAlpha = false;
};

datablock ParticleEmitterData(TF2MinigunFlashEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 50;
   velocityVariance = 0;
   ejectionOffset = 0;
   thetaMin = 0;
   thetaMax = 1;
   phiReferenceVel = 0;
   phiVariance = 360;
   overrideAdvance = false;
   particles = "TF2MinigunFlashParticle";
   uiName = "TF2 Minigun Flash";
};

datablock ParticleData(TF2MinigunSmokeParticle)
{
   dragCoefficient         = 4;
   gravityCoefficient    = -1.0;
   inheritedVelFactor    = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS                = 425;
   lifetimeVarianceMS    = 55;
   textureName               = "base/data/particles/cloud";
   spinSpeed = 10.0;
   spinRandomMin = -500.0;
   spinRandomMax = 500.0;
   colors[0]       = "0.5 0.5 0.5 0.7";
   colors[1]       = "0.5 0.5 0.5 0.0";
   sizes[0]         = 0.05;
   sizes[1]         = 0.25;
   useInvAlpha = false;
};
datablock ParticleEmitterData(TF2MinigunSmokeEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 1.0;
   velocityVariance = 1.0;
   ejectionOffset    = 0.0;
   thetaMin             = 0;
   thetaMax             = 90;
   phiReferenceVel   = 0;
   phiVariance         = 360;
   overrideAdvance = false;
   particles = "TF2MinigunSmokeParticle";
};

//////////
// item //
//////////
datablock ItemData(TF2MinigunItem)
{
category = "Weapon";  // Mission editor category
className = "Weapon"; // For inventory system

// Basic Item Properties
shapeFile = "./Minigun.dts";
rotate = false;
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;

//gui stuff
uiName = "TF2 Minigun";
iconName = "./icon_TF2Minigun";
doColorShift = true;
colorShiftColor = "0.1 0.1 0.1 1.000";

// Dynamic properties defined by the scripts
image = TF2MinigunIdleImage;
canDrop = true;
};

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(TF2MinigunIdleImage)
{
   // Basic Item properties
   shapeFile = "./Minigun.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 -0.1 -0.5";
   eyeOffset = "0.30 1 -0.5";
   rotation = eulerToMatrix( "75 0 0" );
   eyerotation = eulerToMatrix( "75 50 -25" );

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off.  
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = TF2MinigunProjectile;
   projectileType = Projectile;

casing = GunShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 0 0";
shellExitVariance   = 15.0;
shellVelocity       = 7.0;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;

   doColorShift = true;
   colorShiftColor = TF2MinigunItem.colorShiftColor;//"0.1 0.1 0.1 1.000";

   //casing = " ";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                    = "Activate";
stateTimeoutValue[0]            = 0.15;
stateTransitionOnTimeout[0]     = "Ready";
stateSequence[0] = "root";
stateSound[0] = weaponSwitchSound;
stateScript[0]                  = "onActivate";

stateName[1]                    = "Ready";
stateTransitionOnTriggerDown[1] = "Spinup";
stateSequence[1] = "root";
stateAllowImageChange[1]        = true;
stateTransitionOnNoAmmo[1] = "Spinup";

stateName[2]                    = "Spinup";
stateAllowImageChange[2]        = false;
stateTransitionOnTimeout[2]     = "Fire";
stateTimeoutValue[2]            = 0.67;
stateSequence[2] = "Spin";

stateName[3] = "Fire";
stateScript[3]                  = "onFire";
};

function TF2MinigunIdleImage::onActivate(%this,%obj,%slot)
{
%obj.setImageAmmo(0, 1);
%obj.TF2MinigunTriggerdown = 0;
}

function TF2MinigunIdleImage::onFire(%this,%obj,%slot)
{
%obj.mountimage(TF2MinigunSpinupimage,0);
}

package TF2MinigunAltFire
{
function Armor::onTrigger(%this, %obj, %slot, %val)
{
if(%obj.getMountedImage(0) $= TF2MinigunIdleImage.getID() && %slot $= 4 && %val == 1)
{
%obj.TF2MinigunTriggerdown = 1;
//%obj.setImageAmmo(0, 0);
schedule(10,0,TF2MinigunTriggerDown,%obj);
}
if(%obj.getMountedImage(0) $= TF2MinigunIdleImage.getID() && %slot $= 4 && %val == 0)
{
%obj.TF2MinigunTriggerdown = 0;
%obj.setImageAmmo(0, 1);
}
if(%obj.getMountedImage(0) $= TF2MinigunImage.getID() && %slot $= 4 && %val == 1)
{
%obj.TF2MinigunTriggerdown = 1;
//%obj.setImageAmmo(0, 0);
schedule(10,0,TF2MinigunTriggerDown,%obj);
}
if(%obj.getMountedImage(0) $= TF2MinigunImage.getID() && %slot $= 4 && %val == 0)
{
%obj.TF2MinigunTriggerdown = 0;
%obj.setImageAmmo(0, 1);
}    
Parent::onTrigger(%this, %obj, %slot, %val);
}

};
activatePackage(TF2MinigunAltFire);

function TF2MinigunTriggerDown(%obj)
{
if(%obj.TF2MinigunTriggerDown == 1)
{
%obj.setImageAmmo(0, 0);
schedule(10,0,TF2MinigunTriggerDown,%obj);
}
if(%obj.TF2MinigunTriggerDown == 0)
{
%obj.setImageAmmo(0, 1);
}
}


////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(TF2MinigunSpinupImage)
{
   // Basic Item properties
   shapeFile = "./Minigun.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 -0.05 -0.25";
   eyeOffset = "0.30 0.75 -0.5";
   rotation = eulerToMatrix( "37.5 0 0" );
   eyerotation = eulerToMatrix( "38.5 25 -11" );

   doColorShift = true;
   colorShiftColor = TF2MinigunItem.colorShiftColor;//"0.1 0.1 0.1 1.000";

   //casing = " ";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                    = "Activate";
stateSequence[0] = "spin";
stateTimeoutValue[0]            = 0.2;
stateTransitionOnTimeout[0]     = "Ready";
stateAllowImageChange[0]        = false;

stateName[1] = "Ready";
stateSequence[1] = "spin";
statescript[1] = "OnReady";
};

function TF2MinigunSpinupImage::onReady(%this,%obj,%slot)
{
%obj.mountimage(TF2Minigunimage,0);
}

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(TF2MinigunSpindownImage : TF2MinigunSpinupImage)
{
   // Initial start up state
stateName[0]                    = "Activate";
stateSequence[0] = "root";
stateTimeoutValue[0]            = 0.2;
stateTransitionOnTimeout[0]     = "Ready";
stateAllowImageChange[0]        = false;
stateTransitionOnTriggerDown[0] = "Ready";

stateName[1] = "Ready";
stateSequence[1] = "root";
statescript[1] = "OnReady";
};

function TF2MinigunSpindownImage::onReady(%this,%obj,%slot)
{
%obj.mountimage(TF2MinigunIdleimage,0);
}


////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(TF2MinigunImage)
{
   // Basic Item properties
   shapeFile = "./Minigun.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = "0.30 0.05 -0.5";
   rotation = eulerToMatrix( "0 0 0" );
   eyerotation = eulerToMatrix( "2 0 3" );

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off.  
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = TF2MinigunProjectile;
   projectileType = Projectile;

casing = GunShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 0 0";
shellExitVariance   = 15.0;
shellVelocity       = 7.0;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;

   doColorShift = true;
   colorShiftColor = TF2MinigunItem.colorShiftColor;//"0.1 0.1 0.1 1.000";

 //Raycasting Weapons settings
   raycastWeaponRange = 1000;
   raycastWeaponTargets = $TypeMasks::FxBrickObjectType | //Targets the weapon can hit: Raycasting Bricks
   $TypeMasks::PlayerObjectType | //AI/Players
   $TypeMasks::StaticObjectType | //Static Shapes
   $TypeMasks::TerrainObjectType | //Terrain
   $TypeMasks::VehicleObjectType; //Vehicles
   raycastWeaponPierceTargets = ""; //Gun cannot pierce
   raycastExplosionProjectile = gunprojectile;
   raycastExplosionSound = ""; //sound played by exploding gunprojectile
   raycastDirectDamage = 9;
   raycastDirectDamageType = $DamageType::TF2Minigun;
   raycastSpreadCount = 1;
   raycastSpreadAmt = 0.004;
   raycastTracerProjectile = TF2BulletTrailProjectile;

   //casing = " ";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                    = "Activate";
stateScript[0] = "OnActivate";
stateTimeoutValue[0]            = 0.15;
stateTransitionOnTimeout[0]     = "Ready";
stateSequence[0] = "Spin";

stateName[1]                    = "Ready";
stateSequence[1] = "Spin";
stateTimeoutValue[1]            = 1.00;
stateTransitionOnTimeout[1]     = "Spindown";
stateTransitionOnTriggerDown[1] = "Fire";
stateTransitionOnNoAmmo = "AltFire";

stateName[2]                    = "AltFire";
stateSequence[2] = "Spin";
stateTransitionOnTriggerDown[2] = "Fire";
stateTransitionOnAmmo[2] = "Ready";

stateName[3]                    = "Fire";
stateSequence[3] = "Spin";
stateTransitionOnTimeout[3]     = "Smoke";
stateTimeoutValue[3]            = 0.01;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = TF2MinigunFlashEmitter;
stateEmitterTime[3] = 0.01;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = gunShot1Sound;
stateEjectShell[3]       = true;

stateName[4] = "Smoke";
stateEmitter[4] = TF2MinigunSmokeEmitter;
stateEmitterTime[4] = 0.05;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4]            = 0.05;
stateTransitionOnTimeout[4]     = "AltFire";

stateName[5]                    = "Spindown";
stateSequence[5] = "root";
stateScript[5]             = "OnSpindown";

};

function TF2MinigunImage::onActivate(%this,%obj,%slot)
{
%obj.SetImageAmmo(0, 1);
}

function TF2MinigunImage::onFire(%this,%obj,%slot)
{
Parent::onFire(%this,%obj,%slot);
}

function TF2MinigunImage::onSpindown(%this,%obj,%slot)
{
%obj.mountimage(TF2MinigunSpindownimage,0);
}

You see, in the TF2MinigunIdle image where it checks if it has NO ammo, which happens when you hold M2, it initiates this spinup sequence.
I've been having a glitch that if I make it check if it does HAVE ammo, while the M2 package sets it to be, whenever equip the damn thing it just starts looping the different images

However, even though I use this ammo system in reverse, it works.

Also, is there anything here that I could perhaps organize differently to make it perhaps a little less hacky/laggy/unnecessary?
« Last Edit: August 27, 2010, 02:25:37 PM by The Titanium »

I found this out by myself without the help of any of you bastards.
Thank you so much!
:cookieMonster:

So why do you need the three separate weapon images? You're already triggering state changes by stateTransitionOn[No]Ammo, so you can use that to do any animations and scripts you need.

Because I'm a stupid crap and I can't model anything so I went ahead and stole Racer's tf2 minigun model and made it in three different positions to make it look like its moving from up to down.