1010
1111
1212#if ! defined _gps_included
13- #error You need to include the GPS plugin before this: https://github.com/kristoisberg/samp-gps-plugin/releases
13+ # include < GPS>
1414#endif
1515
1616#if defined include_waze_gps
2323# define MAX_WAZE_DOTS (100 )
2424# define WAZE_UPDATE_TIME (3100 )
2525
26- // Includes
27- #include < YSI_Coding\y_hooks>
28- #include < YSI_Data\y_iterate>
29-
3026 // Forrwards
3127forward UpdateWaze (playerid, Float: X, Float: Y, Float: Z);
3228forward OnPlayerWazeRouters (Path: pathid, playerid);
3329
3430static enum WAZEGPS_ENUM {
3531 wazeGPS_Timer,
3632 wazeGPS_Color,
33+ wazeGPS_Count,
34+
35+ // Rotas
36+ bool: wazeGPS_Created[MAX_WAZE_DOTS],
3737 wazeGPS_Routes[MAX_WAZE_DOTS],
3838
3939 Float: wazeGPS_Position[3 ],
4040 Float: wazeGPS_TickPosition[3 ]
4141};
4242
4343static
44- Iterator: wazePointers[MAX_PLAYERS]< MAX_WAZE_DOTS> ,
45- wazeGPS[MAX_PLAYERS][WAZEGPS_ENUM];
44+ wazeGPS[MAX_PLAYERS][WAZEGPS_ENUM];
4645
47- hook OnPlayerDisconnect (playerid, reason) {
48-
49- WazeGPS_Reset (playerid);
50- return Y_HOOKS_CONTINUE_RETURN_1;
51- }
46+ public OnPlayerDisconnect (playerid, reason) {
5247
53- hook OnPlayerStateChange (playerid, newstate, oldstate) {
48+ WazeGPS_Reset (playerid);
5449
55- switch (newstate)
56- {
57- case PLAYER_STATE_PASSENGER:
58- {
59- foreach (new i: VehicleOccupant[GetPlayerVehicleID (playerid)]) {
60- if (GetPlayerState (i) != PLAYER_STATE_DRIVER) continue ;
61- SetPlayerWaze (playerid, wazeGPS[playerid][wazeGPS_Position][0 ], wazeGPS[playerid][wazeGPS_Position][1 ], wazeGPS[playerid][wazeGPS_Position][2 ], wazeGPS[playerid][wazeGPS_Color]);
62- break ;
63- }
64- }
65- }
66- return true ;
50+ #if defined alsOnPlayerDisconnect
51+ alsOnPlayerDisconnect (playerid, reason);
52+ #else
53+ return true ;
54+ #endif
6755}
6856
57+ #if defined _ALS_OnPlayerDisconnect
58+ #undef OnPlayerDisconnect
59+ #else
60+ # define _ALS_OnPlayerDisconnect
61+ #endif
62+ # define OnPlayerDisconnect alsOnPlayerDisconnect
63+ #if defined alsOnPlayerDisconnect
64+ forward alsOnPlayerDisconnect (playerid, reason);
65+ #endif
66+
6967
7068
7169/*
@@ -85,13 +83,17 @@ public UpdateWaze(playerid, Float:X, Float:Y, Float:Z) {
8583 if (GetPlayerInterior (playerid) != 0 )
8684 return StopWazeGPS (playerid);
8785
88- if (IsPlayerInRangeOfPoint (playerid, 30 .0 , wazeGPS[playerid][wazeGPS_TickPosition][0 ], wazeGPS[playerid][wazeGPS_TickPosition][1 ], wazeGPS[playerid][wazeGPS_TickPosition][2 ]))
89- return true ; // Prevent Lags
86+ if (IsPlayerInRangeOfPoint (playerid, 30 .0 , wazeGPS[playerid][wazeGPS_Position][0 ], wazeGPS[playerid][wazeGPS_Position][1 ], wazeGPS[playerid][wazeGPS_Position][2 ])) {
87+ StopWazeGPS (playerid);
88+ return true ; // Prevent Lags
89+ }
9090
9191 new
9292 MapNode: start,
9393 MapNode: target;
9494
95+ DestroyWazeRoutesGPS (playerid);
96+
9597 GetPlayerPos (playerid, wazeGPS[playerid][wazeGPS_TickPosition][0 ], wazeGPS[playerid][wazeGPS_TickPosition][1 ], wazeGPS[playerid][wazeGPS_TickPosition][2 ]);
9698 if (GetClosestMapNodeToPoint (wazeGPS[playerid][wazeGPS_TickPosition][0 ], wazeGPS[playerid][wazeGPS_TickPosition][1 ], wazeGPS[playerid][wazeGPS_TickPosition][2 ], start) != 0 ) return true ;
9799 if (GetClosestMapNodeToPoint (X, Y, Z, target)) return true ;
@@ -103,26 +105,21 @@ public OnPlayerWazeRouters(Path:pathid, playerid) {
103105 if (! IsValidPath (pathid)) return true ;
104106 if (! wazeGPS[playerid][wazeGPS_Timer]) return true ;
105107
106- DestroyWazeRoutesGPS (playerid);
107-
108- new
109- Float: length,
110- size;
111-
108+ new size;
112109 GetPathSize (pathid, size);
113- GetPathLength (pathid, length);
114-
115- if (size == 1 )
116- return StopWazeGPS (playerid);
110+ if (size == 1 ) return StopWazeGPS (playerid);
117111
118112 new
119113 MapNode: nodeid,
120114 Float: x,
121115 Float: y,
122116 Float: z,
117+ Float: length,
123118 index;
124119
125120 GetPlayerPos (playerid, x, y, z);
121+
122+ GetPathLength (pathid, length);
126123 GetClosestMapNodeToPoint (x, y, z, nodeid);
127124 GetMapNodePos (nodeid, x, y, z);
128125
@@ -140,8 +137,9 @@ public OnPlayerWazeRouters(Path:pathid, playerid) {
140137 GetMapNodePos (nodeid, X, Y, Z);
141138
142139 if (i == index)
143- CreateWazePointer (playerid, x, y, X, Y, wazeGPS[playerid][wazeGPS_Color]);
144-
140+ if (! CreateWazePointer (playerid, x, y, X, Y, wazeGPS[playerid][wazeGPS_Color]))
141+ break ;
142+
145143 x = X + 0 .5 ;
146144 y = Y + 0 .5 ;
147145 }
@@ -162,19 +160,18 @@ public OnPlayerWazeRouters(Path:pathid, playerid) {
162160
163161*/
164162
165- static stock Float: GDBP (Float: X, Float: Y, Float: Z, Float: PointX, Float: PointY, Float: PointZ)
166- return ( floatsqroot (floatadd (floatadd (floatpower (floatsub (X, PointX), 2 .0 ), floatpower (floatsub (Y, PointY), 2 .0 )), floatpower (floatsub (Z, PointZ), 2 .0 ) )));
163+ static stock Float: GDBP (Float: X, Float: Y, Float: Z, Float: PointX, Float: PointY, Float: PointZ)
164+ return floatsqroot(floatadd (floatadd (floatpower (floatsub (X, PointX), 2 .0 ), floatpower (floatsub (Y, PointY), 2 .0 )), floatpower (floatsub (Z, PointZ), 2 .0 )));
167165
168166stock IsValidWazeGPS (playerid)
169167 return (wazeGPS[playerid][wazeGPS_Timer] <= 0 ? (false ) : (true ));
170168
171169static stock WazeGPS_Reset (playerid) {
172170
173171 StopWazeGPS (playerid);
174- Iter_Clear (wazePointers[playerid]);
175172
176- new dsada [WAZEGPS_ENUM];
177- wazeGPS[playerid] = dsada ;
173+ static const e_Clear [WAZEGPS_ENUM];
174+ wazeGPS[playerid] = e_Clear ;
178175}
179176
180177stock SetPlayerWaze (playerid, Float: x, Float: y, Float: z, color = 0x 8A44E4FF ) {
@@ -204,38 +201,41 @@ stock StopWazeGPS(playerid) {
204201
205202static stock DestroyWazeRoutesGPS (playerid) {
206203
207- foreach (new i: wazePointers[playerid]) {
208- GangZoneDestroy (wazeGPS[playerid][wazeGPS_Routes][i]);
209- Iter_Remove (wazePointers[playerid], i);
210- }
204+ for (new i = 0 ; i < wazeGPS[playerid][wazeGPS_Count]; i++ ) {
205+ if (! wazeGPS[playerid][wazeGPS_Created][i]) continue ;
206+
207+ wazeGPS[playerid][wazeGPS_Created][i] = false ;
208+ GangZoneDestroy (wazeGPS[playerid][wazeGPS_Routes][i]);
209+ }
210+
211+ wazeGPS[playerid][wazeGPS_Count] = 0 ;
211212}
212213
213214static stock CreateWazePointer (playerid, Float: X1, Float: Y1, Float: X2, Float: Y2, color) {
214215
215216 new
216217 Float: Dis = 12 .5 ,
217- Float: x, Float: y,
218- Points = floatround (GDBP (X1, Y1, 0 .0 , X2, Y2, 0 .0 ) / Dis);
218+ Float: x,
219+ Float: y,
220+ Float: GDPointers = GDBP (X1, Y1, 0 .0 , X2, Y2, 0 .0 ),
221+ Points = floatround (GDPointers / Dis),
222+ index;
219223
220224 for (new i = 1 ; i <= Points; i++ ) {
221225
222- switch (i) {
223- case 0 : {
224- x = X1;
225- y = Y1;
226- }
227- default : {
228- x = X1 + (((X2 - X1) / Points) * i);
229- y = Y1 + (((Y2 - Y1) / Points) * i);
230- }
231- }
232-
233- new index = Iter_Free (wazePointers[playerid]);
234- if (index == - 1 ) break ;
235-
236- wazeGPS[playerid][wazeGPS_Routes][index] = GangZoneCreate (x - (Dis / 2 )- 5 , y - (Dis / 2 ) - 5 , x + (Dis / 2 ) + 5 , y + (Dis / 2 ) + 5 );
226+ index = wazeGPS[playerid][wazeGPS_Count];
227+
228+ if (index >= MAX_WAZE_DOTS)
229+ return false ;
230+
231+ x = X1 + (((X2 - X1) / Points) * i);
232+ y = Y1 + (((Y2 - Y1) / Points) * i);
233+
234+ wazeGPS[playerid][wazeGPS_Created][index] = true ;
235+ wazeGPS[playerid][wazeGPS_Routes][index] = GangZoneCreate (x- (Dis/ 2 )- 5 , y- (Dis/ 2 )- 5 , x+ (Dis/ 2 )+ 5 , y+ (Dis/ 2 )+ 5 );
237236 GangZoneShowForPlayer (playerid, wazeGPS[playerid][wazeGPS_Routes][index], color);
238237
239- Iter_Add (wazePointers [playerid], index) ;
238+ wazeGPS [playerid][wazeGPS_Count] ++ ;
240239 }
240+ return true ;
241241}
0 commit comments