Skip to main content

Project 09: Complete mod

This is your guided graduation exam. Everything you have learned across the five stages comes together in an imposed, professional brief. You will build a complete VIP Chauffeur Service mod from scratch, combining road node queries, driver boarding, autonomous AI driving, map blips, destination markers, arrival rewards, and failure handling if the vehicle is destroyed.


The mission

Author a complete, production-grade VIP Chauffeur Service mod fulfilling six core requirements:

  1. Construct an explicit finite state machine governing the service from summon to drop-off.
  2. Query the road navigation mesh to spawn a luxury car (VehicleHash.Cognoscenti) and driver (PedHash.LSMicheal) upon pressing F9.
  3. Synchronize chauffeur boarding into the driver seat, then prompt the player to board as a passenger.
  4. Command autonomous AI transit across the city using modern collision-avoidance driving flags.
  5. Guide the journey with real-time radar GPS route guidance and an in-world 3D destination marker.
  6. Evaluate mission completion: award a guarded $1,000 payment upon arrival, handle vehicle destruction with immediate fail-safe teardown, and guarantee clean unload.

Specifications, constraints

  • Finite state machine: Formalize lifecycle progression using an explicit enum (ChauffeurState) rather than messy interdependent boolean flags.
  • Modern driving flags: Use VehicleDrivingFlags.StopForVehicles rather than deprecated or obsolete flags (such as FollowTraffic).
  • Boarding synchronization: Ensure the driver is fully seated (_driver.IsInVehicle(_car)) before inviting the player to board.
  • Vehicle destruction fail-safe: Abort immediately and notify the player if the car is wrecked (_car.IsDead) during transit.
  • Zero entity leakage: Fully delete car, driver, and radar blip in OnAborted.

Implementation steps

  1. Define the finite state machine: Create a ChauffeurState enum containing Inactive, BoardingDriver, WaitingForPlayer, DrivingToDestination, Arrived, and Failed.
  2. Declare state fields: In Project09CompleteMod, define private fields for _state, _car, _driver, _destinationBlip, _destination, and _rewardAwarded.
  3. Wire lifecycle events: In the constructor, attach handlers to KeyDown, Tick, and Aborted.
  4. Implement service start: In OnKeyDown, listen for Keys.F9 when inactive. Find the nearest road node, stream assets, spawn the vehicle and driver, order the driver to EnterVehicle, and transition to BoardingDriver.
  5. Manage the tick loop:
    • Check the global vehicle fail-safe: if _car == null || !_car.Exists() || _car.IsDead, announce failure, clean up, and exit.
    • In BoardingDriver: Once _driver.IsInVehicle(_car), transition to WaitingForPlayer and prompt the player.
    • In WaitingForPlayer: Once player.IsInVehicle(_car), call StartJourney().
    • In DrivingToDestination: Render the 3D ground marker. If distance to destination is under 7 meters, call CompleteJourney().
  6. Implement journey transit: In StartJourney, create the GPS route blip, command autonomous driving with _driver.Task.DriveTo(...), and set state to DrivingToDestination.
  7. Handle arrival: In CompleteJourney, verify !_rewardAwarded, credit $1,000 to Game.Player.Money, and clean up.
  8. Implement teardown: In CleanUp, delete blip, driver, and vehicle, and reset state. Call CleanUp in OnAborted.

APIs, tools to explore

  • Ped.Task.EnterVehicle(Vehicle vehicle, VehicleSeat seat, int timeout, float speed, EnterVehicleFlags flag): Commands an NPC to walk to a vehicle, open the door, and take a seat.
  • Ped.Task.DriveTo(Vehicle vehicle, Vector3 target, float radius, VehicleDrivingFlags flags, float speed): Instructs an AI driver to navigate along roads toward destination coordinates.
  • VehicleDrivingFlags.StopForVehicles: Modern navigation flag instructing AI drivers to observe traffic stops, slow for obstacles, and avoid collisions.
  • Ped.IsInVehicle(Vehicle vehicle): Validates that an entity is seated inside a specified vehicle.
  • Vehicle.IsDead: Checks if a vehicle has been destroyed, exploded, or submerged in water.

Validation checklist

Your mod is validated when:

  • Pressing F9 near a roadway: Cognoscenti spawns on the asphalt. The chauffeur approaches, opens the door, and sits behind the wheel.
  • Getting into the passenger seat: Chauffeur acknowledges the player, the GPS route appears on the radar, and the car navigates through city traffic respecting cars ahead.
  • Approaching the destination: The 3D yellow cylinder marker is visible on the street.
  • Arrival within 7 meters: The trip concludes, $1,000 is awarded once, and all entities are cleaned up.
  • Vehicle destruction test: Damaging or blowing up the car triggers the fail-safe notification and resets state cleanly.
  • Reloading with Insert: Car, driver, and blip are instantly removed without error.

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.