Page 1 of 2

Iron Sight Tutorial (FAQ)

Posted: Mon Oct 24, 2011 7:48 pm
by kinetosimpetus
http://www.youtube.com/watch?v=-xN3brwjfe8

It's pretty simple, as long as you know how to create a custom ingame.lvl which is outlined HERE.

The added entry in data_MODID\Common\ingame.req is like this:

Code: Select all

    REQN
    {
        "config"
        "1playerhud"
    }
If ironsights are the only thing you want to do with your ingame.lvl, the whole .req can look like this:

Code: Select all

ucft
{
    REQN
    {
        "config"
        "1playerhud"
    }
}
Make a 512 x 512 .tga that is completely transparent. Set this as the ScopeTexture in every weapon you want to use ironsights with. I tried a smaller one, 8 x 8, but it didn't work. Simply loading a null ScopeTexture will result in a default one being used.

I made the ironsights by adding a second weapon icon, like the ones in the lower left corner, or "floating" if they are new weapons, but the positioning has to be in the right spot for ironsights, and it has to display them at pretty much the opposite times that the actual weapon icons are shown.

The file 1playerhud.hud is located in data_MODID\Common\hud\PC. This is the file usually edited for making custom huds. I think you could rename it to something else if you want to keep separate hud files, just list the names of the hud files you need in the ingame.req under config.

Here is my 1playerhud.hud:
Hidden/Spoiler:
[code]FileInfo("1playerhud")
{
Viewports(1)

}

