/
LAC-GPS.inc
313 lines (251 loc) · 7.3 KB
/
LAC-GPS.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* ValkGPS
*
* Modos de uso del GPS:
* GPS_MODE_1: Al marcar una ubicacion en el mapa, el GPS creara un checkpoint y se le marcara al jugador el camino.
* GPS_MODE_2: Se hookeara la funcion SetPlayerCheckpoint y al crear un checkpoint, automaticamente se le marcara el camino.
* GPS_MODE_ALL: GPS_MODE_1 + GPS_MODE_2
* Version: 1.0
*
* Creditos:
* Gamer_Z, #Fede
*/
#if defined include_valk_gps
#endinput
#endif
#define include_valk_gps
/* Parametros configurables */
#define GPS_COLOR 0x8A44E4FF
new const ColorsRutePlayerGPS[] = {
0x8A44E4FF, // Morado
0xDA1515FF // Rojo
};
#define GPS_UPDATE_TIME 1100
#if !defined GPS_MODE_1 && !defined GPS_MODE_2 && !defined GPS_MODE_ALL
#error "GPS_MODE is not defined"
#endif
#if defined GPS_MODE_ALL
#define GPS_MODE_1
#define GPS_MODE_2
#endif
#define MAX_DOTS 100
#include <GPS>
#include <YSI_Coding\y_hooks>
/* --------------------------------------------------------------------- */
#if __Pawn != 0x030A
#define INITIALIZE_WITH_FOR // Fix problem for native-compiler users.
#endif
new static
bool:playerHasGPSActive[MAX_PLAYERS],
PlayerColorGPS[MAX_PLAYERS],
PlayerGPSTimer[MAX_PLAYERS],
Float:PlayerGPS_PointX[MAX_PLAYERS],
Float:PlayerGPS_PointY[MAX_PLAYERS],
Float:PlayerGPS_PointZ[MAX_PLAYERS],
#if defined INITIALIZE_WITH_FOR
Routes[MAX_PLAYERS][MAX_DOTS] = {-1, ...};
#else
Routes[MAX_PLAYERS][MAX_DOTS];
#endif
/* --------------------- */
#if defined INITIALIZE_WITH_FOR
hook OnPlayerConnect(playerid)
{
for(new i; i < MAX_DOTS; i++)
{
Routes[playerid][i] = -1;
}
return Y_HOOKS_CONTINUE_RETURN_1;
}
#endif
forward OnPathFound(Path:pathid, playerid);
stock Float:GDBP(Float:X, Float:Y, Float:Z, Float: PointX, Float: PointY, Float: PointZ) return floatsqroot(floatadd(floatadd(floatpower(floatsub(X, PointX), 2.0), floatpower(floatsub(Y, PointY), 2.0)), floatpower(floatsub(Z, PointZ), 2.0)));
/*stock Float:GDBP(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ) return VectorSize(X-PointX, Y-PointY, Z-PointZ);*/
/* --------------------------------------------------------------------- */
hook OnPlayerDisconnect(playerid, reason)
{
if(playerHasGPSActive[playerid])
{
ForcePlayerEndLastRoute(playerid);
}
return Y_HOOKS_CONTINUE_RETURN_1;
}
/*#if defined GPS_MODE_1
hook OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
{
StartPlayerPath(playerid, fX, fY, fZ);
return Y_HOOKS_CONTINUE_RETURN_1;
}
#endif*/
/* --------------------------------------------------------------------- */
forward AssignatePlayerPath(playerid, Float:X, Float:Y, Float:Z);
public AssignatePlayerPath(playerid, Float:X, Float:Y, Float:Z)
{
new Float:x, Float:y, Float:z, MapNode:start, MapNode:target;
GetPlayerPos(playerid, x, y, z);
if((GDBP(X, Y, 0.0, x, y, 0.0) <= 7.5))
{
ForcePlayerEndLastRoute(playerid);
return 1;
}
if (GetClosestMapNodeToPoint(x, y, z, start) != 0) return print("Error Code 1.");
if (GetClosestMapNodeToPoint(X, Y, Z, target)) return print("Error: Code 2");
if (FindPathThreaded(start, target, "OnPathFound", "i", playerid))
{
SendClientMessage(playerid, -1, "Error: Code 4.");
return 1;
}
return 1;
}
public OnPathFound(Path:pathid, playerid)
{
if(!IsValidPath(pathid)) return SendClientMessage(playerid, -1, "Error: Code 5.");
DestroyRoutes(playerid);
new size, Float:length;
GetPathSize(pathid, size);
GetPathLength(pathid, length);
if(size == 1)
{
ForcePlayerEndLastRoute(playerid);
return /*SendClientMessage(playerid, -1, "Has llegado a tu destino.");*/ 1;
}
new MapNode:nodeid, index, Float:lastx, Float:lasty,Float:lastz;
GetPlayerPos(playerid, lastx, lasty, lastz);
GetClosestMapNodeToPoint(lastx, lasty, lastz, nodeid);
GetMapNodePos(nodeid, lastx, lasty, lastz);
new _max = MAX_DOTS;
if(MAX_DOTS > size) _max = size;
new Float:X,Float:Y,Float:Z;
for(new i = 0; i < _max; i++)
{
GetPathNode(pathid, i, nodeid);
GetPathNodeIndex(pathid, nodeid, index);
GetMapNodePos(nodeid, X, Y, Z);
if(i == index) CreateMapRoute(playerid, lastx, lasty, X, Y, ColorsRutePlayerGPS[ PlayerColorGPS[playerid] ]);
lastx = X+0.5;
lasty = Y+0.5;
}
return 1;
}
ForcePlayerEndLastRoute(playerid)
{
PlayerGPS_PointX[playerid] = 0.0;
PlayerGPS_PointY[playerid] = 0.0;
PlayerGPS_PointZ[playerid] = 0.0;
KillTimer(PlayerGPSTimer[playerid]);
playerHasGPSActive[playerid] = false;
DestroyRoutes(playerid);
}
StartPlayerPath(playerid, Float:X, Float:Y, Float:Z)
{
//ForcePlayerEndLastRoute(playerid);
playerHasGPSActive[playerid] = true;
PlayerGPS_PointX[playerid] = X;
PlayerGPS_PointY[playerid] = Y;
PlayerGPS_PointZ[playerid] = Z;
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
AssignatePlayerPath(playerid, X, Y, Z);
PlayerGPSTimer[playerid] = SetTimerEx("AssignatePlayerPath", GPS_UPDATE_TIME, true, "ifff", playerid, X, Y, Z);
}
}
IsPlayerGPSIsActive(playerid)
{
return playerHasGPSActive[playerid];
}
RestorePlayerGPSRoutes(playerid)
{
KillTimer(PlayerGPSTimer[playerid]);
AssignatePlayerPath(playerid, PlayerGPS_PointX[playerid], PlayerGPS_PointY[playerid], PlayerGPS_PointZ[playerid]);
//PlayerGPSTimer[playerid] = repeat AssignatePlayerPath(playerid, PlayerGPS_PointX[playerid], PlayerGPS_PointY[playerid], PlayerGPS_PointZ[playerid]);
PlayerGPSTimer[playerid] = SetTimerEx("AssignatePlayerPath", GPS_UPDATE_TIME, true, "ifff", playerid, PlayerGPS_PointX[playerid], PlayerGPS_PointY[playerid], PlayerGPS_PointZ[playerid]);
return 1;
}
CreateMapRoute(playerid, Float:X1, Float:Y1, Float:X2, Float:Y2, color)
{
new Float:Dis = 12.5;
new Float:TotalDis = GDBP(X1, Y1, 0.0, X2, Y2, 0.0);
new Points = floatround(TotalDis / Dis);
for(new i = 1; i <= Points; i++)
{
new Float:x, Float:y;
if(i != 0)
{
x = X1 + (((X2 - X1) / Points)*i);
y = Y1 + (((Y2 - Y1) / Points)*i);
}
else
{
x = X1;
y = Y1;
}
new slot = 0;
while(slot <= MAX_DOTS)
{
if(slot == MAX_DOTS)
{
slot = -1;
break;
}
if(Routes[playerid][slot] == -1)
{
break;
}
slot++;
}
if(slot == -1) return;
Routes[playerid][slot] = CreatePlayerGangZone(playerid, x-(Dis / 2)-5, y-(Dis / 2)-5, x+(Dis / 2)+5, y+(Dis / 2)+5);
PlayerGangZoneShow(playerid, Routes[playerid][slot], color);
}
}
DestroyRoutes(playerid)
{
for(new x; x < MAX_DOTS; x++)
{
if(Routes[playerid][x] != -1)
{
PlayerGangZoneDestroy(playerid, Routes[playerid][x]);
Routes[playerid][x] = -1;
}
}
}
HideGPSRoutes(playerid)
{
if(playerHasGPSActive[playerid] == true)
{
KillTimer(PlayerGPSTimer[playerid]);
DestroyRoutes(playerid);
}
return 1;
}
#if defined GPS_MODE_2
stock GPS_SetPlayerCheckpoint(playerid, Float:x, Float:y, Float:z)
{
ForcePlayerEndLastRoute(playerid);
StartPlayerPath(playerid, x, y, z);
return 1;
}
stock SetPlayerCheckpointGPS(playerid, Float:x,Float:y, Float:z, color = 0, bool:force = false)
{
if(force == true)
{
if(playerHasGPSActive[playerid] == true) return 0;
}
ForcePlayerEndLastRoute(playerid);
StartPlayerPath(playerid, x,y,z);
PlayerColorGPS[playerid] = color;
return 1;
}
stock GPS_DestroyPlayerCP(playerid)
{
ForcePlayerEndLastRoute(playerid);
return 1;
}
#endif
/*#if defined _ALS_SetPlayerCheckpoint
#undef SetPlayerCheckpoint
#else
#define _ALS_SetPlayerCheckpoint
#endif
#define SetPlayerCheckpoint GPS_SetPlayerCheckpoint
#endif*/