Ironsights; How-To-Add. The Complete Guide.This guide was created using the Bushmaster ACR as a base, which uses Lilboarder32's imageSwitch package, and Ephialtes' random spread package.
SummaryFirst off, I have to thank Lilboarder, for his wonderful help. Second of all..
Welcome to Ironsights; How-To-Add.
Now, to start off this tutorial, you need to meet a few requirements. You need to have...
Notepad (or any other text editing program)
A gun model
A gun script
A working gun with no bugs, in Blockland
And, once you have those things, you are ready to begin.
ScriptingSo, to start off, I'm going to just give you the code, so you can mess around and implement that, right away if you wish.
package imageSwitch
{
function Armor::onTrigger(%this,%obj,%slot,%val)
{
Parent::onTrigger(%this,%obj,%slot,%val);
if(%slot == 4 && %val)
{
if(%obj.getMountedImage(0) == IMAGE1.getID())
{
%obj.updateArm(IMAGE2);
%obj.mountImage(IMAGE2,0);
}
else if(%obj.getMountedImage(0) == IMAGE2.getID())
{
%obj.updateArm(IMAGE2);
%obj.mountImage(IMAGE1,0);
}
}
}
};
activatePackage(imageSwitch);
Now wait, what?
You probably don't have two images assigned yet, so, I'll give you the code for a new image aswell.
////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(DATA2Image)
{
// Basic Item properties
shapeFile = "./DATA.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.0 1.0 -0.85"
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 = BowItem;
ammo = " ";
projectile = DATAProjectile;
projectileType = Projectile;
casing = DATAShellDebris;
shellExitDir = "-1.0 -1.0 -3.0";
shellExitOffset = "0 0 0";
shellExitVariance = 15.0;
shellVelocity = 10.0;
//melee particles shoot from eye node for consistancy
melee = false;
//raise your arm up or not
armReady = true;
LarmReady = true;
doColorShift = false;
colorShiftColor = DATAItem.colorShiftColor;//"0.400 0.196 0 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.
// The animation dustLock is used to reset the bolt to the closed
// position when you pick it up.
stateName[0] = "Activate";
stateSequence[0] = "dustLock";
stateTimeoutValue[0] = 0.23;
stateTransitionOnTimeout[0] = "Ready";
stateSound[0] = weaponSwitchSound;
stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Fire";
stateAllowImageChange[1] = true;
stateSequence[1] = "ready";
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Smoke";
stateTimeoutValue[3] = 0.15;
stateFire[3] = true;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = DATAFlashEmitter;
stateEmitterTime[3] = 0.08;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = DATAFireSound;
stateEjectShell[3] = true;
stateName[4] = "Smoke";
stateEmitter[4] = DATASmokeEmitter;
stateEmitterTime[4] = 0.12;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4] = 0.0;
stateTransitionOnTimeout[4] = "Ready";
};
Good! Now that you defined a new image, give it the name of your first image, but increase the number value on the end by one. Remember, this was using my bACR script, so you should probably just find that code in your server.cs, and copy+paste it, edit it, etc, yeah. (I replaced my datablock names with DATA, so if you did use it, it's easier to change.)
Now, you need to take your ironsight code that we gave you earlier, and insert it at the ABSOLOUTE end of your server.cs!
};
MissionCleanup.add(%p);
}
return %p;
}
PASTE IT HERE. DO NOT ADD THIS CODE.
Voila! You have added your imageswitcher, and in theory, you can change images right now, simply via right clicking! (note, if you did JUST THIS, the gun will probably do nothing, and be very uneventful, and probably broken, bare with me for a bit longer.) So, now, you should go up to the code in IMAGE2, saying..
eyeOffset = 0; //"0.0 1.0 -0.85"
Change that to...
eyeOffset = "0.0 1.0 -0.85"
Now, your gun should be slightly offset when you right click, but it won't be looking down the sights, so adjust that until you are, OR, use the easy-adjustment guide + base.
(this is what I used in my script for the eyeOffset)
eyeOffset = "0 0.3 -0.73"; //-Left +Right, -Back +Front, -Down +Up
REMEMBER! You may have to do A LOT of trial and error, this took me 6 hours to get right!
But, if you did all of this correctly, you should have working ironsights.
All of the material is used from my RTB topic.