SHOW:
|
|
- or go back to the newest paste.
1 | /*============================================================================== | |
2 | Derby Script v1 by OutLawZ | |
3 | ==============================================================================*/ | |
4 | ||
5 | #include <a_samp> | |
6 | #include <sscanf2> | |
7 | ||
8 | #define DERBY_INTERMISSION "90" // Time in seconds for the next derby to commence | |
9 | #define DERBY_COOLDOWN "30" // Time in seconds for the players to signup | |
10 | #define DERBY_COUNTDOWN "5" // Time in seconds for countdown | |
11 | #define MONEY_REWARD "500" // Money reward for the player that wins | |
12 | #define SCORE_REWARD "10" // Score reward for the player that wins | |
13 | #define ENABLE_CLIENT_MSG // Comment out if you don't want client messages to show | |
14 | ||
15 | #define MIN_DERBY_PLAYERS (2) | |
16 | #define MAX_DERBY_PLAYERS (12) | |
17 | #define MAX_TD_FRAMES (8) | |
18 | #define MAX_CLIENT_STRING (128) | |
19 | ||
20 | #define COLOR_ERROR (0xF11D22FF) | |
21 | #define COLOR_ORANGE (0xF4C70FFF) | |
22 | #define COLOR_GREEN (0x0B9311FF) | |
23 | ||
24 | #define DERBY_LIST "Derbies\\Derby.min" | |
25 | #define DERBY_DATA "Derbies\\%s.deb" | |
26 | ||
27 | #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1])))) | |
28 | ||
29 | forward EndDerby(); | |
30 | forward DerbyTextdraws(); | |
31 | forward Commence_Derby(); | |
32 | forward InitiatePlayers(); | |
33 | forward DerbyRequirementCheck(playerid); | |
34 | forward FreezeVehicle(vehicleid,toggle); | |
35 | forward CountdownDerby(); | |
36 | forward Start_Derby(); | |
37 | forward KickPlayerFromDerby(playerid, reason[]); | |
38 | forward RetVehicle(vehfrz,Float:VX,Float:VY,Float:VZ,Float:VA); | |
39 | forward VehicleToPoint(playerid, Float:radi, Float:px, Float:py, Float:pz); | |
40 | ||
41 | enum DERBY_SETTINGS | |
42 | { | |
43 | bool:Derby_Enabled, | |
44 | bool:Derby_Access, | |
45 | bool:Derby_Start, | |
46 | Derby_Countdown, | |
47 | DerbyMaxPlayers, | |
48 | Derby_Current, | |
49 | File:DerbyFile, | |
50 | Derby_Timer | |
51 | }; | |
52 | ||
53 | enum DERBY_PDATA | |
54 | { | |
55 | Derby_Name[32], | |
56 | Derby_Interior, | |
57 | Derby_World, | |
58 | Derby_VehModel, | |
59 | Float:Derby_Minheight, | |
60 | bool:Derby_ActiveCheck, | |
61 | bool:Derby_HightMeassure | |
62 | }; | |
63 | ||
64 | enum DERBY_INFO | |
65 | { | |
66 | Derby_Vehicle, | |
67 | Float:Derby_Position[4] | |
68 | }; | |
69 | ||
70 | enum DERBY_PLAYERS | |
71 | { | |
72 | bool:DerbySigned, | |
73 | Float:DerbyJoinP[4], | |
74 | Float:DerbyHealth, | |
75 | DerbyIW[2], | |
76 | DerbyWeapons[13], | |
77 | DerbyAmmo[13], | |
78 | DerbyInactive | |
79 | }; | |
80 | ||
81 | new | |
82 | DerbyWait [MAX_PLAYERS], | |
83 | DerbyString [MAX_CLIENT_STRING], | |
84 | Text:DerbyTextdraw [MAX_TD_FRAMES], | |
85 | fv [MAX_VEHICLES], | |
86 | DerbyPlayers [MAX_PLAYERS][DERBY_PLAYERS], | |
87 | DerbySettings [DERBY_SETTINGS], | |
88 | DerbyData [DERBY_PDATA], | |
89 | DerbyCoords [MAX_DERBY_PLAYERS][DERBY_INFO], | |
90 | Float:D_X, Float:D_Y, Float:D_Z | |
91 | ; | |
92 | ||
93 | public OnFilterScriptInit() | |
94 | { | |
95 | print("\n--------------------------------------"); | |
96 | print(" Derby Filterscript by OutLawZ Loaded "); | |
97 | print("--------------------------------------\n"); | |
98 | ||
99 | if(!fexist(DERBY_LIST)) | |
100 | { | |
101 | printf("Error: You don't have derby file %s", DERBY_LIST); | |
102 | DerbySettings[DerbyFile] = fopen(DERBY_LIST, io_write); | |
103 | fclose(DerbySettings[DerbyFile]); | |
104 | } | |
105 | else | |
106 | { | |
107 | new bool:Empty = true; | |
108 | DerbySettings[DerbyFile] = fopen(DERBY_LIST, io_read); | |
109 | ||
110 | while(fread(DerbySettings[DerbyFile], DerbyString)) | |
111 | if(!isnull(DerbyString)) Empty = false; | |
112 | ||
113 | if(Empty) printf("Error: Derby file %s is empty!", DERBY_LIST); | |
114 | } | |
115 | ||
116 | DerbySettings[Derby_Current] = -1; | |
117 | DerbySettings[Derby_Enabled] = true; | |
118 | ||
119 | DerbyTextdraw[0] = TextDrawCreate(619.000000, 125.000000, "_"); | |
120 | TextDrawBackgroundColor(DerbyTextdraw[0], 255); | |
121 | TextDrawFont(DerbyTextdraw[0], 1); | |
122 | TextDrawLetterSize(DerbyTextdraw[0], 0.519999, 10.200002); | |
123 | TextDrawColor(DerbyTextdraw[0], -1); | |
124 | TextDrawSetOutline(DerbyTextdraw[0], 0); | |
125 | TextDrawSetProportional(DerbyTextdraw[0], 1); | |
126 | TextDrawSetShadow(DerbyTextdraw[0], 1); | |
127 | TextDrawUseBox(DerbyTextdraw[0], 1); | |
128 | TextDrawBoxColor(DerbyTextdraw[0], 140); | |
129 | TextDrawTextSize(DerbyTextdraw[0], 488.000000, -1.000000); | |
130 | TextDrawSetSelectable(DerbyTextdraw[0], 0); | |
131 | ||
132 | DerbyTextdraw[1] = TextDrawCreate(614.000000, 131.000000, "_"); | |
133 | TextDrawBackgroundColor(DerbyTextdraw[1], 255); | |
134 | TextDrawFont(DerbyTextdraw[1], 1); | |
135 | TextDrawLetterSize(DerbyTextdraw[1], 0.519999, 1.799999); | |
136 | TextDrawColor(DerbyTextdraw[1], -1); | |
137 | TextDrawSetOutline(DerbyTextdraw[1], 0); | |
138 | TextDrawSetProportional(DerbyTextdraw[1], 1); | |
139 | TextDrawSetShadow(DerbyTextdraw[1], 1); | |
140 | TextDrawUseBox(DerbyTextdraw[1], 1); | |
141 | TextDrawBoxColor(DerbyTextdraw[1], 150); | |
142 | TextDrawTextSize(DerbyTextdraw[1], 493.000000, -1.000000); | |
143 | TextDrawSetSelectable(DerbyTextdraw[1], 0); | |
144 | ||
145 | DerbyTextdraw[2] = TextDrawCreate(614.000000, 158.000000, "_"); | |
146 | TextDrawBackgroundColor(DerbyTextdraw[2], 255); | |
147 | TextDrawFont(DerbyTextdraw[2], 1); | |
148 | TextDrawLetterSize(DerbyTextdraw[2], 0.519999, 5.599998); | |
149 | TextDrawColor(DerbyTextdraw[2], -1); | |
150 | TextDrawSetOutline(DerbyTextdraw[2], 0); | |
151 | TextDrawSetProportional(DerbyTextdraw[2], 1); | |
152 | TextDrawSetShadow(DerbyTextdraw[2], 1); | |
153 | TextDrawUseBox(DerbyTextdraw[2], 1); | |
154 | TextDrawBoxColor(DerbyTextdraw[2], 150); | |
155 | TextDrawTextSize(DerbyTextdraw[2], 493.000000, -1.000000); | |
156 | TextDrawSetSelectable(DerbyTextdraw[2], 0); | |
157 | ||
158 | DerbyTextdraw[3] = TextDrawCreate(552.000000, 133.000000, "Diesel Induction"); | |
159 | TextDrawAlignment(DerbyTextdraw[3], 2); | |
160 | TextDrawBackgroundColor(DerbyTextdraw[3], 255); | |
161 | TextDrawFont(DerbyTextdraw[3], 2); | |
162 | TextDrawLetterSize(DerbyTextdraw[3], 0.169999, 1.000000); | |
163 | TextDrawColor(DerbyTextdraw[3], -1179010561); | |
164 | TextDrawSetOutline(DerbyTextdraw[3], 0); | |
165 | TextDrawSetProportional(DerbyTextdraw[3], 1); | |
166 | TextDrawSetShadow(DerbyTextdraw[3], 1); | |
167 | TextDrawSetSelectable(DerbyTextdraw[3], 0); | |
168 | ||
169 | DerbyTextdraw[4] = TextDrawCreate(554.000000, 158.000000, "Derby is going to start~n~in 0 seconds!"); | |
170 | TextDrawAlignment(DerbyTextdraw[4], 2); | |
171 | TextDrawBackgroundColor(DerbyTextdraw[4], 255); | |
172 | TextDrawFont(DerbyTextdraw[4], 2); | |
173 | TextDrawLetterSize(DerbyTextdraw[4], 0.199999, 0.899999); | |
174 | TextDrawColor(DerbyTextdraw[4], -1); | |
175 | TextDrawSetOutline(DerbyTextdraw[4], 0); | |
176 | TextDrawSetProportional(DerbyTextdraw[4], 1); | |
177 | TextDrawSetShadow(DerbyTextdraw[4], 1); | |
178 | TextDrawSetSelectable(DerbyTextdraw[4], 0); | |
179 | ||
180 | DerbyTextdraw[5] = TextDrawCreate(614.000000, 187.000000, "_"); | |
181 | TextDrawBackgroundColor(DerbyTextdraw[5], 255); | |
182 | TextDrawFont(DerbyTextdraw[5], 1); | |
183 | TextDrawLetterSize(DerbyTextdraw[5], 0.519999, 1.200000); | |
184 | TextDrawColor(DerbyTextdraw[5], -1); | |
185 | TextDrawSetOutline(DerbyTextdraw[5], 0); | |
186 | TextDrawSetProportional(DerbyTextdraw[5], 1); | |
187 | TextDrawSetShadow(DerbyTextdraw[5], 1); | |
188 | TextDrawUseBox(DerbyTextdraw[5], 1); | |
189 | TextDrawBoxColor(DerbyTextdraw[5], 255); | |
190 | TextDrawTextSize(DerbyTextdraw[5], 493.000000, -1.000000); | |
191 | TextDrawSetSelectable(DerbyTextdraw[5], 0); | |
192 | ||
193 | DerbyTextdraw[6] = TextDrawCreate(554.000000, 197.000000, "Currently 0 Joined!"); | |
194 | TextDrawAlignment(DerbyTextdraw[6], 2); | |
195 | TextDrawBackgroundColor(DerbyTextdraw[6], 255); | |
196 | TextDrawFont(DerbyTextdraw[6], 2); | |
197 | TextDrawLetterSize(DerbyTextdraw[6], 0.199999, 0.899999); | |
198 | TextDrawColor(DerbyTextdraw[6], 463129599); | |
199 | TextDrawSetOutline(DerbyTextdraw[6], 0); | |
200 | TextDrawSetProportional(DerbyTextdraw[6], 1); | |
201 | TextDrawSetShadow(DerbyTextdraw[6], 1); | |
202 | TextDrawSetSelectable(DerbyTextdraw[6], 0); | |
203 | ||
204 | DerbyTextdraw[7] = TextDrawCreate(488.500, 121.000, "hud:radar_race"); | |
205 | TextDrawFont(DerbyTextdraw[7], 4); | |
206 | TextDrawTextSize(DerbyTextdraw[7], 14.500, 13.000); | |
207 | TextDrawColor(DerbyTextdraw[7], -1); | |
208 | ||
209 | Start_Derby(); | |
210 | return 1; | |
211 | } | |
212 | ||
213 | public OnFilterScriptExit() | |
214 | { | |
215 | for(new i; i < MAX_DERBY_PLAYERS; i++) | |
216 | { | |
217 | DestroyVehicle(DerbyCoords[i][Derby_Vehicle]); | |
218 | DerbyCoords[i][Derby_Vehicle] = INVALID_VEHICLE_ID; | |
219 | } | |
220 | ||
221 | for(new i; i < MAX_TD_FRAMES; i++) | |
222 | { | |
223 | TextDrawHideForAll(DerbyTextdraw[i]); | |
224 | TextDrawDestroy(DerbyTextdraw[i]); | |
225 | } | |
226 | DerbySettings[Derby_Enabled] = false; | |
227 | return 1; | |
228 | } | |
229 | ||
230 | stock LoadNextDerby() | |
231 | { | |
232 | DerbySettings[Derby_Current] ++; | |
233 | new Next = -1, D_Load[32]; | |
234 | DerbySettings[DerbyFile] = fopen(DERBY_LIST, io_read); | |
235 | ||
236 | while(fread(DerbySettings[DerbyFile], DerbyString)) | |
237 | { | |
238 | Next++; | |
239 | StripNewLine(DerbyString); | |
240 | ||
241 | if(!Next) format(D_Load, sizeof D_Load, "%s", DerbyString); | |
242 | if(Next == DerbySettings[Derby_Current]) | |
243 | return LoadDerby(DerbyString); | |
244 | } | |
245 | DerbySettings[Derby_Current] = 0; | |
246 | return LoadDerby(D_Load); | |
247 | } | |
248 | ||
249 | stock LoadDerby(derbyname[]) | |
250 | { | |
251 | if(DerbySettings[DerbyFile]) fclose(DerbySettings[DerbyFile]); | |
252 | format(DerbyString, sizeof DerbyString, DERBY_DATA, derbyname); | |
253 | if(!fexist(DerbyString)) return printf("ERROR: Derby Data File (%s) doesn't exist!", DerbyString); | |
254 | ||
255 | DerbySettings[DerbyFile] = fopen(DerbyString, io_read); | |
256 | new Next, iIndex, Float:DCoords[4]; | |
257 | while(fread(DerbySettings[DerbyFile], DerbyString)) | |
258 | { | |
259 | StripNewLine(DerbyString); | |
260 | Next++; | |
261 | ||
262 | if(!sscanf(DerbyString, "p<,>ffff", DCoords[0], DCoords[1], DCoords[2], DCoords[3])) | |
263 | { | |
264 | if(0 <= iIndex < MAX_DERBY_PLAYERS) | |
265 | { | |
266 | DerbyCoords[iIndex][Derby_Position][0] = DCoords[0]; | |
267 | DerbyCoords[iIndex][Derby_Position][1] = DCoords[1]; | |
268 | DerbyCoords[iIndex][Derby_Position][2] = DCoords[2]; | |
269 | DerbyCoords[iIndex][Derby_Position][3] = DCoords[3]; | |
270 | } | |
271 | iIndex++; | |
272 | } | |
273 | else if(!sscanf(DerbyString, "p<|>s[32]iiifll", DerbyData[Derby_Name], DerbyData[Derby_Interior], DerbyData[Derby_World], DerbyData[Derby_VehModel], DerbyData[Derby_Minheight], DerbyData[Derby_ActiveCheck], DerbyData[Derby_HightMeassure])) | |
274 | { | |
275 | printf("Loaded \"%s\" Header", DerbyData[Derby_Name]); | |
276 | } | |
277 | else printf("Error: Derby (%s) has invalid data format @Line %i", DerbyString, Next); | |
278 | } | |
279 | fclose(DerbySettings[DerbyFile]); | |
280 | ||
281 | if(iIndex != MAX_DERBY_PLAYERS) printf("Warning: Loaded Coords for %i derby players (Required: %i)", iIndex, MAX_DERBY_PLAYERS); | |
282 | ||
283 | else printf("Loaded Coordinates for all players"); | |
284 | return 1; | |
285 | } | |
286 | ||
287 | stock StripNewLine(string[]) // DracoBlue | |
288 | { | |
289 | new len = strlen(string); | |
290 | if (string[0]==0) return; | |
291 | if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) { | |
292 | string[len - 1] = 0; | |
293 | if (string[0]==0) return; | |
294 | if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0; | |
295 | } | |
296 | } | |
297 | ||
298 | public Commence_Derby() | |
299 | { | |
300 | DerbySettings[Derby_Access] = false; | |
301 | ||
302 | if(DerbySettings[DerbyMaxPlayers] < 2) | |
303 | { | |
304 | for(new i; i < MAX_PLAYERS; i++) | |
305 | { | |
306 | TextDrawHideForPlayer(i, DerbyTextdraw[0]); | |
307 | TextDrawHideForPlayer(i, DerbyTextdraw[1]); | |
308 | TextDrawHideForPlayer(i, DerbyTextdraw[2]); | |
309 | TextDrawHideForPlayer(i, DerbyTextdraw[3]); | |
310 | TextDrawHideForPlayer(i, DerbyTextdraw[4]); | |
311 | TextDrawHideForPlayer(i, DerbyTextdraw[5]); | |
312 | TextDrawHideForPlayer(i, DerbyTextdraw[6]); | |
313 | TextDrawHideForPlayer(i, DerbyTextdraw[7]); | |
314 | DerbyPlayers[i][DerbySigned] = false; | |
315 | } | |
316 | SendClientMessageToAll(COLOR_GREEN, "Derby Event couldn't start because there were not enough players (Next derby in "#DERBY_INTERMISSION" seconds)"); | |
317 | if(DerbySettings[Derby_Enabled]) SetTimer("Start_Derby", strval(DERBY_INTERMISSION) * 1000, false); | |
318 | DerbySettings[Derby_Start] = false; | |
319 | return 1; | |
320 | } | |
321 | ||
322 | for(new i; i < DerbySettings[DerbyMaxPlayers]; i++) | |
323 | { | |
324 | for(new a; a < MAX_PLAYERS; a++) TextDrawHideForPlayer(i, DerbyTextdraw[a]); | |
325 | DerbyCoords[i][Derby_Vehicle] = CreateVehicle(DerbyData[Derby_VehModel], DerbyCoords[i][Derby_Position][0], DerbyCoords[i][Derby_Position][1], DerbyCoords[i][Derby_Position][2], DerbyCoords[i][Derby_Position][3], -1, -1, 999999); | |
326 | LinkVehicleToInterior(DerbyCoords[i][Derby_Vehicle], DerbyData[Derby_Interior]); | |
327 | SetVehicleVirtualWorld(DerbyCoords[i][Derby_Vehicle], DerbyData[Derby_World]); | |
328 | FreezeVehicle((DerbyCoords[i][Derby_Vehicle]), true); | |
329 | DerbyPlayers[i][DerbyInactive] = 0; | |
330 | } | |
331 | SetTimer("InitiatePlayers", 3000, 0); | |
332 | SendClientMessageToAll(COLOR_GREEN, "Derby Initializing..."); | |
333 | return 1; | |
334 | } | |
335 | ||
336 | public InitiatePlayers() | |
337 | { | |
338 | new iIndex; | |
339 | for(new i; i<MAX_PLAYERS; i++) | |
340 | { | |
341 | if(!DerbyPlayers[i][DerbySigned]) continue; | |
342 | ||
343 | GetPlayerPos(i, DerbyPlayers[i][DerbyJoinP][0], DerbyPlayers[i][DerbyJoinP][1], DerbyPlayers[i][DerbyJoinP][2]); | |
344 | GetPlayerFacingAngle(i, DerbyPlayers[i][DerbyJoinP][3]); | |
345 | DerbyPlayers[i][DerbyIW][0] = GetPlayerInterior(i); | |
346 | DerbyPlayers[i][DerbyIW][1] = GetPlayerVirtualWorld(i); | |
347 | for(new w; w < 13; w++) GetPlayerWeaponData(i, w, DerbyPlayers[i][DerbyWeapons][w], DerbyPlayers[i][DerbyAmmo][w]); | |
348 | ||
349 | RemovePlayerFromVehicle(i); | |
350 | ResetPlayerWeapons(i); | |
351 | ||
352 | SetPlayerInterior(i, DerbyData[Derby_Interior]); | |
353 | SetPlayerVirtualWorld(i, DerbyData[Derby_World]); | |
354 | PutPlayerInVehicle(i, DerbyCoords[iIndex][Derby_Vehicle], 0); | |
355 | TogglePlayerControllable(i, false); | |
356 | iIndex++; | |
357 | } | |
358 | DerbySettings[Derby_Countdown] = strval(DERBY_COUNTDOWN) + 1; | |
359 | DerbySettings[Derby_Start] = true; | |
360 | CountdownDerby(); | |
361 | return 1; | |
362 | } | |
363 | ||
364 | public CountdownDerby() | |
365 | { | |
366 | new D_Small[5]; | |
367 | DerbySettings[Derby_Countdown] --; | |
368 | if(DerbySettings[Derby_Countdown] >= 1) | |
369 | { | |
370 | format(D_Small, sizeof D_Small, "%i", DerbySettings[Derby_Countdown]); | |
371 | for(new i = 0; i < MAX_PLAYERS ;i++) | |
372 | { | |
373 | if(!DerbyPlayers[i][DerbySigned]) continue; | |
374 | GameTextForPlayer(i, D_Small, 1600, 5); | |
375 | } | |
376 | SetTimer("CountdownDerby", 2000, false); | |
377 | } | |
378 | else | |
379 | { | |
380 | for(new i; i < MAX_PLAYERS ;i++) | |
381 | { | |
382 | if(!DerbyPlayers[i][DerbySigned]) continue; | |
383 | GameTextForPlayer(i, "~g~GO", 999, 5); | |
384 | PlayerPlaySound(i, 1057, 0.0, 0.0, 10.0); | |
385 | TogglePlayerControllable(i, true); | |
386 | if(!IsPlayerInAnyVehicle(i)) KickPlayerFromDerby(i, "You lost the derby for exiting your vehicle."); | |
387 | FreezeVehicle(GetPlayerVehicleID(i), false); | |
388 | } | |
389 | DerbySettings[Derby_Timer] = SetTimer("DerbyRequirementCheck", 1000, false); | |
390 | format(DerbyString, sizeof DerbyString, "Derby \"%s\" has been started!", DerbyData[Derby_Name]); | |
391 | SendClientMessageToAll(COLOR_GREEN, DerbyString); | |
392 | } | |
393 | return 1; | |
394 | } | |
395 | ||
396 | ||
397 | public KickPlayerFromDerby(playerid, reason[]) | |
398 | { | |
399 | DerbyPlayers[playerid][DerbySigned] = false; | |
400 | SendClientMessage(playerid, COLOR_ERROR, reason); | |
401 | if(DerbySettings[DerbyMaxPlayers] < 2) return EndDerby(); | |
402 | SetPlayerPos(playerid, DerbyPlayers[playerid][DerbyJoinP][0], DerbyPlayers[playerid][DerbyJoinP][1], DerbyPlayers[playerid][DerbyJoinP][2]); | |
403 | SetPlayerFacingAngle(playerid, DerbyPlayers[playerid][DerbyJoinP][3]); | |
404 | SetPlayerInterior(playerid, DerbyPlayers[playerid][DerbyIW][0]); | |
405 | SetPlayerVirtualWorld(playerid, DerbyPlayers[playerid][DerbyIW][1]); | |
406 | ResetPlayerWeapons(playerid); | |
407 | for(new w; w < 13; w++) GivePlayerWeapon(playerid, DerbyPlayers[playerid][DerbyWeapons][w], DerbyPlayers[playerid][DerbyAmmo][w]); | |
408 | DerbySettings[DerbyMaxPlayers] --; | |
409 | return 1; | |
410 | } | |
411 | ||
412 | public DerbyRequirementCheck(playerid) | |
413 | { | |
414 | if(DerbySettings[DerbyMaxPlayers] < MIN_DERBY_PLAYERS) return EndDerby(); | |
415 | ||
416 | static CheckLocalData; | |
417 | CheckLocalData++; | |
418 | ||
419 | for(new i; i<MAX_PLAYERS; i++) | |
420 | { | |
421 | if(!DerbyPlayers[i][DerbySigned]) continue; | |
422 | if(DerbyData[Derby_HightMeassure]) | |
423 | { | |
424 | GetPlayerPos(i, D_X, D_Y, D_Z); | |
425 | if (D_Z < DerbyData[Derby_Minheight]) KickPlayerFromDerby(i, "You lost the derby for falling out of range."); | |
426 | } | |
427 | if(!IsPlayerInAnyVehicle(i)) | |
428 | { | |
429 | KickPlayerFromDerby(i, "You lost the derby for exiting your vehicle."); | |
430 | continue; | |
431 | } | |
432 | if(CheckLocalData >= 20) | |
433 | { | |
434 | if(DerbyData[Derby_ActiveCheck]) | |
435 | { | |
436 | GetVehicleHealth(GetPlayerVehicleID(i), D_X); | |
437 | if(D_X == DerbyPlayers[i][DerbyHealth]) | |
438 | { | |
439 | if(++DerbyPlayers[i][DerbyInactive] >= 20) | |
440 | { | |
441 | GetVehicleHealth(GetPlayerVehicleID(i), D_Y); | |
442 | SetVehicleHealth(GetPlayerVehicleID(i), D_Y - 150.00); | |
443 | SendClientMessage(i, 0xFF0000FF, "Your vehicle health is decreased by 150 for avoiding being hit."); | |
444 | } | |
445 | } | |
446 | else | |
447 | { | |
448 | DerbyPlayers[i][DerbyHealth] = D_X; | |
449 | DerbyPlayers[i][DerbyInactive] = 0; | |
450 | } | |
451 | } | |
452 | CheckLocalData = 0; | |
453 | } | |
454 | } | |
455 | if(DerbySettings[Derby_Start]) SetTimer("DerbyRequirementCheck", 1000, false); | |
456 | return 1; | |
457 | } | |
458 | ||
459 | public EndDerby() | |
460 | { | |
461 | if(DerbySettings[DerbyMaxPlayers] >= 2) return 1; | |
462 | if(!DerbySettings[Derby_Start]) return 1; | |
463 | ||
464 | DerbySettings[Derby_Start] = false; | |
465 | KillTimer(DerbySettings[Derby_Timer]); | |
466 | ||
467 | #if defined ENABLE_CLIENT_MSG | |
468 | format(DerbyString, sizeof DerbyString, "Derby \"%s\" has ended, (Next derby in "#DERBY_INTERMISSION" seconds)", DerbyData[Derby_Name]); | |
469 | SendClientMessageToAll(COLOR_GREEN, DerbyString); | |
470 | #endif | |
471 | ||
472 | for(new i; i < MAX_PLAYERS; i++) | |
473 | { | |
474 | if(!DerbyPlayers[i][DerbySigned]) continue; | |
475 | DerbyPlayers[i][DerbySigned] = false; | |
476 | ||
477 | GetPlayerName(i, DerbyString, MAX_PLAYER_NAME); | |
478 | format(DerbyString, sizeof DerbyString, "%s won the derby with a reward of $"#MONEY_REWARD" and "#SCORE_REWARD" points", DerbyString); | |
479 | SendClientMessageToAll(COLOR_GREEN, DerbyString); | |
480 | ||
481 | GivePlayerMoney(i, strval(MONEY_REWARD)); | |
482 | SetPlayerScore(i, GetPlayerScore(i) + strval(SCORE_REWARD)); | |
483 | ||
484 | SetPlayerPos(i, DerbyPlayers[i][DerbyJoinP][0], DerbyPlayers[i][DerbyJoinP][1], DerbyPlayers[i][DerbyJoinP][2]); | |
485 | SetPlayerFacingAngle(i, DerbyPlayers[i][DerbyJoinP][3]); | |
486 | SetPlayerInterior(i, DerbyPlayers[i][DerbyIW][0]); | |
487 | SetPlayerVirtualWorld(i, DerbyPlayers[i][DerbyIW][1]); | |
488 | ResetPlayerWeapons(i); | |
489 | for(new w; w < 13; w++) GivePlayerWeapon(i, DerbyPlayers[i][DerbyWeapons][w], DerbyPlayers[i][DerbyAmmo][w]); | |
490 | } | |
491 | ||
492 | for(new i; i < MAX_DERBY_PLAYERS; i++) | |
493 | { | |
494 | DestroyVehicle(DerbyCoords[i][Derby_Vehicle]); | |
495 | DerbyCoords[i][Derby_Vehicle] = INVALID_VEHICLE_ID; | |
496 | } | |
497 | ||
498 | DerbySettings[DerbyMaxPlayers] = 0; | |
499 | DerbySettings[Derby_Countdown] = 0; | |
500 | DerbySettings[Derby_Access] = false; | |
501 | ||
502 | if(DerbySettings[Derby_Enabled]) SetTimer("Start_Derby", strval(DERBY_INTERMISSION) * 1000, false); | |
503 | return 1; | |
504 | } | |
505 | ||
506 | public Start_Derby() | |
507 | { | |
508 | LoadNextDerby(); | |
509 | ||
510 | #if defined ENABLE_CLIENT_MSG | |
511 | format(DerbyString, sizeof DerbyString,"%s is going to start in "#DERBY_COOLDOWN" seconds, /derby to sign up.", DerbyData[Derby_Name]); | |
512 | SendClientMessageToAll(COLOR_GREEN, DerbyString); | |
513 | #endif | |
514 | ||
515 | DerbySettings[DerbyMaxPlayers] = 0; | |
516 | DerbySettings[Derby_Access] = true; | |
517 | DerbySettings[Derby_Countdown] = strval(DERBY_COOLDOWN); | |
518 | ||
519 | for(new i; i < MAX_PLAYERS; i++) | |
520 | { | |
521 | for(new w; w < MAX_TD_FRAMES; w++) TextDrawShowForPlayer(i, DerbyTextdraw[w]); | |
522 | DerbyWait[i] = 0; | |
523 | } | |
524 | DerbyTextdraws(); | |
525 | return 1; | |
526 | } | |
527 | ||
528 | public DerbyTextdraws() | |
529 | { | |
530 | DerbySettings[Derby_Countdown] --; | |
531 | TextDrawSetString(DerbyTextdraw[3], DerbyData[Derby_Name]); | |
532 | ||
533 | format(DerbyString, sizeof DerbyString, "Derby is going to start~n~in %i seconds!", DerbySettings[Derby_Countdown]); | |
534 | TextDrawSetString(DerbyTextdraw[4], DerbyString); | |
535 | ||
536 | format(DerbyString, sizeof DerbyString, "Currently %i Joined!", DerbySettings[DerbyMaxPlayers]); | |
537 | TextDrawSetString(DerbyTextdraw[6], DerbyString); | |
538 | ||
539 | if(DerbySettings[Derby_Countdown] <= 0) | |
540 | { | |
541 | for(new i = 0; i < MAX_PLAYERS;i++) | |
542 | { | |
543 | if(IsPlayerConnected(i) && DerbyPlayers[i][DerbySigned]) | |
544 | { | |
545 | TextDrawHideForPlayer(i, DerbyTextdraw[4]); | |
546 | TextDrawHideForPlayer(i, DerbyTextdraw[6]); | |
547 | } | |
548 | } | |
549 | Commence_Derby(); | |
550 | } | |
551 | else SetTimer("DerbyTextdraws", 1000, 0); | |
552 | } | |
553 | ||
554 | public OnPlayerConnect(playerid) | |
555 | { | |
556 | DerbyWait[playerid] = gettime() + 45; // I added this to prevent textdraw bugs! | |
557 | return 1; | |
558 | } | |
559 | ||
560 | public OnPlayerDisconnect(playerid, reason) | |
561 | { | |
562 | if(DerbyPlayers[playerid][DerbySigned]) | |
563 | { | |
564 | DerbySettings[DerbyMaxPlayers] --; | |
565 | DerbyPlayers[playerid][DerbySigned] = false; | |
566 | } | |
567 | return 1; | |
568 | } | |
569 | ||
570 | public OnPlayerDeath(playerid, killerid, reason) | |
571 | { | |
572 | if(DerbyPlayers[playerid][DerbySigned] && DerbySettings[Derby_Start]) | |
573 | { | |
574 | DerbySettings[DerbyMaxPlayers] --; | |
575 | DerbyPlayers[playerid][DerbySigned] = false; | |
576 | if(DerbySettings[DerbyMaxPlayers] < 2) return EndDerby(); | |
577 | GameTextForPlayer(playerid, "~r~You have been kicked out!", 4000, 0); | |
578 | } | |
579 | return 1; | |
580 | } | |
581 | ||
582 | public OnPlayerExitVehicle(playerid, vehicleid) | |
583 | { | |
584 | if(DerbyPlayers[playerid][DerbySigned] && DerbySettings[Derby_Start]) | |
585 | { | |
586 | KickPlayerFromDerby(playerid, "You lost the derby for exiting your vehicle."); | |
587 | } | |
588 | return 1; | |
589 | } | |
590 | ||
591 | public FreezeVehicle(vehicleid, toggle) // Seif | |
592 | { | |
593 | new Float:fvX,Float:fvY,Float:fvZ,Float:fvA; | |
594 | new mp = GetMaxPlayers(); | |
595 | for(new all = 0; all < mp; all++) | |
596 | { | |
597 | if (GetPlayerState(all) == 2) | |
598 | { | |
599 | if (GetPlayerVehicleID(all) == vehicleid) | |
600 | { | |
601 | TogglePlayerControllable(all,0); | |
602 | TogglePlayerControllable(all,1); | |
603 | } | |
604 | } | |
605 | } | |
606 | GetVehiclePos(vehicleid,fvX,fvY,fvZ); | |
607 | GetVehicleZAngle(vehicleid,fvA); | |
608 | ||
609 | if (toggle == 1) fv[vehicleid] = SetTimerEx("RetVehicle", 200,1,"iffff",vehicleid,fvX,fvY,fvZ,fvA); | |
610 | else KillTimer(fv[vehicleid]); | |
611 | } | |
612 | ||
613 | public RetVehicle(vehfrz,Float:VX,Float:VY,Float:VZ,Float:VA) | |
614 | { | |
615 | if (!VehicleToPoint(vehfrz,1.0,VX,VY,VZ)) | |
616 | { | |
617 | SetVehiclePos(vehfrz,VX,VY,VZ); | |
618 | SetVehicleZAngle(vehfrz,VA); | |
619 | } | |
620 | } | |
621 | ||
622 | public VehicleToPoint(playerid, Float:radi, Float:px, Float:py, Float:pz) | |
623 | { | |
624 | if(IsPlayerConnected(playerid)) | |
625 | { | |
626 | new Float:x, Float:y, Float:z; | |
627 | new Float:ox, Float:oy, Float:oz; | |
628 | GetVehiclePos(playerid, ox, oy, oz); | |
629 | x = (ox -px); | |
630 | y = (oy -py); | |
631 | z = (oz -pz); | |
632 | if (((x < radi) && (x > -radi)) && ((y < radi) && (y > -radi)) && ((z < radi) && (z > -radi))) return 1; | |
633 | } | |
634 | return 0; | |
635 | } | |
636 | ||
637 | public OnPlayerCommandText(playerid, cmdtext[]) | |
638 | { | |
639 | if (strcmp("/derby", cmdtext, true, 10) == 0) | |
640 | { | |
641 | if(!DerbySettings[Derby_Enabled]) return SendClientMessage(playerid, COLOR_ERROR, "Derbies are currently closed."); | |
642 | if(!DerbySettings[Derby_Access]) return SendClientMessage(playerid, COLOR_ERROR, "Derby signups are currently closed, wait for the next one to start."); | |
643 | if(DerbyPlayers[playerid][DerbySigned]) return SendClientMessage(playerid, COLOR_ERROR, "You already signed up for the derby, wait for it to start!"); | |
644 | if(DerbyWait[playerid] - gettime() > 1) return SendClientMessage(playerid, COLOR_ERROR, "Please wait before you can join the derby!"); | |
645 | if(DerbySettings[DerbyMaxPlayers] >= MAX_DERBY_PLAYERS) return SendClientMessage(playerid, COLOR_ERROR, "The arena is full!"); | |
646 | ||
647 | DerbySettings[DerbyMaxPlayers] ++; | |
648 | DerbyPlayers[playerid][DerbySigned] = true; | |
649 | GetPlayerName(playerid, DerbyString, MAX_PLAYER_NAME); | |
650 | ||
651 | SendClientMessage(playerid, COLOR_ORANGE, "You have successfully signed up for the derby!"); | |
652 | TextDrawShowForPlayer(playerid, DerbyTextdraw[6]); | |
653 | ||
654 | #if defined ENABLE_CLIENT_MSG | |
655 | format(DerbyString, sizeof DerbyString, "%s has signed up for derby using /derby", DerbyString); | |
656 | SendClientMessageToAll(COLOR_ORANGE, DerbyString); | |
657 | #endif | |
658 | ||
659 | return 1; | |
660 | } | |
661 | return 0; | |
662 | } |