From 9273b46f7d66e0fd01191ee16bff74038a0e76a8 Mon Sep 17 00:00:00 2001 From: Tom Grobbe <31419184+TomGrobbe@users.noreply.github.com> Date: Thu, 30 Aug 2018 03:00:19 +0200 Subject: [PATCH] OP: set waypoint is now completely changed it updates the live position of the player using a special blip. and removes it once in range or whenever it's toggled off again. NOTE: TODO: May contain serious memory leak, needs more testing. --- vMenu/FunctionsController.cs | 46 ++++++++++++++++++++++-------- vMenu/menus/OnlinePlayers.cs | 55 ++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 16 deletions(-) diff --git a/vMenu/FunctionsController.cs b/vMenu/FunctionsController.cs index 9943249e..640996e8 100644 --- a/vMenu/FunctionsController.cs +++ b/vMenu/FunctionsController.cs @@ -1013,24 +1013,48 @@ private async Task PlayerBlipsControl() #endregion + #region Online Player Options Tasks + private async Task OnlinePlayersTasks() + { + await Delay(500); + if (MainMenu.OnlinePlayersMenu != null && MainMenu.OnlinePlayersMenu.PlayersWaypointList.Count > 0) + { + foreach (int playerId in MainMenu.OnlinePlayersMenu.PlayersWaypointList) + { + if (!NetworkIsPlayerActive(playerId)) + { + waypointPlayerIdsToRemove.Add(playerId); + } + else + { + Vector3 pos1 = GetEntityCoords(GetPlayerPed(playerId), true); + Vector3 pos2 = Game.PlayerPed.Position; + if (Vdist2(pos1.X, pos1.Y, pos1.Z, pos2.X, pos2.Y, pos2.Z) < 20f) + { + int blip = GetBlipFromEntity(GetPlayerPed(playerId)); + if (DoesBlipExist(blip)) { - if (!(p.Character.AttachedBlip == null || !p.Character.AttachedBlip.Exists())) - { - p.Character.AttachedBlip.Delete(); - } + SetBlipRoute(blip, false); + RemoveBlip(ref blip); + waypointPlayerIdsToRemove.Add(playerId); + Notify.Custom($"~g~You've reached ~s~{GetPlayerName(playerId)}'s~g~ location, disabling GPS route."); } - - - await Delay(60); // wait 60 ticks before doing the next player. } - await Delay(1000); // wait 1000 ticks before doing the next loop. } - else + await Delay(10); + } + if (waypointPlayerIdsToRemove.Count > 0) + { + foreach (int id in waypointPlayerIdsToRemove) { - await Delay(1000); + MainMenu.OnlinePlayersMenu.PlayersWaypointList.Remove(id); } + await Delay(10); } - */ + waypointPlayerIdsToRemove.Clear(); + } + } + #endregion /// Not task related #region Private ShowSpeed Functions diff --git a/vMenu/menus/OnlinePlayers.cs b/vMenu/menus/OnlinePlayers.cs index b0510870..b41e1594 100644 --- a/vMenu/menus/OnlinePlayers.cs +++ b/vMenu/menus/OnlinePlayers.cs @@ -81,7 +81,7 @@ public void UpdatePlayerlist() // Create all player options buttons. UIMenuItem teleportBtn = new UIMenuItem("Teleport To Player", "Teleport to this player."); UIMenuItem teleportInVehBtn = new UIMenuItem("Teleport Into Vehicle", "Teleport into the player's vehicle."); - UIMenuItem setWaypointBtn = new UIMenuItem("Set Waypoint", "Set a waypoint to this player."); + UIMenuItem setWaypointBtn = new UIMenuItem("Toggle GPS Route", "Enables or disables drawing a GPS route to this player."); UIMenuItem spectateBtn = new UIMenuItem("Spectate Player", "Spectate this player."); UIMenuItem summonBtn = new UIMenuItem("Summon Player", "Bring this player to your location."); summonBtn.SetRightBadge(UIMenuItem.BadgeStyle.Alert); @@ -157,10 +157,55 @@ public void UpdatePlayerlist() // Set waypoint button is pressed. else if (item2 == setWaypointBtn) { - if (player.Handle != PlayerPedId()) - World.WaypointPosition = GetEntityCoords(GetPlayerPed(player.Handle), true); - else - Notify.Error("You can not set a waypoint to yourself.", true, true); + bool selectedPedRouteAlreadyActive = false; + if (PlayersWaypointList.Count > 0) + { + if (PlayersWaypointList.Contains(player.Handle)) + { + selectedPedRouteAlreadyActive = true; + } + foreach (int playerId in PlayersWaypointList) + { + int playerPed = GetPlayerPed(playerId); + if (DoesEntityExist(playerPed) && DoesBlipExist(GetBlipFromEntity(playerPed))) + { + int oldBlip = GetBlipFromEntity(playerPed); + SetBlipRoute(oldBlip, false); + RemoveBlip(ref oldBlip); + Notify.Custom($"~g~GPS route to ~s~{GetPlayerName(playerId)}~g~ is now disabled."); + } + } + PlayersWaypointList.Clear(); + } + + if (!selectedPedRouteAlreadyActive) + { + if (player.Handle != PlayerId()) + { + int ped = GetPlayerPed(player.Handle); + int blip = GetBlipFromEntity(ped); + if (DoesBlipExist(blip)) + { + SetBlipColour(blip, 58); + SetBlipRouteColour(blip, 58); + SetBlipRoute(blip, true); + } + else + { + blip = AddBlipForEntity(ped); + SetBlipColour(blip, 58); + SetBlipRouteColour(blip, 58); + SetBlipRoute(blip, true); + } + PlayersWaypointList.Add(player.Handle); + Notify.Custom($"~g~GPS route to ~s~{player.Name}~g~ is now active, press the ~s~Toggle GPS Route~g~ button again to disable the route."); + } + else + { + Notify.Error("You can not set a waypoint to yourself."); + } + } + } // Spectate player button is pressed. else if (item2 == spectateBtn)