Author Topic: [Tutorial] Ironsights; How to add.  (Read 7116 times)

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.

Summary
First 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.

Scripting
So, 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.
Code: [Select]
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.
Code: [Select]
////////////////
//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!
Code: [Select]
};

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..
Code: [Select]
eyeOffset = 0; //"0.0 1.0 -0.85"Change that to...
Code: [Select]
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)
Code: [Select]
eyeOffset = "0 0.3 -0.73"; //-Left +Right, -Back +Front, -Down +UpREMEMBER! 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.

Neat, thanks for the tutorial. I'll try it out right away.

New problem; I modified the gun script and it would not show up in the addons list.
Here
is the addon.



« Last Edit: March 13, 2011, 04:00:27 PM by slimabob »

Please fix this up a bit. <-Besides that crap great job, Thanks for posting this ill be sure to fav this page.



Here
is the addon.
"The file link that you requested is not valid. " Use mediafire?

On the part with the package, you should have people change the package name. Since if lots of people use this and don't change the name, the add-ons wouldn't be compatible.


Uploaded to mediafire.
The .zip contains the folder called Weapon_Tactical_Gun, make sure that all the contents of that folder are in the main drectory of the .zip. Not in a subdirectory. (You have it as Weapon_Tactical_Gun.zip/Weapon_Tactical_Gun/Server.cs you have to have it as Weapon_Tactical_Gun.zip/Server.cs)

Looks like a great tutorial, even though I'm not too thrilled about the prospect of more ironsighted weapons in Blockland.

Can you lock the camera onto a model node within the weapon as an alternative?

I always thought this was common sense... :/

Looks like a great tutorial, even though I'm not too thrilled about the prospect of more ironsighted weapons in Blockland.
Why?

Can you lock the camera onto a model node within the weapon as an alternative?


I do not think so. You simply have to tweak the eyeOffset Values in the script to make it line up.

I do not think so. You simply have to tweak the eyeOffset Values in the script to make it line up.
Okaaaay...
I'm still gonna test it out sometime when I get the chance.
Or not if someone tries it.

To be honest. I hate ironsights in Blockland.