Skip to content

Commit

Permalink
OP: set waypoint is now completely changed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TomGrobbe committed Aug 30, 2018
1 parent fd140b0 commit 9273b46
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 16 deletions.
46 changes: 35 additions & 11 deletions vMenu/FunctionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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~<C>{GetPlayerName(playerId)}</C>'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
Expand Down
55 changes: 50 additions & 5 deletions vMenu/menus/OnlinePlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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~<C>{GetPlayerName(playerId)}</C>~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~<C>{player.Name}</C>~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)
Expand Down

0 comments on commit 9273b46

Please sign in to comment.