diff --git a/_Resource/VoiceGPS.zip b/_Resource/VoiceGPS.zip index c2c1710..18fd452 100644 Binary files a/_Resource/VoiceGPS.zip and b/_Resource/VoiceGPS.zip differ diff --git a/_Resource/VoiceGPS/VoiceGPS_FiveM.Client.net.dll b/_Resource/VoiceGPS/VoiceGPS_FiveM.Client.net.dll index b63d698..1810770 100644 Binary files a/_Resource/VoiceGPS/VoiceGPS_FiveM.Client.net.dll and b/_Resource/VoiceGPS/VoiceGPS_FiveM.Client.net.dll differ diff --git a/src/VoiceGPS-FiveM.Client/ClientScript.cs b/src/VoiceGPS-FiveM.Client/ClientScript.cs index 9fad63e..6d6e6af 100644 --- a/src/VoiceGPS-FiveM.Client/ClientScript.cs +++ b/src/VoiceGPS-FiveM.Client/ClientScript.cs @@ -76,9 +76,6 @@ private async Task OnTick() _justPlayedArrived = true; await Delay(2000); } -#if DEBUG - //Chat("a"); -#endif _playedStartDriveAudio = false; @@ -89,9 +86,6 @@ private async Task OnTick() _justPlayedArrived = false; if (!_playedStartDriveAudio) { -#if DEBUG - //Chat("b"); -#endif PlayAudio("start"); await Delay(2600); _playedStartDriveAudio = true; @@ -111,10 +105,6 @@ private async Task OnTick() return; } -#if DEBUG - //ShowNotification(DirectionToString(dir)); -#endif - //0 : You arrived at your destination //1 : Going The Wrong wAY...recalculating //2: Follow this lane and wait for more instructions @@ -125,7 +115,7 @@ private async Task OnTick() //7: Take the next return to the right. (distance on p6) //8: Exit motorway - if (_lastDirection != dir || (_lastDirection == dir && _lastDistance < dist)) + if (_lastDirection != dir || (_lastDirection == dir && _lastDistance - dist < -50)) { _justPlayed200M = false; _justPlayedImmediate = false; @@ -192,100 +182,87 @@ private async Task OnTick() } - private string DirectionToString(int direction) - { - switch (direction) - { - default: - return $"Unknown ({direction})"; - case 0: - return $"You have arrived (0)"; - case 1: - return $"Recalculating (1)"; - case 2: - return $"Follow the road (2)"; - case 3: - return $"Left at next junction (3)"; - case 4: - return $"Right at next junction (4)"; - case 5: - return $"Straight at next junction (5)"; - case 6: - return $"Keep left (6)"; - case 7: - return $"Keep right (7)"; - case 8: - return $"Exit motorway (8)"; - } - } + //private string DirectionToString(int direction) + //{ + // switch (direction) + // { + // default: + // return $"Unknown ({direction})"; + // case 0: + // return $"You have arrived (0)"; + // case 1: + // return $"Recalculating (1)"; + // case 2: + // return $"Follow the road (2)"; + // case 3: + // return $"Left at next junction (3)"; + // case 4: + // return $"Right at next junction (4)"; + // case 5: + // return $"Straight at next junction (5)"; + // case 6: + // return $"Keep left (6)"; + // case 7: + // return $"Keep right (7)"; + // case 8: + // return $"Exit motorway (8)"; + // } + //} private async Task PlayDirectionAudio(int dir, int dist) { - //Chat("Attempting to play sound."); - - var streets = GetStreetNameForDirection(dist); - - var roadName = streets.Item1; - var crossingRoadName = streets.Item2; - - var playerPosition = _playerPed.Position; - var hash = 0u; - var crossingRoadHash = 0u; + var dontPlayStreetName = false; + var roadName = ""; - API.GetStreetNameAtCoord( - playerPosition.X, - playerPosition.Y, - playerPosition.Z, - ref hash, ref crossingRoadHash); - - var currentRoad = API.GetStreetNameFromHashKey(hash); - - var dontPlayStreetName = (currentRoad == roadName); - - - roadName = ConvertStreetNameToAudioFileName(roadName); - crossingRoadName = crossingRoadName != null ? ConvertStreetNameToAudioFileName(crossingRoadName) : "N/A"; -#if DEBUG - ShowNotification("Upcoming street: " + roadName + " |X| " + crossingRoadName); -#endif + if (dir == 3 || dir == 4) + { + roadName = GetCorrectTurningRoadName(dir, dist, out dontPlayStreetName); + } switch (dir) { default: // Anything NOT known - Chat(dir.ToString()); + // Chat(dir.ToString()); break; case 6: // Not 100% PlayAudio("keepleft"); + await Delay(900); break; case 7: // Not 100% PlayAudio("keepright"); + await Delay(900); break; case 3: // Turn left at next intersection + // Chat(dir.ToString()); + PlayAudio("turnleft"); + await Delay(900); + if (dist < 175 && dist > 30 && !dontPlayStreetName) { - await Delay(900); PlayAudio("onto"); await Delay(500); PlayAudio("streetnames/" + roadName); await Delay(1250); // Generic time wait to prevent audio overlapping } - break; case 4: // Turn right at next intersection + // Chat(dir.ToString()); + PlayAudio("turnright"); + await Delay(900); + if (dist < 175 && dist > 30 && !dontPlayStreetName) { - await Delay(900); PlayAudio("onto"); await Delay(500); PlayAudio("streetnames/" + roadName); @@ -302,10 +279,11 @@ private async Task PlayDirectionAudio(int dir, int dist) case 1: // Driver went wrong way -- remaking route PlayAudio("recalculating"); + await Delay(1200); break; case 8: - PlayAudio("exitMotorwayToRight"); + //PlayAudio("exitMotorwayToRight"); break; } } @@ -318,7 +296,8 @@ void ToggleVgps() { _lastDirection = 0; _justPlayed200M = _justPlayedArrived = _justPlayedFollowRoad = - _justPlayedImmediate = _justPlayedRecalc = _justPlayed1000M = false; + _justPlayedImmediate = _justPlayedRecalc = _justPlayed1000M = + _playedStartDriveAudio = false; } ShowNotification(_voiceGpsEnabled ? "Voice GPS ~g~ENABLED" : "Voice GPS ~r~DISABLED"); @@ -382,6 +361,7 @@ private Tuple GetStreetNameForDirection(int distance, Vector3? x xyOffset = new Vector3(0, 0, 0); Vector3 coords = Game.PlayerPed.Position + (Game.PlayerPed.ForwardVector * distance) + (Vector3) xyOffset; + // ReSharper disable once InconsistentNaming var roadPositionXY = new Vector2(coords.X, coords.Y); @@ -431,5 +411,53 @@ private string ConvertStreetNameToAudioFileName(string streetName) return streetName; } + + private string GetCorrectTurningRoadName(int direction, int distance, out bool incorrectStreetName) + { + var streets = GetStreetNameForDirection(distance); + var roadName = streets.Item1; + + var playerPosition = _playerPed.Position; + + var hash = 0u; + var crossingRoadHash = 0u; + + API.GetStreetNameAtCoord( + playerPosition.X, + playerPosition.Y, + playerPosition.Z, + ref hash, ref crossingRoadHash); + + var currentRoad = API.GetStreetNameFromHashKey(hash); + + incorrectStreetName = (currentRoad == roadName); + + if (incorrectStreetName) + { + var rightVector = _playerPed.RightVector; + var leftVector = rightVector * -1; + + switch (direction) + { + case 3: + streets = GetStreetNameForDirection(distance, leftVector * 5); + roadName = streets.Item1; + incorrectStreetName = (currentRoad == roadName); + break; + case 4: + streets = GetStreetNameForDirection(distance, rightVector * 5); + roadName = streets.Item1; + incorrectStreetName = (currentRoad == roadName); + break; + } + } + + if (incorrectStreetName) + return null; + + roadName = ConvertStreetNameToAudioFileName(roadName); + + return roadName; + } } }