Skip to main content

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:

  1. Trigger an encounter scene dynamically when the player approaches within 60 meters of a target location.
  2. Spawn two distinct actors (a dealer and a buyer) facing each other in conversational interaction (Task.ChatTo).
  3. Monitor player proximity and drawn weapon status in real time.
  4. Escalate the scene dynamically: the buyer flees in terror on foot while the dealer opens fire on the player.
  5. Despawn the actors and reset the encounter if the player ignores the scene and moves beyond 120 meters.
  6. 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

  1. Declare state tracking: Define fields for _dealer, _buyer, _eventTriggered, _dealEscalated, and a target _dealLocation.
  2. Wire lifecycle events: In the constructor, attach event handlers to Tick and Aborted.
  3. Handle proximity activation: In OnTick, compute player.Position.DistanceTo(_dealLocation). If untriggered and within 60 meters, call SpawnDealScene() and flag as triggered.
  4. Handle distance culling: If the scene is active and the player travels further than 120 meters away, invoke CleanUp().
  5. 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).
  6. 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 mutual Task.ChatTo.
  7. 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.
  8. Build cleanup: In CleanUp, delete both entities and reset boolean flags. Wire CleanUp to OnAborted.

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.