- Created a new documentation file detailing usage examples for the NPC item giving system, including immediate and container-based item transfers. - Updated the ContainerMinigame to support additional NPC context, enhancing the user experience when interacting with NPC inventories. - Implemented new NPC configurations in the scenario JSON to demonstrate item giving mechanics and container UI features. - Added an Ink script for the Equipment Officer NPC, showcasing how to present items through the container UI and manage player interactions.
6.6 KiB
NPC Item Giving System - Usage Examples
This document demonstrates how to use the NPC item giving system with both immediate and container-based approaches.
Setup
NPCs must declare itemsHeld array in the scenario JSON:
{
"id": "equipment_officer",
"displayName": "Equipment Officer",
"itemsHeld": [
{
"type": "lockpick",
"name": "Lock Pick Kit",
"takeable": true,
"observations": "Professional lock picking set"
},
{
"type": "workstation",
"name": "Analysis Workstation",
"takeable": true,
"observations": "Portable workstation"
}
]
}
Ink Variables
Items are automatically synced to Ink variables:
VAR has_lockpick = false
VAR has_workstation = false
VAR has_phone = false
VAR has_keycard = false
Declare only the has_* variables you need for your NPC.
Usage Pattern 1: Immediate Single Item Transfer
Tag: #give_item:type
Use Case: Give one specific item immediately without opening UI
Ink Example:
=== give_basic_item ===
Here's a lockpick set!
#give_item:lockpick
Good luck!
-> hub
How it works:
- Player reads dialogue
- Tag is processed
- First
lockpickfrom NPC'sitemsHeldis added to inventory - Item is removed from NPC's inventory
- Conversation continues
Notes:
- Only gives the first matching item type
- No UI overlay
- Fast and clean for single items
Usage Pattern 2: Container UI - All Items
Tag: #give_npc_inventory_items
Use Case: Show all items the NPC is holding for player to choose from
Ink Example:
=== give_all_items ===
# speaker:npc
Here are all the tools I have available. Take what you need!
#give_npc_inventory_items
What else can I help with?
-> hub
How it works:
- Tag is processed
- Container minigame opens in "NPC mode"
- Shows NPC's portrait and all items in
itemsHeld - Player can take items from container
- Each taken item is removed from NPC's inventory
- Variables updated automatically
- Conversation continues
Container UI Features:
- NPC portrait/avatar displayed
- "Equipment Officer offers you items" header
- Grid of available items
- Player can examine each item before taking
Usage Pattern 3: Container UI - Filtered Items
Tag: #give_npc_inventory_items:type1,type2
Use Case: Show only specific item types from NPC's inventory
Ink Example:
=== give_tools_only ===
# speaker:npc
Here are the specialized tools we have. Choose what you need for the job.
#give_npc_inventory_items:lockpick,workstation
Let me know if you need anything else!
-> hub
Comma-separated types:
// Show lockpicks and keycards only
#give_npc_inventory_items:lockpick,keycard
// Show workstations only
#give_npc_inventory_items:workstation
How it works:
- Tag parsed for filter types
- Container UI opens showing only matching items
- If NPC has 2 lockpicks, 1 workstation, 1 keycard:
- With filter
lockpick,keycard: shows 2 lockpicks + 1 keycard (not workstation)
- With filter
- Player can take from filtered list
- Variables updated
Advanced Example: Conditional Item Giving
Ink Example:
=== equipment_hub ===
What tools do you need?
{has_lockpick and has_workstation and has_keycard:
+ [I have all the tools I need]
-> thanks_npc
}
{has_lockpick or has_workstation or has_keycard:
+ [Show me everything else you have]
#give_npc_inventory_items
-> equipment_hub
}
+ [I need specialized tools]
-> show_tools
+ [I need security access]
-> show_keycards
+ [I'm good for now]
-> goodbye
=== show_tools ===
Here are our specialized tools:
#give_npc_inventory_items:lockpick,workstation
-> equipment_hub
=== show_keycards ===
Here are the access devices:
#give_npc_inventory_items:keycard
-> equipment_hub
=== thanks_npc ===
Perfect! Anything else?
-> equipment_hub
=== goodbye ===
Come back if you need anything!
-> END
Complete Scenario Example
From npc-sprite-test2.json:
Helper NPC (Immediate Item Transfer)
- Position: (5, 3)
- Story:
helper-npc.ink - Items: phone, workstation, lockpick
- Pattern: Uses
#give_item:typefor single items - Demonstrates: Conditional dialogue that adapts to available items
Equipment Officer (Container-Based UI)
- Position: (8, 5)
- Story:
equipment-officer.ink - Items: 2 lockpicks (Basic & Advanced), 1 workstation, 1 keycard
- Pattern: Uses
#give_npc_inventory_itemsto show container minigame - Demonstrates:
- Container UI with NPC portrait
- Multiple items of same type
- All items displayed in interactive grid
- Items removed from NPC inventory as player takes them
- Conversation continues after item selection
Container Minigame UI Features (NPC Mode)
When #give_npc_inventory_items is used, the container minigame opens with:
- NPC Portrait/Avatar - Displayed at top if available
- Custom Header - "Equipment Officer offers you items"
- Item Grid - Interactive grid showing all held items (or filtered items)
- Item Details - Click items to see observations/descriptions
- Take Items - Player can take any/all items shown
- Automatic Updates - NPC inventory decreases as items taken
- Variable Sync -
has_*variables update in real-time
Example dialogue flow:
Player: "Show me what you have available"
→ Container minigame opens with NPC's items
→ Player takes "Advanced Lock Pick Kit"
→ NPC inventory now has 1 lockpick instead of 2
→ has_lockpick variable remains true (still has items)
→ Conversation continues with "What else can I help with?"
Event System
When items are given, the npc_items_changed event is emitted:
window.eventDispatcher.emit('npc_items_changed', { npcId });
This automatically triggers:
- Variables re-sync in Ink
- Conditions re-evaluated
- Conversation state updated
Best Practices
- Declare all
has_*variables you'll check in Ink at the top of your story - Use immediate giving (
#give_item) for story-critical single items - Use container UI when offering multiple items or choices
- Use filtered container UI for specialized equipment categories
- Check variables in conditions to adapt dialogue based on what's available
- Remove items as they're taken - they're automatically removed from NPC inventory
Testing
To test the NPC item giving system:
- Load
npc-sprite-test2.jsonscenario - Talk to "Helper NPC" (5, 3) - demonstrates immediate giving
- Talk to "Equipment Officer" (8, 5) - demonstrates container UI
- Try different dialogue paths to see variable updates
- Verify items appear in player inventory
- Check that NPC inventory decreases as items are taken