The world around you: every car on the road, the nearest ones, the time of day and how fast it passes, and the waypoint you've set on the map.
Thread: game thread only (Game.Tick, Game.Run, an ANNA entry). Waypoint can be read from any thread.
Example
Two ANNA menu entries: one tells you how far the nearest Drivatar is, one sets the time to noon.
protected override void OnInit()
{
ANNA.Menu.Add("Nearest Drivatar", () =>
{
var mine = Player.Car;
var other = World.GetNearestVehicle(kind: VehicleKind.Drivatar);
if (mine is null || other is null) return;
UI.Notify(other.Model?.ShortName ?? "A car", $"{mine.DistanceTo(other):F0} m away");
});
ANNA.Menu.Add("Noon", () => World.TimeOfDay = TimeSpan.FromHours(12));
}
Protected Overrides Sub OnInit()
ANNA.Menu.Add("Nearest Drivatar",
Sub()
Dim mine = Player.Car
Dim other = World.GetNearestVehicle(kind:=VehicleKind.Drivatar)
If mine Is Nothing OrElse other Is Nothing Then Return
UI.Notify(If(other.Model?.ShortName, "A car"), $"{mine.DistanceTo(other):F0} m away")
End Sub)
ANNA.Menu.Add("Noon", Sub() World.TimeOfDay = TimeSpan.FromHours(12))
End Sub
Members
Properties
| Member | What it does |
|---|---|
Vehicles (property, get, IReadOnlyList<Vehicle>) | Every car the game updated last frame: yours, Drivatars, traffic. |
TimeOfDay (property, get/set, TimeSpan) | The time of day, as the world's clock has it. Setting it moves the sun straight away. Values past 24 hours (or below 0) wrap round. |
TimeScale (property, get/set, float) | How fast the clock runs: 1 is the game's own pace, 0 stops it. Values below 0 are set as 0. |
Waypoint (property, get, Vector3?) | The waypoint you've set on the map, or null if there's none (or the HUD isn't up to say, in the garage for example). It's on the road where the sat-nav's route ends, with the ground's height; or the map's pin when there's no route. Any thread. |
LightLevel (property, get, float) | How much light there is where you're driving, as the game's lighting has it. It drops to a fifth or less in a tunnel; compare it with a moment ago rather than with a fixed number. -1 if it can't be read. Any thread. New in 0.12.0. |
Methods
| Member | What it does |
|---|---|
GetNearestVehicle(Vector3? from = null, VehicleKind? kind = null) → Vehicle? | The car nearest from (your car's position if you leave it out), not counting yours. Only cars of kind, if you give one. Null if there's none. |
GetVehiclesInRange(float radius, Vector3? from = null) → IReadOnlyList<Vehicle> | Cars within radius metres of from (your car if you leave it out), nearest first, not counting yours. |
PrepareRoutes() | Call it from OnInit if you use RouteToNearest: it hooks the game's navigation module as the game starts. Only mods that call it get the hook, because FH2 ANNA turns its own routes off when another mod hooked that module first. New in 0.12.0. |
RouteToNearest(Destination destination) → bool | Sets the GPS route to the nearest Event, BucketList, RoadTrip stop, BonusBoard (found, not smashed) or BarnFind rumour, as ANNA's voice commands did. Call PrepareRoutes from OnInit first. False if there's none. Game thread only. New in 0.12.0. |
Notes
- Like every
Vehicle, the cars you get here are only valid for this frame. Don't keep them between ticks. - If you leave out
fromand you're not driving (noPlayer.Car),GetNearestVehiclereturns null andGetVehiclesInRangereturns an empty list. TimeOfDayandTimeScalethrow anInvalidOperationExceptionwhen the world isn't loaded.Waypointthrows anInvalidOperationExceptionwhen the game isn't ready yet (still loading, or a game build the SDK doesn't know).- On a game build where the sat-nav isn't as expected,
Waypointis always null andplatform.logsays so ("World.Waypoint off"). - Distances and positions are in metres: X and Z across the map, Y up.
- Using the game-thread members from another thread throws an
InvalidOperationExceptionthat says to useGame.TickorGame.Run.
