Skip to main content

Interactive objects

How the player uses things in the world: doors, crates, cases, beds, save points, terminals, guns, vehicles and the rest. The first half explains the mechanism and surveys every retail kind of interaction. The second half gives three ways to make a new one, cheapest first, with a lever, a radio and a readable note as examples.

Marks: (proven) seen in a running game; (RE-verified) read in FarCry2_server's code; (seen in data) read in the retail files; (inferred); (untested). Nothing on this page has been run in game. Counts are over the 250 sectors of w1_b_2.

How "use" works​

  1. The player asks every entity in front of him. CPawnInteractionMonitor (a component on the player) sends each candidate a CEntityEventIsUsable event. Every component on that entity sees it, and a component that wants to be used answers with "usable", a usage string and a position (IsUsableEntity, 0x08fe2ff0; GetUsableEntitiesInFrontOfPlayer, 0x08fe31b0) (RE-verified).
  2. The usage string picks a HUD icon. CFCXMainHudUI::CheckInteraction (0x08a604d0) hashes the string and asks the HUD's prompt manager for a prompt of that name. If there is none, it falls back to a default (RE-verified). The prompts are the <hudprompt> entries in ui\…\hud.mgb.desc: interact (the hand), switchweapon, watch, ratchet, ied, map, reload and a few more (seen in data). Retail usage strings such as door, USE M249 and Pick LandMine match none of them, so they show the default, which is the hand (inferred). A prompt is an icon, never text.
  3. Pressing use sends the entity CEntityEventOnUsed, which the answering component handles (RE-verified: both event names are in each answerer's code**)**. The entity then raises a Use event that event links (InputEvent = Use) and Domino callbacks ("Use") listen to (seen in data).

Fifteen places in the engine call the event's SetUsable (RE-verified):

  • Named by their own strings: the ladder ("Climb Ladder"), the mounted weapon ("bound mounted weapon"), a climbing helper (CheckClimb, TryClimb), and the multiplayer flag ("Take flag").
  • Inside a known class's code, between its constructors and destructors: CUsableComponent, CDoor, CBedroll, CPickup and its subclasses, CBazaarComputer, CProximityTriggerComponent, CExplosive and CMagicCrate.
  • By address only (inferred): the vehicle.
  • The rest: a generic setter, and one handler at 0x08fc4670 that was not identified.

Retail interactions​

InteractionArchetype exampleComponent that answers usePromptWhat use doesPersist levelSaved fieldsIn w1_b_2
DoorInteractive.InteractiveDoors.Urbain01_AnimatedDoor01CDoor, with CTriggerComponent and an animated CCompoundPhysComponentdoor → handpush or pull it open3bEnabled, UsedOnce, LastDoorAction8
Medkit cabinet (health)OA_MissionPickups.MissionPickups.MedKitCMedicStation (an opening pickup)handopens, refills syrettes1bOpened, bActive10
Ammo crate / pilepile_archetypes.PickupPiles.AmmoPileCPickupPilehandrefills ammo; also destructible1Destroyed, bActive2
Loose ammo, syrette, waterpickups.Ammo.Small_Ammo_Pickup, pickups.Health.SyretteCPickupMultipleAmmo, CPickupAmmo, CPickupHealthhandtake it1bActive
Weapon on the groundpickups.Weapons.AK47_newCPickupWeaponswitchweaponswap weapons1 or 3ammo, Reliability
Mine, pipe bombweapons.Explosives.IED_Base.IED_MineCExplosivePick LandMine → handtake it2the explosive's state
Diamond briefcaseOA_MissionPickups.MissionPickups.DiamondBriefcase_LVL1CPickupDiamond (an opening pickup with a beeper)handopens, pays nDiamonds3bOpened, bActive15
Tape, courier pouchOA_MissionPickups.MissionPickups.CarverTapeCPickupMissionItemhandtake it; graphs listen with PickupListener3 or 1bNeverPicked
Cell tower panelOA_MissionPickups.MissionPickups.CellTowerPanelCOpeningPickuphandthe phone contract (mission page)3bOpened
BedrollInteractive.Save.BedRollCBedrollwatchsleep and pass timenonebEnabled, savedTimeScale
Save pointProximityTrigger_11 (placed, no archetype)CProximityTriggerComponent with bUsablehandits Use link sends CMissionHandlerEvent._SaveGame3bEnabled, Usable1
Bus stationProximityTrigger_BusStation_W1B2toHubCProximityTriggerComponent with bUsablehanda Domino graph listens to Use4
Weapon shop computerInteractive.Computer.BazaarComputerCBazaarComputerhandopens the shop menunone
Safe-house weapon crateInteractive.MagicCrates.PrimaryCrateCMagicCratehand; CantUseText when not boughttake a weapon of the crate's category1
Mounted gunweapons.MountedWeapons.M249_SandBagsthe mounted weaponUSE M249 → handmount it1its implementation14
Vehiclevehicle.Land.*the vehiclehandget in1 or 3driver, health, parts
LadderOA_Ladder.Ladders.LadderDogon14stepsCLadderhandclimb1Users
Mission documentprops.Props.Folder_AnimReadyCUsableComponenthandraises Use; a graph decides2bEnabled
Explosive barrelOA_Explosives.Explosives.ExplosiveBarrel_NEWnone—not usable: damage drives its CCompoundPhysComponent states, two of which explode1compound state
Destructible prop261 archetypes with CCompoundPhysComponentnone—not usable: damage or events step a state machinemostly 1compound state
Radioobject_archetypes.Appliances.BoomBoxRadionone; CRadio plays a broadcast list, the global EnableRadioBroadcast(bool) switches them—not usable; shooting breaks it1bIsPlayingRadio
Malaria pillsno world pickup——pills come from scripts: SetMalariaPillCount, GetMalariaPillCountthe player's RemainingPills

Archetypes, components, prompts, persist levels and counts are (seen in data). "Saved fields" are the members the component registry marks as written to savegames (RE-verified).

The weapon crate​

Every weapon crate opens one store, the player's CPawnMagicCrate component, whose Contents the crates share. On use, CMagicCrate::OnEvent asks GetWeaponFromCategory for the carried gun of the crate's class and CPawnMagicCrate::ContainsCategory for a stored one, and signals the player's state machine: pick when only the store has one, drop when only the player does, switch when both do. The crate animation's magic_crate_pick_detach event then runs CompleteTransaction (Steam 0x106D7130): GetWeaponFromInventory (0x106D7050, through GetWeaponFromCategory) names the gun that goes in, which is removed from the inventory into Contents, and GetWeaponFromCrate (0x106D6F80) the gun that comes out, which AddWeapon adds and SelectWeapon draws by its class. Both return an entity proxy through a pointer argument, RET 4 (RE-verified, server build and Steam).

What persists​

A field marked "saved" reaches the save only if the entity itself is saved. A world-placed entity is saved at CPersistComponent level 2 and up, and at level 1 only when the persistence budget is -1 (garrisons) (RE-verified). So:

  • Level 3 or 2 keeps its state: opened diamond cases, doors, mission items, the save trigger, a used document.
  • Level 1 resets when its sector reloads: medkit cabinets, ammo piles, loose ammo, mounted guns. This is why a cabinet is full again when you return (inferred).
  • Mission-layer states are saved separately, in the save's MissionManager list (campaign state) (RE-verified), so anything a layer switch did survives a reload.

Three ways to build a new one​

The retail save point is the template, and it needs no script. It is an invisible box entity with three components (seen in data):

<object type="CTriggerComponent"><value name="static" type="Bool">True</value></object>
<object type="CProximityTriggerComponent">
<value name="bEnabled" type="Bool">True</value>
<value name="vectorSize" type="Vector3"><x>1</x><y>1</y><z>1</z></value>
<value name="bUsable" type="Bool">True</value>
<value name="selUsableBy" type="UInt32">2</value> <!-- PlayerOnly -->
<value name="sUsageString" type="String"></value> <!-- empty: the hand -->
<object type="UseRestrictions">
<value name="bLookAtCheck" type="Bool">True</value>
<value name="fMaxDifLookAt" type="Float">0.3</value>
<value name="bAngleCheck" type="Bool">False</value>
</object>
</object>
<object type="CPersistComponent"><value name="selLevel" type="UInt32">3</value></object>

plus a CEventComponent whose link fires on InputEvent = Use. The visible object is a separate prop placed in the same spot. What the link sends decides what the object does. These event classes appear in retail links (seen in data):

Event classhidEventNameDoesGood for
CMissionHandlerEvent_SaveGamesaves the gamea save point
CMissionHandlerEvent_MissionSetStateGame:MissionSetState(missionName, state): switches a mission layera lever that opens a gate
CMissionHandlerEvent_SetTimeOfDay, _Game_PlayBinkVideo, _Game_PlaySequence, _SetWaterLevelthe matching Game calla clock, a TV, a sluice
CSoundEventPlaySoundplays sndSound on the targeta radio that plays a clip
CLightEventActivateLight, DeactivateLightswitches a lighta light switch
CCompoundPhysChangeStateEventChangeStatesteps a compound object to its next statea breakable that falls apart on use
CCompoundPhysForceStateEventForceStatejumps a compound object to state nIndex
CNewParticlesSystemStartEvent / StopEventPlayParticles / StopParticlesstarts or stops an emittersmoke, sparks
CMapElementEventAvailablechanges a map markerreveal a place on the map

CMissionHandlerEvent runs Lua. Its name _X calls Mission:Event__X in scripts\missiontools.lua. That file is plain Lua, loaded by the engine's LoadLuaScripts (RE-verified for the load**; seen in data** for the name rule: _SaveGame ↔ Mission:Event__SaveGame). Its arguments come from the link's Parameters, a small binary-XML blob. The retail train-station trigger carries:

<Parameters missionName="Missions/HubAiDensity/Capitol/TrainStation" state="1" />

jackall-cli rml decode reads such a blob and rml encode writes one. That attributes arrive in the handler's argument order is (inferred) from the matching names (missionName, state).

Tools: the JackAll Map tab places the trigger, the prop and the link; the parameter blob is hand-made with jackall-cli rml. Everything in this way is (untested) by this project, but every piece of it ships in retail data.

Way 2: your own handler in MissionTools.lua​

Way 1 with a new event name. Add a function to scripts\missiontools.lua:

function Mission:Event__MyMod_ReadNote(title, text)
CGameMessageBoxHelper_GetInstance():CreateTutorialMessageBox(title, text, "", Mission, "Event__MyMod_NoteClosed");
end
function Mission:Event__MyMod_NoteClosed()
end

and link Use → CMissionHandlerEvent._MyMod_ReadNote with <Parameters title="MYMOD_NOTE_TITLE" text="MYMOD_NOTE_TEXT" />. The call is the one the PopUpTutorialMessageBox node makes (seen in data). Any Lua global works the same way: Game:AddDiamonds, SetMalariaPillCount, CGameMissionMgr_GetInstance(). (untested)

The catch: MissionTools.lua ships whole, so two mods that both add handlers replace each other's file. Keep handlers few and prefixed, or use way 3.

Way 3: a Domino graph​

For anything with state: an on/off toggle, a count, a second step. Two nodes listen for use:

  • ProximityTrigger on a usable trigger: control-outs Enter, Leave and Use. 121 retail graphs use it, the bus stations among them (seen in data).
  • UsableEntity on any entity with a CUsableComponent: StartListening, then OnUse. SetAsUsable and SetAsUnusable send CUsableComponent_Enable and _Disable, and SetSize calls SetUsableEntitySize. No retail graph uses this node (seen in data).

Keep the graph's state in Globals so it is saved (script state), and host the graph as in route C of the mission page.

Recipes​

A lever that opens a gate​

Way 1, no script:

  1. Put the gate (any prop; a checkpoint barrier or a wall section) in a new mission layer, Missions/MyMod/GateClosed, declared in <world>.game.xml with default state on. Tools: a JackAll game.xml mission fragment, and the Map tab with _layout.xml for the layer.
  2. Place the lever prop, and a usable trigger around it copied from the save point.
  3. Link the trigger's Use to CMissionHandlerEvent._MissionSetState with <Parameters missionName="Missions/MyMod/GateClosed" state="0" />.

The gate disappears when the lever is used, and stays gone after a reload because layer states are saved. There is no animation: retail's gates and barriers have damage states, not open and closed ones. An animated gate needs a compound object with an "open" state, which is new model work. (untested)

A radio you switch on​

  • One-shot (way 1): a usable trigger beside a radio prop, linked Use → CSoundEvent.PlaySound with your sndSound, targeting the radio entity. Copy the retail link's sndtpType 11, bAssignOnEntity True and bInterruptible True. It plays the clip each time it is used; it cannot switch off.
  • On and off (way 3): ProximityTrigger.Use toggles a flag in Globals and either plays the sound with PlaySound or stops it. The retail CRadio cannot be driven per radio from data: it has no use handler, and its only switch, EnableRadioBroadcast, is global.

A readable note​

  • Way 2: the _MyMod_ReadNote handler above, with the title and text as oasisstrings keys added through oasisstrings.fragment.xml.
  • Way 3: ProximityTrigger.Use → a PopUpTutorialMessageBox node with TitleLocId, TextLocId and ButtonLocId.

The prompt is the hand. A "Read" label would need a new <hudprompt> with its own icon in hud.mgb (a JackAll .mgb fragment) and that name in sUsageString (untested).

A pickup that gives malaria pills​

Way 2: a handler that calls SetMalariaPillCount(GetMalariaPillCount() + 1) and hides the prop by switching its layer off with Game:MissionSetState (or way 1's _MissionSetState on a second link). (untested)

A paper the player keeps​

Copy the Predecessor's envelope, MissionPickups.PartnerMissionEnvelope, a CPickupMissionItem. Give it another model in its descriptor and graphic component, and persist level 3 so that it stays picked. CPickupMissionItem::Pick (Steam 0x106C8040) runs the base pickup's Pick with a copy of the picker, then clears bActive (+0x15) and bNeverPicked (+0xD1) (RE-verified). When the item has a string at +0xC8, it then hands something built from it to the picker's entity (inferred). What the player carries afterwards is up to a plugin. Inventory Overhaul hooks Pick and gives the item named by its archetype's FCSE entity data (mods/tales-of-africa/papers.py, mods/inventory-overhaul/src/pickups.cpp). It is placed by a sector fragment in main (untested in game).

What needs an FCSE plugin​

Data and Lua cover any use that triggers something. These need engine code:

WantWhy data can'tPlugin approach
A text prompt ("Read note", "Turn on radio")prompts are icons chosen by name; the HUD has no text field for themwrite the text into a HUD element when CheckInteraction picks the entity
Hold to use, a progress bar, a use that takes timethe use step is one eventa component that answers IsUsable and runs its own timer
The player's hands doing something (a first-person animation on use, like doors and ladders)those animations belong to the answering C++ componentsa component that drives the player's animation, or reuse of an existing one
Carrying or moving an objectno retail component does itnew component
Per-radio on/off of the retail CRadio and its broadcast listno event or Lua call reaches one radiocall CRadio's methods from a plugin
A new kind of pickup reward with its own HUD feedbackpickups are fixed C++ classesnew component; or way 2 for the reward without the feedback
Changing use range or angle for every objectCPawnInteractionMonitor's query is codedetour the monitor
Per-object state richer than a layer or GlobalsFCSE entity data (persistence), already working

A new answering component is the general plugin route. FCSE already registers a component class with the engine's factory (ABI); giving it an OnEvent that answers CEntityEventIsUsable is the missing piece.

Open questions​

  • Which <hudprompt> the fallback actually picks, and what the IsUsable answerer at 0x08fc4670 is.
  • Whether a CUsableComponent entity's Use reaches event links as well as Domino callbacks. Retail data has no such link to copy.
  • Whether CMissionHandlerEvent passes Parameters attributes by order or by name.
  • What Game:MissionSetState's state values mean beyond 0 and 1.
  • What prop stands at the retail save trigger (1297.5, 3120.9) in worldsector3860.

Cheapest next experiments​

One launch each of the GOG install ("C:\Games\Far Cry 2\bin\FCSE.exe"), on a world-1 save, with the console on ~. Do not save afterwards.

  1. The handler path, no files. Stand in SafeHouse_15 (world 1, about x 1339, y 3230; see the engine experiments) and type #Mission:Event__MissionSetState("Missions/SafeHouse/Upgrades/W1/Level_06", 1). Expect the upgrade's medkit cabinet to appear. That proves MissionTools.lua's handlers and the state value, which the lever recipe rests on.
  2. The note pop-up, no files. #_t={Event_Continue=function() end}; CGameMessageBoxHelper_GetInstance():CreateTutorialMessageBox("BSQ03_01_NBM_01","BSQ03_01","",_t,"Event_Continue"). Expect a tutorial box titled "Destroy the ammo pile inside the Ranch House." with Flora's journal line as its text. That proves the readable-note call.
  3. A data-only lever. One layer: a usable trigger copied from ProximityTrigger_11 into SafeHouse_15's sector 4020, linked Use → _MissionSetState with <Parameters missionName="Missions/SafeHouse/Upgrades/W1/Level_06" state="1" />. It needs no new layer, since it reuses the retail one. Expect the hand icon on the spot, and the cabinet appearing when you use it.