@@ -18,6 +18,7 @@ public class ActivityGhosts : Script
18
18
private Keys loadKey ;
19
19
public static PointF initialGPSPoint ;
20
20
public static bool debug ;
21
+ private const string LOG_FILE = @".\Scripts\ActivityGhosts.log" ;
21
22
22
23
public ActivityGhosts ( )
23
24
{
@@ -42,17 +43,20 @@ private void OnTick(object sender, EventArgs e)
42
43
private void OnKeyDown ( object sender , KeyEventArgs e )
43
44
{
44
45
if ( e . KeyCode == loadKey )
46
+ {
47
+ System . IO . File . Delete ( LOG_FILE ) ;
45
48
LoadGhosts ( ) ;
49
+ }
46
50
}
47
51
48
52
private void OnAbort ( object sender , EventArgs e )
49
53
{
50
54
KeyDown -= OnKeyDown ;
51
55
Tick -= OnTick ;
52
- DeleteAll ( ) ;
56
+ DeleteGhosts ( ) ;
53
57
}
54
58
55
- private void DeleteAll ( )
59
+ private void DeleteGhosts ( )
56
60
{
57
61
foreach ( Ghost g in ghosts )
58
62
g . Delete ( ) ;
@@ -61,7 +65,7 @@ private void DeleteAll()
61
65
62
66
private void LoadGhosts ( )
63
67
{
64
- DeleteAll ( ) ;
68
+ DeleteGhosts ( ) ;
65
69
string ghostsPath = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + "\\ Rockstar Games\\ GTA V\\ Ghosts" ;
66
70
if ( Directory . Exists ( ghostsPath ) )
67
71
{
@@ -75,8 +79,9 @@ private void LoadGhosts()
75
79
{
76
80
if ( Game . Player . Character . Position . DistanceTo2D ( new Vector2 ( points [ 0 ] . Lat , points [ 0 ] . Long ) ) < 50f )
77
81
{
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 } ") ;
80
85
}
81
86
}
82
87
}
@@ -97,13 +102,14 @@ private void LoadSettings()
97
102
98
103
public static void Log ( string message )
99
104
{
100
- using ( StreamWriter sw = new StreamWriter ( @".\Scripts\ActivityGhosts.log" , true ) )
105
+ using ( StreamWriter sw = new StreamWriter ( LOG_FILE , true ) )
101
106
sw . WriteLine ( message ) ;
102
107
}
103
108
}
104
109
105
110
public class Ghost
106
111
{
112
+ private string name ;
107
113
private List < GeoPoint > points ;
108
114
private Vehicle vehicle ;
109
115
private Ped ped ;
@@ -115,35 +121,33 @@ public class Ghost
115
121
VehicleDrivingFlags . AllowMedianCrossing |
116
122
VehicleDrivingFlags . AvoidEmptyVehicles |
117
123
VehicleDrivingFlags . AvoidObjects |
118
- VehicleDrivingFlags . AvoidVehicles ;
124
+ VehicleDrivingFlags . AvoidVehicles |
125
+ VehicleDrivingFlags . IgnorePathFinding ;
126
+
127
+ private string [ ] availableBicycles = { "BMX" , "CRUISER" , "FIXTER" , "SCORCHER" , "TRIBIKE" , "TRIBIKE2" , "TRIBIKE3" } ;
119
128
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" } ;
127
130
128
- public Ghost ( List < GeoPoint > pointList )
131
+ public Ghost ( string fileName , List < GeoPoint > pointList )
129
132
{
133
+ name = fileName ;
130
134
points = pointList ;
131
135
index = 0 ;
132
136
skipped = 0 ;
133
137
Model vModel ;
134
138
Random random = new Random ( ) ;
135
- vModel = new Model ( availableBicycles [ random . Next ( availableBicycles . Count ) ] ) ;
139
+ vModel = new Model ( availableBicycles [ random . Next ( availableBicycles . Length ) ] ) ;
136
140
vModel . Request ( ) ;
137
141
if ( vModel . IsInCdImage && vModel . IsValid )
138
142
{
139
143
while ( ! vModel . IsLoaded )
140
144
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 ) ;
142
146
vehicle = World . CreateVehicle ( vModel , start ) ;
143
147
vModel . MarkAsNoLongerNeeded ( ) ;
144
148
vehicle . Mods . CustomPrimaryColor = Color . FromArgb ( random . Next ( 255 ) , random . Next ( 255 ) , random . Next ( 255 ) ) ;
145
149
Model pModel ;
146
- pModel = new Model ( "a_m_y_cyclist_01" ) ;
150
+ pModel = new Model ( availableCyclists [ random . Next ( availableCyclists . Length ) ] ) ;
147
151
pModel . Request ( ) ;
148
152
if ( pModel . IsInCdImage && pModel . IsValid )
149
153
{
@@ -165,7 +169,8 @@ public void Update()
165
169
int next = index + 1 ;
166
170
if ( points . Count > next )
167
171
{
168
- if ( vehicle . Position . DistanceTo2D ( GetPoint ( index ) ) < 20f )
172
+ float distance = vehicle . Position . DistanceTo2D ( GetPoint ( index ) ) ;
173
+ if ( distance < 20f )
169
174
{
170
175
ped . Task . ClearAll ( ) ;
171
176
ped . Task . DriveTo ( vehicle , GetPoint ( next ) , 0f , points [ index ] . Speed , ( DrivingStyle ) customDrivingStyle ) ;
@@ -176,14 +181,16 @@ public void Update()
176
181
else
177
182
{
178
183
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 } )") ;
180
186
}
181
187
if ( skipped > 4 && points . Count > next + skipped + 1 )
182
188
{
183
189
next += skipped ;
184
190
vehicle . Position = GetPoint ( next ) ;
185
191
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 } ") ;
187
194
ped . Task . ClearAll ( ) ;
188
195
ped . Task . DriveTo ( vehicle , GetPoint ( next + 1 ) , 0f , points [ next ] . Speed , ( DrivingStyle ) customDrivingStyle ) ;
189
196
vehicle . Speed = points [ next ] . Speed ;
@@ -193,8 +200,13 @@ public void Update()
193
200
ped . IsInvincible = true ;
194
201
ped . CanBeKnockedOffBike = true ;
195
202
}
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
+ }
198
210
}
199
211
200
212
private Vector3 GetPoint ( int i , int offset = 0 )
0 commit comments