The gun I was scripting was fine.
Then I added sights to it.
What is wrong with it?
Code+picture:
//audio
datablock AudioProfile(btommyFireSound)
{
filename = "./Sounds/btommy_fire.wav";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(btommyEquipSound)
{
filename = "./Sounds/btommy_Use.wav";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(btommyClipInSound)
{
filename = "./Sounds/btommy_ClipInFULL.wav";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(btommyClipOutSound)
{
filename = "./Sounds/btommy_ClipOut.wav";
description = AudioClose3d;
preload = true;
};
//OtherData
AddDamageType("btommy", '<bitmap:add-ons/Weapon_btommy/Icons/ci_btommy> %1', '%2 <bitmap:add-ons/Weapon_btommy/Icons/ci_btommy> %1',0.75,1);
datablock ProjectileData(btommyProjectile)
{
projectileShapeName = "add-ons/Weapon_Gun/bullet.dts";
directDamage = 10;
directDamageType = $DamageType::btommy;
radiusDamageType = $DamageType::btommy;
brickExplosionRadius = 0;
brickExplosionImpact = true; //destroy a brick if we hit it directly?
brickExplosionForce = 10;
brickExplosionMaxVolume = 1; //max volume of bricks that we can destroy
brickExplosionMaxVolumeFloating = 2; //max volume of bricks that we can destroy if they aren't connected to the ground
impactImpulse = 80;
verticalImpulse = 40;
explosion = gunExplosion;
muzzleVelocity = 75;
velInheritFactor = 1;
armingDelay = 0;
lifetime = 4000;
fadeDelay = 3500;
bounceElasticity = 0.5;
bounceFriction = 0.20;
isBallistic = true;
gravityMod = 0.2;
hasLight = false;
lightRadius = 3.0;
lightColor = "0 0 0.5";
};
//////////
// item //
//////////
datablock ItemData(btommyItem)
{
category = "Weapon"; // Mission editor category
className = "Weapon"; // For inventory system
// Basic Item Properties
shapeFile = "./Models/btommyNH.dts";
rotate = false;
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;
//gui stuff
uiName = "Bioshock Thompson";
iconName = "./Icons/UI_btommy";
doColorShift = true;
colorShiftColor = "0.4 0.4 0.41 1.000";
// Dynamic properties defined by the scripts
image = btommyImage;
canDrop = true;
maxAmmo = 50;
canReload = 1;
};
////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(btommyImage)
{
// Basic Item properties
shapeFile = "./Models/btommy.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; //"0.7 1.2 -0.5";
rotation = eulerToMatrix( "0 0 0" );
// 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 = btommyItem;
ammo = " ";
projectile = btommyProjectile;
projectileType = Projectile;
casing = GunShellDebris;
shellExitDir = "1.0 0.1 1.0";
shellExitOffset = "0 0 0";
shellExitVariance = 10.0;
shellVelocity = 5.0;
//melee particles shoot from eye node for consistancy
melee = false;
//raise your arm up or not
armReady = true;
doColorShift = false;
// 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
// Initial start up state
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.7;
stateTransitionOnTimeout[0] = "LoadCheckA";
StateSequence[0] = "use";
StateSound[0] = "btommyEquipSound";
stateName[1] = "Ready";
stateTransitionOnNoAmmo[1] = "Reload";
stateTransitionOnTriggerDown[1] = "Fire";
stateAllowImageChange[1] = true;
stateName[2] = "Fire";
stateTransitionOnTimeout[2] = "Delay";
stateTimeoutValue[2] = 0.00;
stateFire[2] = true;
stateAllowImageChange[2] = false;
stateSequence[2] = "Fire";
stateScript[2] = "onFire";
stateEjectShell[2] = true;
stateEmitter[2] = gunFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateWaitForTimeout[2] = true;
StateSequence[2] = "fire";
stateSound[2] = btommyFireSound;
stateName[3] = "Delay";
stateTransitionOnTimeout[3] = "FireLoadCheckA";
stateTimeoutValue[3] = 0.06;
stateEmitter[3] = gunSmokeEmitter;
stateEmitterTime[3] = 0.06;
stateEmitterNode[3] = "muzzleNode";
//Torque switches states instantly if there is an ammo/noammo state, regardless of stateWaitForTimeout
stateName[4] = "LoadCheckA";
stateScript[4] = "onLoadCheck";
stateTimeoutValue[4] = 0.01;
stateTransitionOnTimeout[4] = "LoadCheckB";
stateName[5] = "LoadCheckB";
stateTransitionOnAmmo[5] = "Ready";
stateTransitionOnNoAmmo[5] = "ReloadWait";
stateName[6] = "ReloadWait";
stateTimeoutValue[6] = 0.3;
stateTransitionOnTimeout[6] = "Reload";
stateWaitForTimeout[6] = true;
stateName[7] = "Reload";
stateTimeoutValue[7] = 1.53;
stateScript[7] = "onReloadStart";
stateTransitionOnTimeout[7] = "ReloadB";
stateWaitForTimeout[7] = true;
StateSequence[7] = "reload1";
stateSound[7] = btommyClipOutSound;
stateName[8] = "ReloadB";
stateTimeoutValue[8] = 1.63;
stateTransitionOnTimeout[8] = "Reloaded";
stateWaitForTimeout[8] = true;
StateSequence[8] = "reload2";
stateSound[8] = btommyClipInSound;
stateName[9] = "Reloaded";
stateTimeoutValue[9] = 0.5;
stateScript[9] = "onReloaded";
stateTransitionOnTimeout[9] = "Ready";
stateName[10] = "Smoke";
stateEmitter[10] = gunSmokeEmitter;
stateEmitterTime[10] = 0.3;
stateEmitterNode[10] = "muzzleNode";
stateTimeoutValue[10] = 0.2;
stateTransitionOnTimeout[10] = "Ready";
stateTransitionOnTriggerDown[10] = "Fire";
stateName[11] = "ReloadSmoke";
stateEmitter[11] = gunSmokeEmitter;
stateEmitterTime[11] = 0.3;
stateEmitterNode[11] = "muzzleNode";
stateTimeoutValue[11] = 0.2;
stateTransitionOnTimeout[11] = "Reload";
stateName[12] = "FireLoadCheckA";
stateScript[12] = "onLoadCheck";
stateTimeoutValue[12] = 0.01;
stateTransitionOnTimeout[12] = "FireLoadCheckB";
stateName[13] = "FireLoadCheckB";
stateTransitionOnAmmo[13] = "Smoke";
stateTransitionOnNoAmmo[13] = "ReloadSmoke";
};
function btommyImage::onFire(%this,%obj,%slot)
{
if(vectorLen(%obj.getVelocity()) < 0.1 && (getSimTime() - %obj.lastShotTime) > 50)
{
%projectile = btommyProjectile;
%spread = 0.003;
}
else
{
%projectile = btommyProjectile;
%spread = 0.007;
}
%obj.lastShotTime = getSimTime();
%shellcount = 1;
%obj.playThread(2, plant);
%shellcount = 1;
%obj.toolAmmo[%obj.currTool]--;
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;
}
function btommyImage::onLoadCheck(%this,%obj,%slot)
{
if(%obj.toolAmmo[%obj.currTool] <= 0)
%obj.setImageAmmo(%slot,0);
else
%obj.setImageAmmo(%slot,1);
}
function btommyImage::onReloaded(%this,%obj,%slot)
{
%obj.toolAmmo[%obj.currTool] = 50;
%obj.setImageAmmo(%slot,1);
}
datablock ShapeBaseImageData(btommySightsImage)
{
shapeFile = "./Models/btommy.dts";
emap = true;
mountPoint = 0;
offset = "0 0 0";
eyeOffset = "-0.22584 0.5 +1.00"; //-Left +Right, -Back +Front, -Down +Up
rotation = eulerToMatrix( "0 0 1" );
correctMuzzleVector = true;
className = "WeaponImage";
item = btommyItem;
ammo = " ";
projectile = btommyprojectile;
projectileType = Projectile;
casing = gunShellDebris;
shellExitDir = "1.0 -1.3 1.0";
shellExitOffset = "0 0 0";
shellExitVariance = 15.0;
shellVelocity = 7.0;
melee = false;
armReady = true;
doColorShift = false;
colorShiftColor = btommyItem.colorShiftColor;
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "LoadCheckA";
stateName[1] = "Ready";
stateTransitionOnNoAmmo[1] = "reloadSequence";
stateTransitionOnTriggerDown[1] = "Fire";
stateAllowImageChange[1] = true;
stateSequence[1] = "ready";
stateName[2] = "Fire";
stateTimeoutValue[2] = 0.0504;
stateTransitionOnTimeout[2] = "Smoke";
stateFire[2] = true;
stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateSequence[2] = "fire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = btommyflashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = btommyshot1Sound;
stateName[3] = "Smoke";
stateEmitter[3] = gunSmokeEmitter;
stateEmitterTime[3] = 0.1;
stateTimeoutValue[3] = 0.03;
stateEmitterNode[3] = "muzzleNode";
stateTransitionOnTimeout[3] = "FireLoadCheckA";
stateName[4] = "Wait";
stateEjectShell[2] = true;
stateTimeoutValue[4] = 0.033;
stateScript[4] = "";
stateTransitionOnTimeout[4] = "Fire";
stateTransitionOnTriggerUp[4] = "Delay";
stateName[5] = "LoadCheckA";
stateScript[5] = "onLoadCheck";
stateTimeoutValue[5] = 0.01;
stateTransitionOnTimeout[5] = "LoadCheckB";
stateName[6] = "LoadCheckB";
stateTransitionOnAmmo[6] = "Ready";
stateTransitionOnNoAmmo[6] = "ReloadWait";
stateName[7] = "ReloadWait";
stateTimeoutValue[7] = 0.3;
stateScript[7] = "";
stateTransitionOnTimeout[7] = "reloadSequence";
stateWaitForTimeout[7] = true;
stateName[8] = "reloadSequence";
stateScript[8] = "setHKReN";
stateName[9] = "FireLoadCheckA";
stateScript[9] = "onLoadCheck";
stateTimeoutValue[9] = 0.01;
stateTransitionOnTimeout[9] = "FireLoadCheckB";
stateName[10] = "FireLoadCheckB";
stateTransitionOnAmmo[10] = "Wait";
stateTransitionOnNoAmmo[10] = "ReloadWait";
stateName[11] = "Delay";
stateTransitionOnTimeout[11] = "Ready";
stateTimeoutValue[11] = 0.106;
};
function btommySpawnProj(%this,%obj,%slot)
{
if(vectorLen(%obj.getVelocity()) < 1 && (getSimTime() - %obj.lastShotTime) > 1000)
%spread = 0.0003;
else
%spread = 0.0009;
if(vectorLen(%obj.getVelocity()) < 1 && (getSimTime() - %obj.lastShotTime) > 1500 && %obj.getMountedImage(0) == nameToID(btommySightsImage))
%spread = 0.0001;
else if((getSimTime() - %obj.lastShotTime) < 1500 && %obj.getMountedImage(0) == nameToID(btommySightsImage))
%spread = 0.0006;
%projectile = btommyprojectile;
%obj.lastShotTime = getSimTime();
%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;
}
function btommySightsImage::setHKReN(%this,%obj,%slot)
{
%obj.mountImage(btommyImage, 0, 0, 0);
%obj.toolAmmo[%obj.currTool] = 0;
}
function btommySightsImage::onFire(%this,%obj,%slot)
{
if(%obj.toolAmmo[%obj.currTool] > 0)
{
btommySpawnProj(%this,%obj,%slot);
%obj.toolAmmo[%obj.currTool]--;
}
else if(%this.item.maxAmmo == 0)
btommySpawnProj(%this,%obj,%slot);
}
function btommyImage::onFire(%this,%obj,%slot)
{
if(%obj.toolAmmo[%obj.currTool] > 0)
{
btommySpawnProj(%this,%obj,%slot);
%obj.toolAmmo[%obj.currTool]--;
}
else if(%this.item.maxAmmo == 0)
btommySpawnProj(%this,%obj,%slot);
}
function btommyImage::onReloadStart(%this,%obj,%slot,%projectile)
{
%obj.toolAmmo[%obj.currTool] = 0;
}
function btommyImage::onReloaded(%this,%obj,%slot)
{
%obj.toolAmmo[%obj.currTool] = %this.item.maxAmmo;
%obj.setImageAmmo(%slot,1);
}
package btommySightsSwitch
{
function armor::onTrigger(%this, %obj, %triggerNum, %val)
{
%client = %obj.client;
if(%triggerNum == 4 && %obj.isImageMounted(btommyImage) && %val && %obj.toolAmmo[%obj.currTool] != 0)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(btommySightsImage, 0);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
else if(%triggerNum == 4 && %obj.isImageMounted(btommySightsImage) && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(btommyImage, 0);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
Parent::onTrigger(%this, %obj, %triggerNum, %val);
}
};
activatePackage(btommySightsSwitch);
function btommyImage::onMount(%this,%obj,%slot)
{
Parent::onMount(%this,%obj,%slot);
%obj.hideNode("RHand");
%obj.hideNode("RHook");
%obj.hideNode("LHand");
%obj.hideNode("LHook");
}
function btommyImage::onUnMount(%this,%obj,%slot)
{
Parent::onMount(%this,%obj,%slot);
%obj.unHideNode("ALL");
if(isObject(%obj.client))
{
%obj.client.applyBodyParts();
%obj.client.applyBodyColors();
}
else
applyDefaultCharacterPrefs(%obj);
}
function btommySightsImage::onMount(%this,%obj,%slot)
{
Parent::onMount(%this,%obj,%slot);
%obj.hideNode("RHand");
%obj.hideNode("RHook");
%obj.hideNode("LHand");
%obj.hideNode("LHook");
}
function btommySightsImage::onUnMount(%this,%obj,%slot)
{
Parent::onMount(%this,%obj,%slot);
%obj.unHideNode("ALL");
if(isObject(%obj.client))
{
%obj.client.applyBodyParts();
%obj.client.applyBodyColors();
}
else
applyDefaultCharacterPrefs(%obj);
}