TurretShape scripting
by Ronald J Nelson · in Torque 3D Beginner · 05/29/2014 (11:18 pm) · 0 replies
The following is copy of the script I am using. I have just been copying and using what I could find as an example. My problems are that the weapon image is not visible until after the player mounts the turret and fires. Then it is actually mounting at the root of the stand. Finally, and it is probably related to the incorrect mounting location, but I cannot control the heading and pitch of the turret.
I would appreciate any help that can be provided and feel free to use the script if helps you in something you are working on. I am just experimenting, so I'm not particularly attached to it.
Thank you in advance.
I would appreciate any help that can be provided and feel free to use the script if helps you in something you are working on. I am just experimenting, so I'm not particularly attached to it.
Thank you in advance.
datablock DebrisData(TurretDebris)
{
explodeOnMaxBounce = false;
elasticity = 0.15;
friction = 0.5;
lifetime = 2.0;
lifetimeVariance = 0.0;
minSpinSpeed = 40;
maxSpinSpeed = 200;
numBounces = 5;
bounceVariance = 0;
staticOnMaxBounce = true;
gravModifier = 1.0;
useRadiusMass = true;
baseRadius = 1;
velocity = 30.0;
velocityVariance = 12.0;
};
//-----------------------------------------------------------------------------
// Turret Bullet Ammo
//-----------------------------------------------------------------------------
datablock ItemData(TurretAmmo)
{
// Mission editor category
category = "Ammo";
// Add the Ammo namespace as a parent. The ammo namespace provides
// common ammo related functions and hooks into the inventory system.
className = "Ammo";
// Basic Item properties
//shapeFile = "art/shapes/weapons/Turret/Turret_Legs.DAE";
shapeFile = "art/shapes/turrets/50cal.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
// Dynamic properties defined by the scripts
pickUpName = "turret ammo";
};
//-----------------------------------------------------------------------------
// Turret Weapon
//-----------------------------------------------------------------------------
datablock ItemData(TurretHead)
{
// Mission editor category
category = "Weapon";
// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";
// Basic Item properties
//shapeFile = "art/shapes/weapons/Turret/Turret_Head.DAE";
shapeFile = "art/shapes/turrets/turretBarrel.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
// Dynamic properties defined by the scripts
pickUpName = "a turret head";
description = "Turret Head";
image = TurretHeadImage;
reticle = "crossHair";
};
datablock ShapeBaseImageData(TurretHeadImage)
{
// Basic Item properties
//shapeFile = "art/shapes/weapons/Turret/Turret_Head.DAE";
shapeFile = "art/shapes/turrets/turretBarrel.dts";
emap = true;
// Specify mount point
mountPoint = 0;
// Add the WeaponImage namespace as a parent, WeaponImage namespace
// provides some hooks into the inventory system.
class = "WeaponImage";
className = "WeaponImage";
// Projectiles and Ammo.
item = TurretHead;
ammo = TurretAmmo;
projectile = BulletProjectile;
projectileType = Projectile;
projectileSpread = "0.02";
casing = BulletShell;
shellExitDir = "1.0 0.3 1.0";
shellExitOffset = "0.15 -0.56 -0.1";
shellExitVariance = 15.0;
shellVelocity = 3.0;
// Weapon lights up while firing
lightType = "WeaponFireLight";
lightColor = "0.992126 0.968504 0.708661 1";
lightRadius = "4";
lightDuration = "100";
lightBrightness = 2;
// Shake camera while firing.
shakeCamera = false;
camShakeFreq = "0 0 0";
camShakeAmp = "0 0 0";
// 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.
useRemainderDT = true;
// Initial start up state
stateName[0] = "Preactivate";
stateIgnoreLoadedForReady[0] = false;
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNotLoaded[0] = "WaitingDeployment"; // If the turret weapon is not loaded then it has not yet been deployed
stateTransitionOnNoAmmo[0] = "NoAmmo";
// Activating the gun. Called when the weapon is first
// mounted and there is ammo.
stateName[1] = "Activate";
stateTransitionGeneric0In[1] = "Destroyed";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.5;
stateSequence[1] = "Activate";
// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionGeneric0In[2] = "Destroyed";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";
stateSequence[2] = "scan";
// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionGeneric0In[3] = "Destroyed";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.2;
stateFire[3] = true;
stateRecoil[3] = "LightRecoil";
stateAllowImageChange[3] = false;
stateSequence[3] = "fire";
stateSequenceRandomFlash[3] = true; // use muzzle flash sequence
stateScript[3] = "onFire";
stateSound[3] = TurretFireSound;
stateEmitter[3] = GunFireSmokeEmitter;
stateEmitterTime[3] = 0.025;
stateEjectShell[3] = true;
// Play the reload animation, and transition into
stateName[4] = "Reload";
stateTransitionGeneric0In[4] = "Destroyed";
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTimeout[4] = "Ready";
stateWaitForTimeout[4] = "0";
stateTimeoutValue[4] = 0.0;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5] = "NoAmmo";
stateTransitionGeneric0In[5] = "Destroyed";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";
// No ammo dry fire
stateName[6] = "DryFire";
stateTransitionGeneric0In[6] = "Destroyed";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateScript[6] = "onDryFire";
// Waiting for the turret to be deployed
stateName[7] = "WaitingDeployment";
stateTransitionGeneric0In[7] = "Destroyed";
stateTransitionOnLoaded[7] = "Deployed";
stateSequence[7] = "wait_deploy";
// Turret has been deployed
stateName[8] = "Deployed";
stateTransitionGeneric0In[8] = "Destroyed";
stateTransitionOnTimeout[8] = "Ready";
stateWaitForTimeout[8] = true;
stateTimeoutValue[8] = 2.5; // Same length as turret base's Deploy state
stateSequence[8] = "deploy";
// Turret has been destroyed
stateName[9] = "Destroyed";
stateSequence[9] = "destroyed";
};
datablock TurretShapeData(TurretTemplate)
{
category = "Turrets";
//shapeFile = "art/shapes/weapons/Turret/TP_Turret.DAE";
//shapeFileFP = "art/shapes/weapons/Turret/FP_Turret.DAE";
shapeFile = "art/shapes/turrets/50cal.dts";
shapeFileFP = "art/shapes/turrets/50cal.dts";
maxDamage = 110;
explosion = GenericMediumExplosion;
destroyedLevel = 110;
disabledLevel = 0.84;
//debrisShapeName = "art/shapes/turrets/smallTurret.dts";
debris = TargetMajorDebris;
renderWhenDestroyed = false;
cameraMaxDist = 10;
maxEnergy = 280;
rechargeRate = 0.8;
cameraOffset = 2.5;
zRotOnly = false;
maxHeading = 90.0;
minPitch = 90.0;
maxPitch = 90.0;
headingRate = 1.0;
pitchRate = 1.0;
//startLoaded = true;
weaponLinkType = "IndividualFire"; //IndividualFire, GroupedFire, or FireTogether
numMountPoints = 1;
isProtectedMountPoint[0] = true;
mountPose[0] = sitting;
// Weapon mounting
numWeaponMountPoints = 1;
weapon[0] = TurretHead;
weaponAmmo[0] = TurretAmmo;
weaponAmmoAmount[0] = 10000;
maxInv[TurretHead] = 1;
maxInv[TurretAmmo] = 10000;
};
function TurretTemplate::onAdd(%this,%obj)
{
Parent::onAdd(%this,%obj);
}