Arma 3
NPC Framework Script
Condasoft  [developer] 17 Feb @ 5:40pm
READ ME FOR STEAM USERS
Basic Overview
Each NPC follows the same structure:

- **Variables** - Store states such as whether the player is talking to an NPC.
- **Dialogue Functions** - Control how conversations start and how responses work.
- **Player Choices** - The player selects from different responses, triggering further dialogue.
- **Action System** - The player can interact with NPCs using "AddAction".

### Code Breakdown

#### 1. Variables
At the top of the script, some key variables are defined:

previewObject = objNull; // Used for previews of objects (not necessary for dialogue) isTalking = false; // Tracks if the player is currently in dialogue dialogueMenuActive = false; // Tracks if the dialogue menu is active currentNPC = objNull; // Stores the current NPC being talked to isFirstInteraction = true; // Checks if this is the first time the player has spoken to the NPC

#### 2. Dialogue Function
This function starts the dialogue when the player interacts with the NPC:

fnc_initiateDialogueNPC = { params ["_player", "_npc"]; // Takes the player and NPC as input if (!isTalking) then { // Only run if the player isn't already talking isTalking = true; dialogueMenuActive = true; currentNPC = _npc; // Store the NPC the player is speaking to [] spawn { if (isFirstInteraction) then { sleep 1; ["NPC Name", "Hello, stranger. What do you want?"] spawn BIS_fnc_showSubtitle; sleep 2; // Wait for text to display isFirstInteraction = false; }; // Create dialogue options _dialogueMenu = [ ["Ask about the town", [2], "", -5, [["expression", "['AskTown'] call fnc_selectDialogueOptionNPC"]], "1", "1"], ["Leave", [3], "", -5, [["expression", "['LeaveNPC'] call fnc_selectDialogueOptionNPC"]], "1", "1"] ]; showCommandingMenu "#USER:_dialogueMenu"; // Show dialogue menu }; }; };

#### 3. Handling Player Responses
Once the player chooses a response, another function handles it:

fnc_selectDialogueOptionNPC = { params ["_option"]; switch (_option) do { case "AskTown": { [] spawn { sleep 1; ["NPC Name", "This town? It’s barely holding together. Supplies are running low."] spawn BIS_fnc_showSubtitle; sleep 2; isTalking = false; [player, currentNPC] call fnc_initiateDialogueNPC; }; }; case "LeaveNPC": { [] spawn { sleep 1; ["NPC Name", "Suit yourself."] spawn BIS_fnc_showSubtitle; sleep 2; showCommandingMenu ""; dialogueMenuActive = false; isTalking = false; }; }; }; };

#### 4. Adding the Interaction
To make the NPC interactable, the script adds an action to the NPC:

_npc = this; _npc addAction ["Talk to NPC", { params ["_target", "_caller", "_actionId", "_arguments"]; if (!isTalking) then { [_caller, _target] call fnc_initiateDialogueNPC; }; }, nil, 1.5, true, true, "", "player distance _target <= 3"];
Last edited by Condasoft; 17 Feb @ 5:43pm