Group("player1weaponinformationforironsights")
{
PropagateAlpha(1)

Viewport(1)

ZOrder(255)

EventEnable("player1.spawn")
EventDisable("player1.die")

Group("player1weapon1groupforironsights")
{
Viewport(1)
EventEnable("initialize")

Model3D("player1weapon1mesh")
{
EventMesh("player1.weapon1.mesh")

Viewport(1)

ZOrder(5)

EventEnable("player1.weapon1.disable")
EventDisable("player1.weapon1.mesh")

MeshInfo("rep_weap_inf_dc15carbine")
{
Position(0.500000, 0.950000, 0.000000, "Viewport")
Rotation(0.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("rep_weap_inf_pistol_dc18")
{
Position(0.500000, 0.950000, 0.000000, "Viewport")
Rotation(0.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("kin_weap_inf_rifle_dc15ax")
{
Position(0.500000, 1.200000, 0.000000, "Viewport")
Rotation(-5.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("rep_weap_inf_rifle")
{
Position(0.500000, 1.200000, 0.000000, "Viewport")
Rotation(-5.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
}
}
}[/code]
Updated sample code including floating icon fix here.

The first part, "FileInfo", I don't really know what it does, but I don't think it hurts...

The rest is a modification of part of the original hud which I deleted.

The first and outermost "Group" has EventEnable and EventDisable codes that turn this HUD element off when you die or enter a CP. Otherwise ironsights will appear when either of those happen.

I dont know if the inner group is needed, it was like this in the original, so I left it.

The "Model3D" section has 2 more events, these are simply reversed from the original, which hides the weapon icons when zooming in with a scope, so now the new set of icons will appear when zooming as long as the weapon uses a scope.

To add a weapon to the Model3d, copy one of the "MeshInfo" Blocks and change the name to the name of the weapon's .msh. Then test it ingame, if it needs to be moved down, try adding 0.05 to the middle Position number, or subtracting if it is too low. If a weapon is exceptionally long or tall, the first rotation parameter can be changed to rotate the weapon. Use a negative angle to aim down.

If you don't add a meshinfo block for a weapon, an icon will 'float' in the upper left corner of the screen, so add a meshinfo to move it offscreen. Moving the weapon to the left should work:

Code: Select all

Position(-0.500000, 0.000000, 0.000000, "Viewport")
in your mission lua, find the ReadDataFile line for the global ingame.lvl that should already be there, copy and paste a line above or below it adding "dc:" without the quotes before the word "ingame".

Munge with only Common checked.

After munging, the ingame.lvl will have to be copied from data_MODID\_LVL_PC to your mod's addon folder: gamedata\addon\MODID\data\_LVL_PC\

Re: Tutorial: Ironsights

Posted: Mon Oct 24, 2011 8:08 pm
by yuke5
This is fantastic! :D Belongs in the FAQ for sure. I'm going to add this to all my future/current maps/mods right away. Thank you very much for doing this, you're too kind.

Re: Tutorial: Ironsights

Posted: Mon Oct 24, 2011 8:10 pm
by Noobasaurus
What exactly is an "ironsight"? I have an assumption it's the first-person gun in the middle but I'm not exactly sure...

Re: Tutorial: Ironsights

Posted: Mon Oct 24, 2011 8:11 pm
by yuke5
Watch the video posted at the top of the thread.

Re: Tutorial: Ironsights

Posted: Mon Oct 24, 2011 8:13 pm
by Cerfon Rournes
Awesome! Thanks :)

Re: Tutorial: Ironsights

Posted: Mon Oct 24, 2011 8:16 pm
by AQT
@Noobasaurus: In addition to what yuke wrote: Iron Sight. :google:

Thanks for the tutorial, kinetos! :thumbs:

Re: Tutorial: Ironsights

Posted: Mon Oct 24, 2011 8:19 pm
by Unlucky13
Nice job! One more thing to make BF2 so much better.

Re: Iron Sight Tutorial (FAQ)

Posted: Tue Oct 25, 2011 4:36 am
by naru1305
thanks for this tutorial :bowdown:
i think we will see many ironsights next time :D

Re: Iron Sight Tutorial (FAQ)

Posted: Tue Oct 25, 2011 9:15 am
by kinetosimpetus
Oh, I forgot something. For weapons you DON'T want to us iron sights, you need to add a msh info block that moves the icon off screen.

Re: Iron Sight Tutorial (FAQ)

Posted: Wed Oct 26, 2011 8:51 pm
by AQT
It seems that iron sights are incompatible with weapons whose HUD icons were fixed using FragMe!'s tutorial. This was puzzling me for the last few hours. Just putting it out there for anyone who may be having problems getting the weapons to show up.

Re: Iron Sight Tutorial (FAQ)

Posted: Wed Oct 26, 2011 10:12 pm
by Fiodis
Pity. Then if we have custom weapon models we need to use stock icons for them if we want ironsights?

Re: Iron Sight Tutorial (FAQ)

Posted: Wed Oct 26, 2011 10:15 pm
by kinetosimpetus
I am not sure what the problem is. In the video the DC-15s has a fixed icon as well as ironsights.

Re: Iron Sight Tutorial (FAQ)

Posted: Wed Oct 26, 2011 11:32 pm
by Ninja
kinetosimpetus wrote:I am not sure what the problem is. In the video the DC-15s has a fixed icon as well as ironsights.
Is the DC-15 icon placed by the v1.3 patch or is the it placed using FragMe!'s icon fix?

I had to "unfix" icons to get iron sights to work on weapons with fixed icons, but it worked fine with a pistol model which the v1.3 patch fixed the icon for.

Re: Iron Sight Tutorial (FAQ)

Posted: Thu Oct 27, 2011 12:27 am
by kinetosimpetus
It is possible that weapon was fixed by the patch I guess.

Re: Iron Sight Tutorial (FAQ)

Posted: Thu Oct 27, 2011 2:07 am
by Cerfon Rournes
I have gotten the Ironsight working with fixed icons (for custom/stock models)
This does not require a extra weapons file.
In 1playerhud find this line.
Hidden/Spoiler:
[code]Group("player1weapon1group")
{
Viewport(1)
Position(1.046161, -1.150412, 0.000000, "Viewport")
EventEnable("initialize")
Model3D("player1weapon1mesh")
{
EventMesh("player1.weapon1.mesh")
Viewport(1)
ZOrder(5)
EventEnable("player1.weapon1.mesh")
EventDisable("player1.weapon1.disable")
MeshInfo("hud_vehicle_lasers")
{
Position(-0.185992, 0.354928, -0.000509, "Viewport")
Rotation(0.804269, 359.994110, 359.999695)
Scale(1.200000, 1.200000, 1.200000)
}[/code]
Under that will be listed stock weapons with their fixed icon positions.
So, you can load your weapon there as well. (Since you are loading a custom ingame.lvl) Simply copy one that is relevant to the size, positioning of your custom model,( Example, if your model is a rifle, use imp_weap_inf_e11's position as a ref) and paste it right under/over the original Meshinfo line. Then replace the msh name with your custom one.
Example. Some lines before I add the custom Meshinfo line.
Hidden/Spoiler:
[code]MeshInfo("hud_imp_flamethrower")
{
Position(-0.173776, 0.358333, 0.205979, "Viewport")
Rotation(0.013809, 0.000000, 359.991669)
Scale(0.250001, 0.250001, 0.250001)
}

MeshInfo("imp_weap_inf_e11")
{
Position(-0.242922, 0.360546, 0.003365, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
}

MeshInfo("imp_weap_inf_pistol")
{
Position(-0.264184, 0.356163, -0.003873, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
Scale(1.240000, 1.240000, 1.240000)
}[/code]
I copy the imp_weap_inf_e11, put it under, and change the name to a custom msh.
Hidden/Spoiler:
[code] MeshInfo("hud_imp_flamethrower")
{
Position(-0.173776, 0.358333, 0.205979, "Viewport")
Rotation(0.013809, 0.000000, 359.991669)
Scale(0.250001, 0.250001, 0.250001)
}

MeshInfo("imp_weap_inf_e11")
{
Position(-0.242922, 0.360546, 0.003365, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
}

MeshInfo("esm_r37_rifle")
{
Position(-0.242922, 0.360546, 0.003365, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
}

MeshInfo("imp_weap_inf_pistol")
{
Position(-0.264184, 0.356163, -0.003873, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
Scale(1.240000, 1.240000, 1.240000)[/code]
Then just save, munge, and copy the ingame to your respective addon folder.
So far, this has worked for me every time. I hope this helps anyone having problems. :)
Remember, you can do this for any weapon1 floating icon.

Re: Iron Sight Tutorial (FAQ)

Posted: Sun Oct 30, 2011 8:02 pm
by SAMofBIA
in addition to the amazingly awesome ironsight, the clone skin is pretty great too!

Re: Iron Sight Tutorial (FAQ)

Posted: Sun Oct 30, 2011 9:03 pm
by Ninja
Cerfon Rournes wrote:I have gotten the Ironsight working with fixed icons (for custom/stock models)
This does not require a extra weapons file...

Then just save, munge, and copy the ingame to your respective addon folder.
So far, this has worked for me every time. I hope this helps anyone having problems. :)
Remember, you can do this for any weapon1 floating icon.
When I tried this, it just added another icon, there was still one floating in the middle of the screen. I think this would only work if you replace the default ingame.lvl.

Re: Iron Sight Tutorial (FAQ)

Posted: Mon Oct 31, 2011 3:46 pm
by Cerfon Rournes
Are you using a custom weapon? It it's stock, it should be already fixed.. :?
EDIT
You were correct, you need to replace the global ingame for my method to work, sorry for not mentioning that..
Because of that, my tuto is kinda useless..

Re: Iron Sight Tutorial (FAQ)

Posted: Thu Nov 03, 2011 5:39 pm
by kinetosimpetus
I've been trying to get floating icons fixed at the same time as using ironsights, and haven't gotten it to work without replacing the global ingame.lvl. I think if floating icons were fixed in the global ingame, the local ingame can make ironsights without conflict, but I haven't tried it that way yet. *

The extraweapons fix makes the original floating icon invisible, then adds a new visible one that it can manipulate to the right position. the problem is, when you zoom in, the thing that makes the floating icon invisible now seems to make the ironsights invisible, but leaves part of an apparently new floating icon in the corner.

I have also tried making a complete ingame.lvl to use as a local ingame, and remove the original ingame from the lua, but that results in a ctd.

*I don't want to edit the global ingame as long as there is a chance that the local one can be made to work, i don't like editing the global ingame.lvl because if I do it to fix my mod, and someone else edits it to fix their mod, and 5 other people edit it to fix their mod and make custom HUD's, players will have to choose whose ingame to use, and they might not all work with every mod. and installation would be harder.

My current 1playerhud.hud
Hidden/Spoiler:
[code]FileInfo("1playerhud")
{
Viewports(1)

}

Group("player1weaponinformationforironsights")
{
PropagateAlpha(1)

Viewport(1)

ZOrder(255)

EventEnable("player1.spawn")
EventDisable("player1.die")

Group("player1weapon1groupforironsights")
{
Viewport(1)
EventEnable("initialize")

Model3D("player1weapon1mesh")
{
EventMesh("player1.weapon1.mesh")

Viewport(1)

ZOrder(5)

EventEnable("player1.weapon1.disable")
EventDisable("player1.weapon1.mesh")

MeshInfo("kin_weap_inf_rifle_dc15ax")
{
Position(0.500000, 1.200000, 0.000000, "Viewport")
Rotation(-5.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("rep_weap_inf_rifle")
{
Position(0.500000, 1.200000, 0.000000, "Viewport")
Rotation(-5.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("rep_weap_inf_pistol_dc18")
{
Position(0.500000, 0.950000, 0.000000, "Viewport")
Rotation(0.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("rep_weap_inf_dc15carbine")
{
Position(0.500000, 0.950000, 0.000000, "Viewport")
Rotation(0.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
MeshInfo("rep_weap_inf_pistol_mini_r")
{
Position(0.500000, 1.050000, 0.000000, "Viewport")
Rotation(0.000000, 180.000000, 0.000000)
Scale(20.000000, 20.00000, 20.000000)
}
}
}
}[/code]
extraweapons.hud
Hidden/Spoiler:
[code]Code:

ViewPort("Transforms")
{


//EventNameFilter("player%")


// First Weapons Section

TransformNameMesh("player1weapon1")
// add msh names of first weapons here and remove unused lines
{
NameMesh("rep_weap_inf_pistol_mini_r", "com_inv_mesh")
//NameMesh("rep_weap_inf_carbine", "com_inv_mesh")
//NameMesh("rep_weap_inf_dc15m", "com_inv_mesh")
//NameMesh("disrupter_rifle", "com_inv_mesh")
//NameMesh("weap_inf_dc17pistol_r_small", "com_inv_mesh")
NameMesh("delta_weap_helm_pistol", "com_inv_mesh")
//NameMesh("rep_weap_inf_rifle_dc15ax", "com_inv_mesh")
//NameMesh("rep_weap_dc17sniper", "com_inv_mesh")
//NameMesh("rep_weap_dc17rifle", "com_inv_mesh")
//NameMesh("rep_weap_dc17antiarmor", "com_inv_mesh")

NameMesh("cis_weap_inf_assault_cannon", "com_inv_mesh")

EventInput("player1.weapon1.change")
EventOutput("player1.weapon1.mesh")
}

}

Group("extraWeaponDisplay")
{
PropagateAlpha(1)
Viewport(1)
//Position(0.0000000, 1.000000, 0.000000, "Viewport")
ZOrder(255)

//EventEnable("player1.weaponsEnable")
//EventDisable("player1.weaponsDisable")


EventEnable("player1.weapon1.mesh")
EventDisable("player1.weapon1.disable")


Group("extraWeaponIcon")
{
Viewport(1)
//Position(0.346161, -0.450412, 0.000000, "Viewport")
EventEnable("initialize")

Model3D("player1.weapon1mesh")
{
EventMesh("player1.weapon1.change")
Viewport(1)
ZOrder(5)

EventEnable("player1.weapon1.mesh")
EventDisable("player1.weapon1.disable")

//Position(500.000000, 500.000000, 500.000000, "Viewport")
//Rotation(0.804269, 359.994110, 359.999695)
Scale(0.000000, 0.000000, 0.000000)

//change position, rotation and scale of first weapon here, remove unused lines


//MeshInfo("rep_weap_inf_carbine")
//{
// Position(-0.231578, 0.259076, 0.007261, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// Scale(1.140000, 1.140000, 1.140000)
//}
MeshInfo("rep_weap_inf_pistol_mini_r")
{
Position(0.100000, 0.900000, 0.000000, "Viewport")
Rotation(0.000000, 90.000000, 0.000000)
Scale(1.000000, 1.000000, 1.000000)
}
//MeshInfo("rep_weap_inf_dc15m")
//{
// Position(-0.215316, 0.367230, -0.007488, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// Scale(0.820000, 0.820000, 0.820000)
//}
//MeshInfo("disrupter_rifle")
//{
// Position(-0.222832, 0.361293, 0.014590, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
//}
//MeshInfo("weap_inf_dc17pistol_r_small")
//{
// Position(-0.260316, 0.356366, -0.002834, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// Scale(0.800000, 0.800000, 0.800000)
//}
MeshInfo("delta_weap_helm_pistol")
{
Position(-0.260316, 0.356366, -0.002834, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
Scale(0.800000, 0.800000, 0.800000)
}
//MeshInfo("rep_weap_inf_rifle_dc15ax")
//{
// Position(-0.215316, 0.367230, -0.007488, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// //Scale(0.820000, 0.820000, 0.820000)
//}
//MeshInfo("rep_weap_inf_dc17blaster")
//{
// Position(-0.249442, 0.359076, 0.007261, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// Scale(1.000000, 1.000000, 1.000000)
//}
//MeshInfo("rep_weap_inf_dc17sniper")
//{
// Position(-0.249442, 0.359076, 0.007261, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// Scale(1.000000, 1.000000, 1.000000)
//}
//MeshInfo("rep_weap_inf_dc17antiarmor")
//{
// Position(-0.249442, 0.359076, 0.007261, "Viewport")
// Rotation(0.804269, 90.747269, 359.999695)
// Scale(1.000000, 1.000000, 1.000000)
//}
MeshInfo("cis_weap_inf_assault_cannon")
{
Position(-0.222832, 0.361293, 0.014590, "Viewport")
Rotation(0.804269, 90.747269, 359.999695)
}
}
}

// Second Weapons Section

TransformNameMesh("player1weapon2")
// add names of second weapons here
{
NameMesh("com_weap_inf_grenadethermal", "com_inv_mesh")

EventInput("player1.weapon2.change")
EventOutput("player1.weapon2.mesh")
}

Group("extraWeaponDisplay")
{
PropagateAlpha(1)
Viewport(1)
Position(0.0000000, 1.000000, 0.000000, "Viewport")
ZOrder(255)
EventEnable("player1.weaponsEnable")
EventDisable("player1.weaponsDisable")

Group("extraWeaponIcon")
{
Viewport(1)
Position(0.346161, -0.450412, 0.000000, "Viewport")
EventEnable("initialize")

Model3D("player1.weapon2mesh")
{
EventMesh("player1.weapon2.change")
Viewport(1)
ZOrder(5)
EventEnable("player1.weapon2.mesh")
EventDisable("player1.weapon2.disable")
Position(500.000000, 500.000000, 500.000000, "Viewport")
Rotation(0.804269, 359.994110, 359.999695)
Scale(0.000000, 0.000000, 0.000000)

// adjust position, rotation and scale of second weapon here


MeshInfo("com_weap_inf_grenadethermal")
{
Rotation(0.804269, 90.747269, 359.999695)
}
}
}
}
}[/code]

Re: Iron Sight Tutorial (FAQ)

Posted: Thu Nov 03, 2011 6:30 pm
by Fiodis
I thought we couldn't replace the global ingame.lvl, since not all the files included in it are also present in the data_***/Common folder?