Project 06: Dynamic event
In Project 05, you built a static gang encounter. In Project 06, you build an ambient dynamic event inspired by GTA V's random world events: two strangers meeting in an alley for a suspicious exchange. When the player intervenes, the deal degenerates: one actor flees on foot in terror while the other draws a weapon to fight, and the scene cleans itself up when finished.
The mission
Build an ambient dynamic event fulfilling six core criteria:
- Trigger an encounter scene dynamically when the player approaches within 60 meters of a target location.
- Spawn two distinct actors (a dealer and a buyer) facing each other in conversational interaction (
Task.ChatTo). - Monitor player proximity and drawn weapon status in real time.
- Escalate the scene dynamically: the buyer flees in terror on foot while the dealer opens fire on the player.
- Despawn the actors and reset the encounter if the player ignores the scene and moves beyond 120 meters.
- Cleanly delete all entities upon script unload.
Specifications, constraints
- On-foot flight only: Keep the escape strictly on foot via
_buyer.Task.FleeFrom(player); vehicle pursuit mechanics are reserved for later stages. - Single trigger guard: Enforce state flags so the encounter cannot duplicate or re-spawn while active.
- Distance-based cleanup: Free memory by despawning both actors whenever the player travels past 120 meters.
- Zero entity leakage: Wipe all active entities inside
OnAborted.
Implementation steps
- Declare state tracking: Define fields for
_dealer,_buyer,_eventTriggered,_dealEscalated, and a target_dealLocation. - Wire lifecycle events: In the constructor, attach event handlers to
TickandAborted. - Handle proximity activation: In
OnTick, computeplayer.Position.DistanceTo(_dealLocation). If untriggered and within 60 meters, callSpawnDealScene()and flag as triggered. - Handle distance culling: If the scene is active and the player travels further than 120 meters away, invoke
CleanUp(). - Evaluate escalation criteria: If active and unescalated, check if the player steps within 8 meters or is holding an active weapon. If so, call
EscalateConflict(player). - Build scene spawning: In
SpawnDealScene, stream both models, place the actors 1.5 meters apart facing each other, give a pistol to the dealer, and command mutualTask.ChatTo. - Build escalation logic: In
EscalateConflict, clear existing tasks on both actors, command the dealer to fight the player, and order the buyer to flee from the player on foot. - Build cleanup: In
CleanUp, delete both entities and reset boolean flags. WireCleanUptoOnAborted.
APIs, tools to explore
Ped.Task.ChatTo(Ped otherPed): Commands two pedestrians to face each other and play conversational body language animations.Ped.Task.FleeFrom(Entity target): Triggers a natural on-foot sprint away from an intimidating or hostile entity.Ped.Task.Combat(Ped target): Commands hostile attack targeting a specific entity.Entity.Position.DistanceTo(Vector3 point): Measures Euclidean distance to evaluate proximity triggers.GTA.UI.Notification.PostTicker(string message, bool isImportant): Posts contextual news feed updates above the radar.
Validation checklist
Your mod is validated when:
- Approaching within 60 meters of the alley: The dealer and buyer spawn facing each other and engage in conversational gestures.
- Stepping within 8 meters or drawing a firearm: The buyer turns and runs down the street on foot, while the dealer draws a pistol and opens fire.
- Driving 120 meters away during the event: Both entities despawn cleanly without leaving permanent garbage in the world.
- Reloading with
Insert: Both entities are deleted immediately.
Solution, explanations
Partner
Verified solution and code explanations
The mission, specifications, and guided steps remain 100% free and open for everyone. The complete verified reference code and production explanations are reserved for Partner members.