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:
- Construct an explicit finite state machine governing the service from summon to drop-off.
- Query the road navigation mesh to spawn a luxury car (
VehicleHash.Cognoscenti) and driver (PedHash.LSMicheal) upon pressingF9. - Synchronize chauffeur boarding into the driver seat, then prompt the player to board as a passenger.
- Command autonomous AI transit across the city using modern collision-avoidance driving flags.
- Guide the journey with real-time radar GPS route guidance and an in-world 3D destination marker.
- 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.StopForVehiclesrather than deprecated or obsolete flags (such asFollowTraffic). - 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
- Define the finite state machine: Create a
ChauffeurStateenum containingInactive,BoardingDriver,WaitingForPlayer,DrivingToDestination,Arrived, andFailed. - Declare state fields: In
Project09CompleteMod, define private fields for_state,_car,_driver,_destinationBlip,_destination, and_rewardAwarded. - Wire lifecycle events: In the constructor, attach handlers to
KeyDown,Tick, andAborted. - Implement service start: In
OnKeyDown, listen forKeys.F9when inactive. Find the nearest road node, stream assets, spawn the vehicle and driver, order the driver toEnterVehicle, and transition toBoardingDriver. - 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 toWaitingForPlayerand prompt the player. - In
WaitingForPlayer: Onceplayer.IsInVehicle(_car), callStartJourney(). - In
DrivingToDestination: Render the 3D ground marker. If distance to destination is under 7 meters, callCompleteJourney().
- Check the global vehicle fail-safe: if
- Implement journey transit: In
StartJourney, create the GPS route blip, command autonomous driving with_driver.Task.DriveTo(...), and set state toDrivingToDestination. - Handle arrival: In
CompleteJourney, verify!_rewardAwarded, credit $1,000 toGame.Player.Money, and clean up. - Implement teardown: In
CleanUp, delete blip, driver, and vehicle, and reset state. CallCleanUpinOnAborted.
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
F9near 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.