Skip to content

Commit 04b7e65

Browse files
committed
Ignore path finding
Keep finished ghosts visible Added road cyclist model More detailed debug info
1 parent 4ff689e commit 04b7e65

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

ActivityGhosts/ActivityGhosts.cs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ActivityGhosts : Script
1818
private Keys loadKey;
1919
public static PointF initialGPSPoint;
2020
public static bool debug;
21+
private const string LOG_FILE = @".\Scripts\ActivityGhosts.log";
2122

2223
public ActivityGhosts()
2324
{
@@ -42,17 +43,20 @@ private void OnTick(object sender, EventArgs e)
4243
private void OnKeyDown(object sender, KeyEventArgs e)
4344
{
4445
if (e.KeyCode == loadKey)
46+
{
47+
System.IO.File.Delete(LOG_FILE);
4548
LoadGhosts();
49+
}
4650
}
4751

4852
private void OnAbort(object sender, EventArgs e)
4953
{
5054
KeyDown -= OnKeyDown;
5155
Tick -= OnTick;
52-
DeleteAll();
56+
DeleteGhosts();
5357
}
5458

55-
private void DeleteAll()
59+
private void DeleteGhosts()
5660
{
5761
foreach (Ghost g in ghosts)
5862
g.Delete();
@@ -61,7 +65,7 @@ private void DeleteAll()
6165

6266
private void LoadGhosts()
6367
{
64-
DeleteAll();
68+
DeleteGhosts();
6569
string ghostsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Rockstar Games\\GTA V\\Ghosts";
6670
if (Directory.Exists(ghostsPath))
6771
{
@@ -75,8 +79,9 @@ private void LoadGhosts()
7579
{
7680
if (Game.Player.Character.Position.DistanceTo2D(new Vector2(points[0].Lat, points[0].Long)) < 50f)
7781
{
78-
ghosts.Add(new Ghost(points));
79-
if (debug) Log($"Loaded ghost from {file.Name}");
82+
ghosts.Add(new Ghost(Path.GetFileNameWithoutExtension(file.Name), points));
83+
if (debug)
84+
Log($"Loaded ghost from {file.Name}");
8085
}
8186
}
8287
}
@@ -97,13 +102,14 @@ private void LoadSettings()
97102

98103
public static void Log(string message)
99104
{
100-
using (StreamWriter sw = new StreamWriter(@".\Scripts\ActivityGhosts.log", true))
105+
using (StreamWriter sw = new StreamWriter(LOG_FILE, true))
101106
sw.WriteLine(message);
102107
}
103108
}
104109

105110
public class Ghost
106111
{
112+
private string name;
107113
private List<GeoPoint> points;
108114
private Vehicle vehicle;
109115
private Ped ped;
@@ -115,35 +121,33 @@ public class Ghost
115121
VehicleDrivingFlags.AllowMedianCrossing |
116122
VehicleDrivingFlags.AvoidEmptyVehicles |
117123
VehicleDrivingFlags.AvoidObjects |
118-
VehicleDrivingFlags.AvoidVehicles;
124+
VehicleDrivingFlags.AvoidVehicles |
125+
VehicleDrivingFlags.IgnorePathFinding;
126+
127+
private string[] availableBicycles = { "BMX", "CRUISER", "FIXTER", "SCORCHER", "TRIBIKE", "TRIBIKE2", "TRIBIKE3" };
119128

120-
private List<string> availableBicycles = new List<string> { "BMX",
121-
"CRUISER",
122-
"FIXTER",
123-
"SCORCHER",
124-
"TRIBIKE",
125-
"TRIBIKE2",
126-
"TRIBIKE3" };
129+
private string[] availableCyclists = { "a_m_y_cyclist_01", "a_m_y_roadcyc_01" };
127130

128-
public Ghost(List<GeoPoint> pointList)
131+
public Ghost(string fileName, List<GeoPoint> pointList)
129132
{
133+
name = fileName;
130134
points = pointList;
131135
index = 0;
132136
skipped = 0;
133137
Model vModel;
134138
Random random = new Random();
135-
vModel = new Model(availableBicycles[random.Next(availableBicycles.Count)]);
139+
vModel = new Model(availableBicycles[random.Next(availableBicycles.Length)]);
136140
vModel.Request();
137141
if (vModel.IsInCdImage && vModel.IsValid)
138142
{
139143
while (!vModel.IsLoaded)
140144
Script.Wait(10);
141-
Vector3 start = GetPoint(index, ActivityGhosts.ghosts.Count + 1);
145+
Vector3 start = GetPoint(index, ActivityGhosts.ghosts.Count % 2 == 0 ? ActivityGhosts.ghosts.Count : ActivityGhosts.ghosts.Count * -1);
142146
vehicle = World.CreateVehicle(vModel, start);
143147
vModel.MarkAsNoLongerNeeded();
144148
vehicle.Mods.CustomPrimaryColor = Color.FromArgb(random.Next(255), random.Next(255), random.Next(255));
145149
Model pModel;
146-
pModel = new Model("a_m_y_cyclist_01");
150+
pModel = new Model(availableCyclists[random.Next(availableCyclists.Length)]);
147151
pModel.Request();
148152
if (pModel.IsInCdImage && pModel.IsValid)
149153
{
@@ -165,7 +169,8 @@ public void Update()
165169
int next = index + 1;
166170
if (points.Count > next)
167171
{
168-
if (vehicle.Position.DistanceTo2D(GetPoint(index)) < 20f)
172+
float distance = vehicle.Position.DistanceTo2D(GetPoint(index));
173+
if (distance < 20f)
169174
{
170175
ped.Task.ClearAll();
171176
ped.Task.DriveTo(vehicle, GetPoint(next), 0f, points[index].Speed, (DrivingStyle)customDrivingStyle);
@@ -176,14 +181,16 @@ public void Update()
176181
else
177182
{
178183
skipped++;
179-
if (ActivityGhosts.debug) ActivityGhosts.Log($"Skipped {skipped} at {index}");
184+
if (ActivityGhosts.debug)
185+
ActivityGhosts.Log($"{name} skipped {skipped} at {index} (off by {distance})");
180186
}
181187
if (skipped > 4 && points.Count > next + skipped + 1)
182188
{
183189
next += skipped;
184190
vehicle.Position = GetPoint(next);
185191
vehicle.Heading = GetHeading(next);
186-
if (ActivityGhosts.debug) ActivityGhosts.Log($"Teleported from {index} to {next}");
192+
if (ActivityGhosts.debug)
193+
ActivityGhosts.Log($"{name} teleported from {index} to {next}");
187194
ped.Task.ClearAll();
188195
ped.Task.DriveTo(vehicle, GetPoint(next + 1), 0f, points[next].Speed, (DrivingStyle)customDrivingStyle);
189196
vehicle.Speed = points[next].Speed;
@@ -193,8 +200,13 @@ public void Update()
193200
ped.IsInvincible = true;
194201
ped.CanBeKnockedOffBike = true;
195202
}
196-
else
197-
Delete();
203+
else if (ped.IsOnBike)
204+
{
205+
ped.Task.ClearAll();
206+
ped.Task.LeaveVehicle(vehicle, false);
207+
if (ActivityGhosts.debug)
208+
ActivityGhosts.Log($"{name} finished at {index}");
209+
}
198210
}
199211

200212
private Vector3 GetPoint(int i, int offset = 0)

0 commit comments

Comments
 (0)