Build it into your mod
Add thermal and night vision to your optic
Four steps and about thirty lines. The example is a sight of your own called MyOptic; the names that belong to the framework are the real ones.
Step 1 – Add the framework as a dependency
Put the framework’s GUID into the Dependencies of your addon.gproj. Its own project file shows why that is all it asks for:
GameProject {
ID "GTGThermalFramework"
GUID "6A48B5AFEAF2488C"
TITLE "GTG Thermal Framework"
Dependencies {
"58D0FB3206B6F859"
}
}
GameProject {
ID "MyOptic"
GUID "<your own GUID>"
TITLE "My optic"
Dependencies {
"58D0FB3206B6F859" "6A48B5AFEAF2488C"
}
}
Step 2 – Put the component on your optic prefab
Add GTG_SOFLAM_VisionModeComponent to the entity that carries your sight. Two attributes decide which modes the device has at all; the cycle is built from them.
Leave a mode out and the player never lands in it. The key attributes carry the names of input actions – step 4 defines them.
GTG_SOFLAM_VisionModeComponent "{<unique 16 hex digits>}" {
m_bAllowNightVision 1
m_bAllowThermal 1
m_sCycleAction "MyOptic_VisionModeAction"
m_sToggleNvThermalAction "MyOptic_ToggleNvThermalAction"
m_sPaletteAction "MyOptic_PaletteAction"
m_sGainUpAction "MyOptic_GainUpAction"
m_sGainDownAction "MyOptic_GainDownAction"
}
| Attribute | Default | Meaning |
|---|---|---|
m_bAllowNightVision, m_bAllowThermal | true, true | Which modes exist. Both on: normal → night → thermal. One on: normal ↔ that one. None: the component hooks up no keys and does nothing. |
m_sCycleAction | GTG_SOFLAM_VisionModeAction | Cycle the vision mode. Empty = no key. |
m_sToggleNvThermalAction | GTG_SOFLAM_ToggleNvThermalAction | Jump straight between night vision and thermal. |
m_sPaletteAction | GTG_SOFLAM_ThermalPaletteAction | Next palette: White Hot, Black Hot, Ironbow, Rainbow. |
m_sGainUpAction, m_sGainDownAction | GTG_SOFLAM_GainUpAction, GTG_SOFLAM_GainDownAction | In night vision: gain. In thermal: the temperature window up and down. |
m_sNightVisionMaterial, m_sNightGrainMaterial | empty | Empty = the game’s own night-vision materials (see Night vision). Set your own .emat to change the look. |
m_aThermalFilters | empty | Empty = the built-in 40 materials. A list of your own materials replaces them – and with them the window labels (see Palettes and windows). |
m_iThermalSlot | 12 | Post-process slot of the thermal picture. 12 does not collide with the vehicle thermal of RHS (11). Two effects on one slot overwrite each other. |
Step 3 – Tell it when the player looks through
The component does not guess when your sight is in use. Your sight calls SetInputEnabled(true) when the player starts looking through it and
false when they stop. That call hooks the key listeners up and takes them down again, and the false returns the mode to normal and
takes the filters off the camera. Both calls live in one method with a bool parameter, so there is no way to hook up and forget to take down.
class MyOptic_SightsComponentClass : SCR_2DSightsComponentClass
{
}
class MyOptic_SightsComponent : SCR_2DSightsComponent
{
protected GTG_SOFLAM_VisionModeComponent m_Vision;
//------------------------------------------------------------------------------------------------
override void OnSightADSActivated()
{
super.OnSightADSActivated();
// ask the owner every time instead of keeping a field set in OnInit: if OnInit runs early or not at all, the field stays null and everything is silent
if (!m_Vision)
m_Vision = GTG_SOFLAM_VisionModeComponent.Cast(GetOwner().FindComponent(GTG_SOFLAM_VisionModeComponent));
if (m_Vision)
m_Vision.SetInputEnabled(true);
}
//------------------------------------------------------------------------------------------------
override void OnSightADSDeactivated()
{
if (m_Vision)
m_Vision.SetInputEnabled(false); // resets the mode and clears the camera effects
super.OnSightADSDeactivated();
}
}
Step 4 – Give it keys
The component listens to action names. Somebody has to define those actions and put them into an input context that is active while the player looks through the optic.
That is a piece of the game’s input configuration, and only one addon can override it, so it is its own page: Keys and hooks.
Short version for a mod without the SOFLAM Core: define the actions in your own chimeraInputCommon.conf and enter their names on the component, as in step 2.
Step 5 – Test
- Start a Workbench session, look through the optic and press the cycle key. You should get normal → night vision → thermal → normal.
- In thermal, the palette key cycles four palettes; the gain keys move the temperature window.
- Leave the optic. The screen must be normal again, with no leftover tint or white wash (see Night vision).
- Press the keys outside the optic. Nothing may happen: the listeners are only registered while you look through.
- After a script reload, restart the Workbench before you judge key behaviour. A hot reload can leave a second key listener behind, and one press then counts twice.