-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRandomRaceGenerator.pwn
3734 lines (3194 loc) · 125 KB
/
RandomRaceGenerator.pwn
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
// - - - - - - - - - - - - - - - - //
// Random Race Generator v1.2.1 //
// - - - - - - - - - - - - - - - - //
Description:
This script allows the player to randomly
create races across the San Andreas map.
While doing this, it provides a neat GUI for
viewing the current available races.
Commands:
/rrg (main command)
/rrg help
- shows all possible commands in the chat.
/rrg menu
- shows the race list (join & create).
/rrg respawn
- respawns the at the last checkpoint.
/rrg leave
- leave the current race or call it off.
/rrg start
- starts the current race, if player is
the host.
/rrg invite [name]
- invite another player to your race, if
the inviting player is host.
/rrg showinvite
- shows the last received invite.
Contest:
This script was made for the RouteConnector
contest, hosted by Gamer_Z.
Contest URL:
http://forum.sa-mp.com/showthread.php?t=411412
Thanks a lot:
- Gamer_Z;
- Mauzen;
- All the people who contributed to the forums
with their snippets and examples!
End note:
Feel free to edit this script as you like. You
are also allowed to borrow any code from it,
as long as you keep some credits to me.
Please do not claim this as your own.
If you have any problems with or questions
about this script, please contact me via the
official SA-MP forums or on GitHub.
An extensive readme can be found on the
GitHub page of this script.
Topic URL:
http://forum.sa-mp.com/showthread.php?t=437708
GitHub URL:
https://github.com/Basssiiie/Random-Race-Generator
Regards,
Basssiiie
*/
// ---------------------------------------------
// --- > --- > --- MAIN SETTINGS --- < --- < ---
// ---------------------------------------------
// This defines the amount of milliseconds before you'll be respawned.
// Default: 2000
#define RESPAWN_TIME 2000
// This defines the virtual world which will be used for the races.
// Note: if this isn't 0 and REMEMBER_OLD_POSITION is false, make sure there's a way out of this virtual world! (Ex. via other cmds)
// Default: 0
#define RACE_VIRTUAL_WORLD 0
// This is the amount of seconds it will take before a player gets disqualified for leaving their vehicle.
// Note: set to 0 if you want to disable this, which allows players to roam the land on foot and they might annoy other people.
// Default: 25
#define VEHICLE_LEAVE_TIME 25
// This defines the amount of milliseconds the game will wait after the first person finished a race, before the race will be cleaned up.
// Note: when a race is cleaned up, everyone is removed from the race and the race-slot becomes available again.
// Default: 60000
#define RACE_CLEANUP_TIME 60000
// This defines whether to remember the old position of a player, before he joins a race.
// Note: when set to true, the player will be spawned at his old position after the race finishes.
// Default: false
#define REMEMBER_OLD_POSITION false
// The amount of time in seconds a race invite will stay active.
// During this time, the invited player can't receive other invites.
// Default: 20
#define INVITE_EXPIRE 20
// -------------------------------------------------
// --- > --- > --- LIMITING SETTINGS --- < --- < ---
// -------------------------------------------------
// This is the maximum amount of public races shown in the list.
// Note: if this number is too high, it will overlap the other buttons.
// Default: 13
#define MAX_PUBLIC_RACES 13
// This is the maximum amount of private races available through the "Create private race"-button.
// Default: 25
#define MAX_PRIVATE_RACES 25
// This is the "maximum" distance a race can be in meters.
// Note: the race won't stop at this exact number, it will try to find a finish point as quickly as possible.
// Default: 30000
#define MAX_RACE_DISTANCE 30000
// This defines the minimal distance a race can be in meters.
// Default: 150
#define MIN_RACE_DISTANCE 150
// This number defines the maximum amount of checkpoints that will be saved into memory.
// Note 1: if a race exceeds this number, it will immediately spawn a finish point at the last checkpoint.
// Note 2: try to find a good balance between this number and MAX_RACE_DISTANCE.
// Default: 300
#define MAX_CHECKPOINTS 300
// This number is the maximum amount of textdraw icons that will be shown on the race menu map.
// Note: the limit seems to be somewhere around 85.
// Default: 80
#define MAX_TEXTDRAW_ICONS 80
// This is the maximum amount of contestants that are allowed to join a race.
// Note 1: this number includes the race starter!
// Note 2: the higher the number, the more vehicles have to be spawned, the higher the chance that they'll get stuck inside buildings.
// Default: 8
#define MAX_CONTESTANTS 8
// This is the minimum amount of contestants that are required to start a race.
// Note 1: this number includes the race starter.
// Note 2: setting this number to anything below 2 will allow 1-player races.
// Default: 2
#define MIN_CONTESTANTS 2
// This is the minimum distance between checkpoints.
// Default: 100.0
#define MINIMAL_DISTANCE_CP 100.0
// This number defines the maximum amount of map icons on the radar, which will be used to suggest the next checkpoints.
// Note 1: as of 0.3x, the limit is 100 map icons.
// Note 2: if you are using a map icon streamer, these suggested icons might not work properly.
// Default: 2
#define MAX_SUGGESTED_MAPICONS 2
// ------------------------------------------------
// --- > --- > --- VEHICLE SETTINGS --- < --- < ---
// ------------------------------------------------
// This is a list with the available vehicles during the race.
// Note: this is a very error-prone part of the script, be careful with adding other vehicles!
// Example: 415,
new RaceVehicleList[] = {
415, // Cheetah
411, // Infernus
451, // Turismo
560, // Sultan
494, // Hotring Racer
524, // Cement Truck
407, // Firetruck
444, // Monster Truck
423, // Mr. Whoopee
457, // Golf Caddy
571, // Go-Kart
594, // RC Cam
568, // Bandito
463, // Freeway
461, // PCJ-600
468, // Sanchez
471, // Quadbike
510, // Mountain Bike
530, // Forklift
539 // Vortex Hovercraft
// Make sure the last entry doesn't have a comma! (All the other entries require a comma at the end.)
};
// This defines whether the player is allowed to pick any vehicle using their ID.
// Note 1: this only adds an extra option to the vehicle list called "Enter a specific model ID", the above list will still exist.
// Note 2: this allows the player to also spawn airplanes, helicopters or invalid vehicles like trailers!
// Default: false
#define ALLOW_ALL_VEHICLES false
// These values define the vehicle colors used on the model defined at RACE_VEHICLE_MODEL or the vehicle in the race.
// Default: -1 and -1
#define RACE_VEHICLE_COL1 -1
#define RACE_VEHICLE_COL2 -1
// --------------------------------------------------
// --- > --- > --- TECHNICAL SETTINGS --- < --- < ---
// --------------------------------------------------
// This is the PVar-tag that will be used for Player Variables.
// Note: this is used to prevent conflicts with other scripts and their variables.
// Default: "RRG_"
#define PVAR_TAG "RRG_"
// This number is the offset of the ID which will be used for dialogs.
// Note: use an unique number which doesn't come close to other IDs used in other scripts.
// Default: 1357
#define DIALOG_OFFSET 1357
// This is the offset, which will be used to create the suggested race checkpoints on the radar.
// Note 1: if this number is lower than 0 or higher than 99, the map icons might not show. (Limit of SA-MP 0.3x.)
// Note 2: the map icons IDs will start at this number. If you have 3 suggested icons (see MAX_SUGGESTED_MAPICONS), make sure this number isn't higher than 97 due to limits.
// Default: 80
#define SUGGESTED_MAPICONS_OFFSET 80
// ----------------------------------------------
// --- > --- > --- COLOR SETTINGS --- < --- < ---
// ----------------------------------------------
// This color is used for empty race slots in the race menu.
// Default: 0xFFFFFFFF (White)
#define COL_MENU_REGULAR 0xFFFFFFFF
// This color is shown when you move your mouse over a race slot in the race menu.
// Default: 0xDD8080FF (Indian/light red)
#define COL_MENU_MOUSEOVER 0xDD8080FF
// This color is used when you select one of the slots in the race menu.
// Default: 0xCF2C23FF (Firebrick/dark red)
#define COL_MENU_SELECTED 0xCF2C23FF
// This color is used for a race slot which can't be joined anymore.
// Default: 0x5B0000FF (Very dark red)
#define COL_MENU_STARTED 0x5B0000FF
// This is the color which is used for the regular chat text.
// Default: 0xFFFFFFFF (White)
#define COL_TEXT_REG 0xFFFFFFFF
#define COL_EMB_REG "{FFFFFF}"
// This is the color which is used for the winners chat text.
// Default: 0xFF3E3EFF (Just red)
#define COL_TEXT_WIN 0xFF2D2DFF
#define COL_EMB_WIN "{FF2D2D}"
// This is the color which is used for important chat, like notes and commands.
// Default: 0xFF3E3EFF (Just red)
#define COL_TEXT_IMPORTANT 0xFF6262FF
#define COL_EMB_IMPORTANT "{FF6262}"
// This is the color which is used for the chat errors.
// Default: 0xD21313FF (Firebrick/dark red)
#define COL_TEXT_ERROR 0xD21313FF // D21313
#define COL_EMB_ERROR "{D21313}"
// This color is used for the (radar) map icons which suggest the next checkpoints.
// Default: 0x5B0000FF (Very dark red)
#define COL_MAP_CP 0x5B0000FF
// -----------------------------------------------
// --- > --- > --- THE SOURCE CODE --- < --- < ---
// -----------------------------------------------
#if defined _samp_included
#define RRG_is_include
#else
#include <a_samp>
#endif
#if defined RRG_is_include
#if defined RRG_included
#endinput
#endif
#define RRG_included
#endif
#define RRG_VERSION "v1.2.1"
#include <RouteConnector>
#define REQUIRED_INC_VERSION (184)
#define REQUIRED_PLUGIN_VERSION (184)
#if (INCLUDE_VERSION < REQUIRED_INC_VERSION)
#error <Invalid include version> Please update RouteConnector.inc from the RouteConnector plugin!
#endif
#if defined MAX_RACES
#if !defined MAX_PUBLIC_RACES
#define MAX_PUBLIC_RACES MAX_RACES
#endif
#undef MAX_RACES
#endif
#define MAX_RACES MAX_PUBLIC_RACES + MAX_PRIVATE_RACES
enum eRaceInfo
{
rHost,
rVehicleModel,
rStarted,
rPlayerAmount,
rCPAmount,
rFinishedPlayers,
Float: rDistance,
rEndTimer
}
new raceInfo[MAX_RACES][eRaceInfo];
new racePeopleInRace[MAX_RACES][MAX_CONTESTANTS][2];
new Float: raceCheckpointList[MAX_RACES][MAX_CHECKPOINTS + 2][3];
new Text: raceMapIcons[MAX_RACES][MAX_TEXTDRAW_ICONS];
new amountOfPrivateRaces = 0;
new Text: joinMenuButtons[3] = {Text: INVALID_TEXT_DRAW, ...};
new Text: joinMenuSlots[MAX_RACES] = {Text: INVALID_TEXT_DRAW, ...};
new Text: joinMenuPrivate = Text: INVALID_TEXT_DRAW;
new Text: joinMenuRaceInfo[MAX_RACES][3];
new Text: joinMenuExtra[4] = {Text: INVALID_TEXT_DRAW, ...};
#define MENU_X 50.0
#define MENU_Y 145.0
#define MAX_VEHICLE_NAME 25
new const VehicleNames[][MAX_VEHICLE_NAME char] = {
!"Landstalker", !"Bravura", !"Buffalo", !"Linerunner", !"Perennial", !"Sentinel", !"Dumper", !"Firetruck", !"Trashmaster", !"Stretch", !"Manana", !"Infernus", !"Voodoo", !"Pony", !"Mule",
!"Cheetah", !"Ambulance", !"Leviathan", !"Moonbeam", !"Esperanto", !"Taxi", !"Washington", !"Bobcat", !"Mr Whoopee", !"BF Injection", !"Hunter", !"Premier", !"Enforcer", !"Securicar", !"Banshee",
!"Predator", !"Bus", !"Rhino", !"Barracks", !"Hotknife", !"Closed Trailer A", !"Previon", !"Coach", !"Cabbie", !"Stallion", !"Rumpo", !"RC Bandit", "Romero", !"Packer", !"Monster", !"Admiral",
!"Squalo", !"Seasparrow", !"Pizzaboy", !"Tram", !"Open Trailer", !"Turismo", !"Speeder", !"Reefer", !"Tropic", !"Flatbed", !"Yankee", !"Caddy", !"Solair", !"Berkley's RC Van", !"Skimmer",
!"PCJ-600", !"Faggio", !"Freeway", !"RC Baron", !"RC Raider", !"Glendale", !"Oceanic", !"Sanchez", !"Sparrow", !"Patriot", !"Quad", !"Coastguard", !"Dinghy", !"Hermes", !"Sabre",
!"Rustler", !"ZR-350", !"Walton", !"Regina", !"Comet", !"BMX", !"Burrito", !"Camper", !"Marquis", !"Baggage", !"Dozer", !"Maverick", !"News Chopper", !"Rancher", !"FBI Rancher",
!"Virgo", !"Greenwood", !"Jetmax", !"Hotring", !"Sandking", !"Blista Compact", !"Police Maverick", !"Boxville", !"Benson", !"Mesa", !"RC Goblin", !"Hotring Racer A", !"Hotring Racer B", !"Bloodring Banger",
!"Lure Rancher", !"Super GT", !"Elegant", !"Journey", !"Bike", !"Mountain Bike", !"Beagle", !"Cropdust", !"Stuntplane", !"Petrol Trailer", !"Roadtrain", !"Nebula", !"Majestic", !"Buccaneer", !"Shamal",
!"Hydra", !"FCR-900", !"NRG-500", !"HPV1000", !"Cement Truck", !"Tow Truck", !"Fortune", !"Cadrona", !"FBI Truck", !"Willard", !"Forklift", !"Tractor", !"Combine", !"Feltzer", !"Remington",
!"Slamvan", !"Blade", !"Freight", !"Brown Streak", !"Vortex", !"Vincent", !"Bullet", !"Clover", !"Sadler", !"Firetruck LA", !"Hustler", !"Intruder", !"Primo", !"Cargobob", !"Tampa", !"Sunrise",
!"Merit", !"Utility", !"Nevada", !"Yosemite", !"Windsor", !"Monster A", !"Monster B", !"Uranus", !"Jester", !"Sultan", !"Stratum", !"Elegy", !"Raindance", !"RC Tiger", !"Flash", !"Tahoma", !"Savanna",
!"Bandito", !"Freight Flat", !"Brown Streak Carriage", !"Kart", !"Mower", !"Duneride", !"Sweeper", !"Broadway", !"Tornado", !"AT-400", !"DFT-30", !"Huntley", !"Stafford", !"BF-400", !"Newsvan",
!"Tug", !"Petrol Trailer", !"Emperor", !"Wayfarer", !"Euros", !"Hotdog", !"Club", !"Freight Carriage", !"Closed Trailer B", !"Andromada", !"Dodo", !"RC Cam", !"Launch", !"LSPD Police", !"SFPD Police",
!"LVPD Police", !"Police Ranger", !"Picador", !"S.W.A.T. Van", !"Alpha", !"Phoenix", !"Ghost Glendale", !"Ghost Sadler", !"Baggage Trailer A", !"Baggage Trailer B", !"Stairs Trailer", !"Black Boxville",
!"Farm Plow", !"Utility Trailer"
};
new vehListStr[(sizeof(RaceVehicleList) + 1) * (MAX_VEHICLE_NAME + 2)];
#if defined RRG_is_include
public OnGameModeInit() return onScriptInit(), CallLocalFunction("RRG_OnGameModeInit", "");
public OnFilterScriptInit() return onScriptInit(), CallLocalFunction("RRG_OnFilterScriptInit", "");
public OnGameModeExit() return onScriptExit(), CallLocalFunction("RRG_OnGameModeExit", "");
public OnFilterScriptExit() return onScriptExit(), CallLocalFunction("RRG_OnFilterScriptInit", "");
#else
public OnGameModeInit() return onScriptInit();
public OnFilterScriptInit() return onScriptInit();
public OnGameModeExit() return onScriptExit();
public OnFilterScriptExit() return onScriptExit();
#endif
new bool: scriptLoaded = false;
main() {}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
onScriptInit()
{
// To prevent the script from loading the same stuff twice:
if (scriptLoaded == true) return 1;
scriptLoaded = true;
// Error checking with plugin or files
if (GetPluginVersion() < REQUIRED_PLUGIN_VERSION)
{
print("\n");
print(" [!] RRG Notice: the RouteConnector plugin is outdated. Please update it if you want to avoid problems!\n");
}
new GPSversion = GetGPSdatVersion();
if (GPSversion == -1 || GPSversion == 0)
{
print("\n");
print(" [!] RRG Notice: GPS.dat has not been found. Please update your RouteConnector plugin or load a file containing nodes!\n");
}
// TD - background
joinMenuExtra[0] = TextDrawCreate(MENU_X, MENU_Y, "_");
TextDrawUseBox(joinMenuExtra[0], true);
TextDrawLetterSize(joinMenuExtra[0], 1.0, 30.0);
TextDrawBoxColor(joinMenuExtra[0], 0x77);
TextDrawTextSize(joinMenuExtra[0], MENU_X + 540.0, MENU_Y + 255.0);
// TD - map
joinMenuExtra[1] = TextDrawCreate(MENU_X + 150.0, MENU_Y + 10.0, "samaps:map");
TextDrawFont(joinMenuExtra[1], 4);
TextDrawTextSize(joinMenuExtra[1], 250.0, 250.0);
// TD - title
joinMenuExtra[2] = TextDrawCreate(320.0, MENU_Y - 18.0, "Random Race Generator");
TextDrawFont(joinMenuExtra[2], 0);
TextDrawLetterSize(joinMenuExtra[2], 1.3, 3.5); // 1.0, 2.75
TextDrawSetOutline(joinMenuExtra[2], 2);
TextDrawAlignment(joinMenuExtra[2], 2);
// TD - description
joinMenuExtra[3] = TextDrawCreate(MENU_X + 410.0, MENU_Y + 19.0, \
"Welcome to the...~n~Random Race Generator!~n~~n~"\
"You can create or join a race by selecting one of the slots on the left.~n~~n~"\
"Each race is randomly generated along the roads of San Andreas; no race is the same as the last one.~n~~n~"\
"The map will show you the current race track of each slot and more information about each race will be shown in this box."\
" ______________________________ Have fun!");
TextDrawColor(joinMenuExtra[3], COL_MENU_REGULAR);
TextDrawTextSize(joinMenuExtra[3], MENU_X + 530.0, 500.0);
TextDrawLetterSize(joinMenuExtra[3], 0.25, 1.2);
TextDrawSetOutline(joinMenuExtra[3], 1);
// TD - buttons
joinMenuButtons[0] = TextDrawCreate(MENU_X + 10.0, MENU_Y + 245.0, " Create");
joinMenuButtons[1] = TextDrawCreate(MENU_X + 10.0, MENU_Y + 245.0, " Join");
joinMenuButtons[2] = TextDrawCreate(MENU_X + 80.0, MENU_Y + 245.0, " Close");
for (new b; b < sizeof(joinMenuButtons); b++) // same looks for all buttons
{
TextDrawColor(joinMenuButtons[b], COL_MENU_REGULAR);
TextDrawLetterSize(joinMenuButtons[b], 0.4, 1.5);
TextDrawSetOutline(joinMenuButtons[b], 1);
TextDrawUseBox(joinMenuButtons[b], true);
TextDrawBoxColor(joinMenuButtons[b], 0x55);
if (b == 2)
{
TextDrawTextSize(joinMenuButtons[b], MENU_X + 140.0, 12.0);
}
else
{
TextDrawTextSize(joinMenuButtons[b], MENU_X + 70.0, 12.0);
}
TextDrawSetSelectable(joinMenuButtons[b], true);
}
// TD - private race button
joinMenuPrivate = TextDrawCreate(MENU_X + 10.0, MENU_Y + 19.0 + float(MAX_PUBLIC_RACES * 15), "<0/"#MAX_PRIVATE_RACES"> Create private race!");
TextDrawColor(joinMenuPrivate, COL_MENU_REGULAR);
TextDrawLetterSize(joinMenuPrivate, 0.25, 1.2);
TextDrawSetOutline(joinMenuPrivate, 1);
TextDrawTextSize(joinMenuPrivate, MENU_X + 155.0, 12.0);
TextDrawSetSelectable(joinMenuPrivate, true);
// TD - public race buttons
for (new s; s < MAX_RACES; s++)
{
if (s < MAX_PUBLIC_RACES)
{
joinMenuSlots[s] = TextDrawCreate(MENU_X + 10.0, MENU_Y + 19.0 + float(s * 15), "<Empty> Create a race!");
TextDrawColor(joinMenuSlots[s], COL_MENU_REGULAR);
TextDrawLetterSize(joinMenuSlots[s], 0.25, 1.2);
TextDrawSetOutline(joinMenuSlots[s], 1);
TextDrawTextSize(joinMenuSlots[s], MENU_X + 155.0, 12.0);
TextDrawSetSelectable(joinMenuSlots[s], true);
}
else
{
joinMenuSlots[s] = Text: INVALID_TEXT_DRAW;
}
raceInfo[s][rHost] = INVALID_PLAYER_ID;
raceInfo[s][rEndTimer] = -1;
for (new p; p < MAX_CONTESTANTS; p++)
{
racePeopleInRace[s][p][0] = INVALID_PLAYER_ID;
}
for (new t; t < sizeof(joinMenuRaceInfo[]); t++)
{
joinMenuRaceInfo[s][t] = Text: INVALID_TEXT_DRAW;
}
for (new i; i < MAX_TEXTDRAW_ICONS; i++)
{
raceMapIcons[s][i] = Text: INVALID_TEXT_DRAW;
}
}
// Dialog - race vehicles list
for (new v; v < sizeof(RaceVehicleList); v++)
{
strcat(vehListStr, VehicleNames[RaceVehicleList[v] - 400]);
strcat(vehListStr, "\n");
}
#if ALLOW_ALL_VEHICLES == true
strcat(vehListStr, "Enter a specific model ID");
#endif
// Loading finished
print("\n");
#if defined RRG_is_include
print("Random Race Generator "RRG_VERSION" loaded succesfully. (include version)\n");
#else
print("Random Race Generator "RRG_VERSION" loaded succesfully.\n");
#endif
return 1;
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
onScriptExit()
{
scriptLoaded = false;
// Destroy all the textdraws:
for (new b; b < sizeof(joinMenuButtons); b++)
{
TextDrawHideForAll(joinMenuButtons[b]);
TextDrawDestroy(joinMenuButtons[b]);
}
for (new e; e < sizeof(joinMenuExtra); e++)
{
TextDrawHideForAll(joinMenuExtra[e]);
TextDrawDestroy(joinMenuExtra[e]);
}
for (new s; s < MAX_RACES; s++)
{
cleanRace(s);
TextDrawHideForAll(joinMenuSlots[s]);
TextDrawDestroy(joinMenuSlots[s]);
for (new r; r < sizeof(joinMenuRaceInfo[]); r++)
{
TextDrawHideForAll(joinMenuRaceInfo[s][r]);
TextDrawDestroy(joinMenuRaceInfo[s][r]);
}
for (new i; i < MAX_TEXTDRAW_ICONS; i++)
{
if (raceMapIcons[s][i] != Text: INVALID_TEXT_DRAW)
{
TextDrawHideForAll(raceMapIcons[s][i]);
TextDrawDestroy(raceMapIcons[s][i]);
raceMapIcons[s][i] = Text: INVALID_TEXT_DRAW;
}
}
}
for (new p, m = GetPlayerPoolSize(); p < m; p++)
{
removeText(p);
DeletePVar(p, PVAR_TAG"exitVehTimer");
}
return 1;
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public OnPlayerSpawn(playerid)
{
// Respawn the player after they've died:
new race = GetPVarInt(playerid, PVAR_TAG"currentRaceID");
if (race)
{
race -= 2;
if (raceInfo[race][rHost] != INVALID_PLAYER_ID)
{
respawnPlayer(playerid, race);
}
}
#if defined RRG_is_include
return CallLocalFunction("RRG_OnPlayerSpawn", "i", playerid);
#else
return 1;
#endif
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public OnPlayerDisconnect(playerid, reason)
{
// Message everyone that the race has been canceled:
new race = GetPVarInt(playerid, PVAR_TAG"currentRaceID");
if (race)
{
race -= 2;
if (raceInfo[race][rHost] == playerid)
{
for (new p; p < MAX_CONTESTANTS; p++)
{
if (racePeopleInRace[race][p][0] != INVALID_PLAYER_ID && racePeopleInRace[race][p][0] != playerid)
{
SendClientMessage(racePeopleInRace[race][p][0], COL_TEXT_IMPORTANT, " [!] NOTE: "COL_EMB_REG"The race you had participated in has been called off.");
}
}
}
}
// Remove player from race and cancel race if necessary:
#if REMEMBER_OLD_POSITION == true
removePlayerFromRace(playerid, false);
#else
removePlayerFromRace(playerid);
#endif
#if defined RRG_is_include
return CallLocalFunction("RRG_OnPlayerDisconnect", "ii", playerid, reason);
#else
return 1;
#endif
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public OnVehicleDeath(vehicleid, killerid)
{
// Check if vehicle was a race vehicle
for (new p, mp = GetPlayerPoolSize(); p < mp; p++)
{
if (IsPlayerConnected(p) && !IsPlayerNPC(p))
{
new race = GetPVarInt(p, PVAR_TAG"currentRaceID");
if (race)
{
race -= 2;
if (raceInfo[race][rHost] != INVALID_PLAYER_ID)
{
if (GetPVarInt(p, PVAR_TAG"currentVehID") == vehicleid)
{
new Float: health;
GetPlayerHealth(p, health);
if (health > 0)
{
respawnPlayer(p, race);
}
break;
}
}
}
}
}
#if defined RRG_is_include
return CallLocalFunction("RRG_OnVehicleDeath", "ii", vehicleid, killerid);
#else
return 1;
#endif
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#if !defined RRG_DisableCommands
public OnPlayerCommandText(playerid, cmdtext[])
{
// First: check if one of the RRG-commands is typed.
if (!strcmp(cmdtext, "/rrg", true, 4))
{
new subcmd[32];
strmid(subcmd, cmdtext, 5, cellmax);
if (cmdtext[4] == ' ' && subcmd[0])
{
// This command shows the join menu with the map.
if (!strcmp(subcmd, "menu", true) || !strcmp(subcmd, "join", true))
{
showJoinMenuForPlayer(playerid);
return 1;
}
// This command allows the player to respawn during the race.
if (!strcmp(cmdtext[5], "respawn", true))
{
new race = GetPVarInt(playerid, PVAR_TAG"currentRaceID");
if (race)
{
race -= 2;
if (raceInfo[race][rStarted] != 2)
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You cannot respawn right now! The race has not started yet.");
}
if (GetPVarInt(playerid, PVAR_TAG"isFinished"))
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You cannot respawn anymore! You have already finished.");
}
respawnPlayer(playerid, race);
}
else
{
SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You are not om a race right now!");
}
return 1;
}
// This command allows the player to leave a race
if (!strcmp(subcmd, "leave", true))
{
new race = GetPVarInt(playerid, PVAR_TAG"currentRaceID");
if (race && raceInfo[race - 2][rHost] == playerid) // If the player is host
{
race -= 2;
if (removePlayerFromRace(playerid) == 1) // Race has been ended and no host was found
{
SendClientMessage(playerid, COL_TEXT_IMPORTANT, " [!] NOTE: "COL_EMB_REG"You have called off the race.");
for (new p; p < MAX_CONTESTANTS; p++)
{
if (racePeopleInRace[race][p][0] != INVALID_PLAYER_ID && racePeopleInRace[race][p][0] != raceInfo[race][rHost])
{
SendClientMessage(racePeopleInRace[race][p][0], COL_TEXT_IMPORTANT, " [!] NOTE: "COL_EMB_REG"The race you are participating in has been called off.");
}
}
}
}
else // If the player is a contestant (not the host)
{
if (race)
{
SendClientMessage(playerid, COL_TEXT_IMPORTANT, " [!] NOTE: "COL_EMB_REG"You have left the race.");
}
else
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You are currently not in a race.");
}
removePlayerFromRace(playerid);
}
return 1;
}
// This allows people to invite other players (especially useful for private races)
if (!strcmp(subcmd, "invite", true, 6))
{
new race = GetPVarInt(playerid, PVAR_TAG"currentRaceID");
if (!race)
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You are currently not in a race.");
}
race -= 2;
if (subcmd[6] != ' ' || !subcmd[7])
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: Correct usage: '/rrg invite [name]'.");
}
new invitename[MAX_PLAYER_NAME + 2];
strmid(invitename, subcmd, 7, cellmax);
// Search for a player with the given name
new lastplayer = INVALID_PLAYER_ID, amountfound;
for (new p, m = GetPlayerPoolSize(); p < m; p++)
{
if (IsPlayerConnected(p) && !IsPlayerNPC(p))
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(p, pName, MAX_PLAYER_NAME);
if (strfind(pName, invitename, true) != -1)
{
amountfound++;
if (amountfound == 1)
{
lastplayer = p;
}
}
}
}
switch (amountfound)
{
case 0: // No players were found with the given name.
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: No player in this server matches the given name.");
}
case 1: // One player was found with the given name, thus try to send an invite.
{
if (playerid == lastplayer)
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You cannot invite yourself.");
}
// Already invited?
new curinvite = GetPVarInt(lastplayer, PVAR_TAG"currentInviteID");
if (curinvite)
{
curinvite--;
if (GetPVarInt(lastplayer, PVAR_TAG"currentInviteTime") >= gettime())
{
if (curinvite == playerid)
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You have already invited the given player.");
}
else
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: The given player has already received another invite.");
}
}
}
// Already racing?
new otherrace = GetPVarInt(lastplayer, PVAR_TAG"currentRaceID");
if (otherrace)
{
otherrace -= 2;
if (otherrace == race)
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: The given player is already in this race.");
}
else
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: The given player is already in another race.");
}
}
// Send invite!
new str[128], pName[MAX_PLAYER_NAME], len;
len = GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
if (raceInfo[race][rHost] == playerid)
{
switch (pName[len - 1])
{
case 's', 'z', 'S', 'Z': format(str, sizeof(str), " [!] NOTE: "COL_EMB_REG"You have been invited to join %s' race.", pName);
default: format(str, sizeof(str), " [!] NOTE: "COL_EMB_REG"You have been invited to join %s's race.", pName);
}
}
else
{
new hName[MAX_PLAYER_NAME];
len = GetPlayerName(raceInfo[race][rHost], hName, MAX_PLAYER_NAME);
switch (pName[len - 1])
{
case 's', 'z', 'S', 'Z': format(str, sizeof(str), " [!] NOTE: "COL_EMB_REG"You have been invited by %s to join %s' race.", pName, hName);
default: format(str, sizeof(str), " [!] NOTE: "COL_EMB_REG"You have been invited by %s to join %s's race. ", pName, hName);
}
}
SendClientMessage(lastplayer, COL_TEXT_ERROR, str);
SendClientMessage(lastplayer, COL_TEXT_IMPORTANT, " [!] NOTE: "COL_EMB_REG"Use '"COL_EMB_IMPORTANT"/rrg showinvite"COL_EMB_REG"' to accept or decline it. The invite will expire in "#INVITE_EXPIRE" seconds.");
SetPVarInt(lastplayer, PVAR_TAG"currentInviteID", playerid + 1);
SetPVarInt(lastplayer, PVAR_TAG"currentInviteTime", gettime() + INVITE_EXPIRE);
GetPlayerName(lastplayer, pName, MAX_PLAYER_NAME);
format(str, sizeof(str), " [!] NOTE: "COL_EMB_REG"You have invited %s to join your race.", pName);
SendClientMessage(playerid, COL_TEXT_IMPORTANT, str);
}
default: // More than one player was found with the given name
{
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: More than one player in this server matches the given name. Be more specific!");
}
}
return 1;
}
// Shows an invite to the player if he or she received one.
if (!strcmp(subcmd, "showinvite", true))
{
new invitetime = GetPVarInt(playerid, PVAR_TAG"currentInviteTime"), invitingplayer = GetPVarInt(playerid, PVAR_TAG"currentInviteID");
if (invitetime >= gettime())
{
if (invitingplayer)
{
invitingplayer--;
new race = GetPVarInt(invitingplayer, PVAR_TAG"currentRaceID");
if (!race)
{
DeletePVar(playerid, PVAR_TAG"currentInviteID");
DeletePVar(playerid, PVAR_TAG"currentInviteTime");
SendClientMessage(playerid, COL_TEXT_REG, " [!] ERROR: The invite you received is not valid anymore. Invite has been removed.");
return 1;
}
race -= 2;
new dialogTitle[MAX_PLAYER_NAME + 24], dialogStr[255], pName[MAX_PLAYER_NAME], len, vehicleName[MAX_VEHICLE_NAME];
len = GetPlayerName(invitingplayer, pName, MAX_PLAYER_NAME);
format(dialogTitle, sizeof(dialogTitle), "{FFFFFF}Invite from %s", pName);
if (raceInfo[race][rVehicleModel])
{
strunpack(vehicleName, VehicleNames[raceInfo[race][rVehicleModel] - 400]);
}
else
{
DeletePVar(playerid, PVAR_TAG"currentInviteID");
DeletePVar(playerid, PVAR_TAG"currentInviteTime");
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: An error occured while showing invite. (Reference ID: 011) Race vehicle model could not be found.");
}
// Make dialog text based on if the inviting player is the host of the race or not.
if (raceInfo[race][rHost] == invitingplayer)
{
switch (pName[len - 1])
{
case 's', 'z', 'S', 'Z':
{
format(dialogStr, sizeof(dialogStr),\
"{FFFFFF}You have been invited to join %s' race.\n\n{CF2C23}Vehicle:{FFFFFF} %s\n{CF2C23}Length:{FFFFFF} %.1f meters\n{CF2C23}Checkpoints{FFFFFF}: %i\n{CF2C23}Host:{FFFFFF} %s\n\nDo you want to accept or decline this invite?",\
pName, vehicleName, raceInfo[race][rDistance], raceInfo[race][rCPAmount], pName);
}
default:
{
format(dialogStr, sizeof(dialogStr),\
"{FFFFFF}You have been invited to join %s's race.\n\n{CF2C23}Vehicle:{FFFFFF} %s\n{CF2C23}Length:{FFFFFF} %.1f meters\n{CF2C23}Checkpoints{FFFFFF}: %i\n{CF2C23}Host:{FFFFFF} %s\n\nDo you want to accept or decline this invite?",\
pName, vehicleName, raceInfo[race][rDistance], raceInfo[race][rCPAmount], pName);
}
}
}
else
{
new hName[MAX_PLAYER_NAME];
len = GetPlayerName(raceInfo[race][rHost], hName, MAX_PLAYER_NAME);
switch (hName[len - 1])
{
case 's', 'z', 'S', 'Z':
{
format(dialogStr, sizeof(dialogStr),\
"{FFFFFF}You have been invited by %s to join %s' race.\n\n{CF2C23}Vehicle:{FFFFFF} %s\n{CF2C23}Length:{FFFFFF} %.1f meters\n{CF2C23}Checkpoints:{FFFFFF} %i\n{CF2C23}Host:{FFFFFF} %s\n\nDo you want to accept or decline this invite?",\
pName, hName, vehicleName, raceInfo[race][rDistance], raceInfo[race][rCPAmount], hName);
}
default:
{
format(dialogStr, sizeof(dialogStr),\
"{FFFFFF}You have been invited by %s to join %s's race.\n\n{CF2C23}Vehicle:{FFFFFF} %s\n{CF2C23}Length:{FFFFFF} %.1f meters\n{CF2C23}Checkpoints:{FFFFFF} %i\n{CF2C23}Host:{FFFFFF} %s\n\nDo you want to accept or decline this invite?",\
pName, hName, vehicleName, raceInfo[race][rDistance], raceInfo[race][rCPAmount], hName);
}
}
}
SetPVarInt(playerid, PVAR_TAG"currentInviteTime", cellmax);
ShowPlayerDialog(playerid, DIALOG_OFFSET + 3, 0, dialogTitle, dialogStr, "Accept", "Decline");
}
else
{
DeletePVar(playerid, PVAR_TAG"currentInviteID");
DeletePVar(playerid, PVAR_TAG"currentInviteTime");
return SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: An error occured while showing invite. (Reference ID: 010) The inviting player ID could not be found.");
}
}
else // If the invite has expired
{
if (invitetime && invitingplayer)
{
DeletePVar(playerid, PVAR_TAG"currentInviteID");
DeletePVar(playerid, PVAR_TAG"currentInviteTime");
new str[128], pName[MAX_PLAYER_NAME];
GetPlayerName(invitingplayer - 1, pName, MAX_PLAYER_NAME);
format(str, sizeof(str), " [!] ERROR: The invite you received from %s has expired.", pName);
SendClientMessage(playerid, COL_TEXT_ERROR, str);
}
else
{
SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You do not have an invite to show.");
}
}
return 1;
}
// This command allows the host to start a race
if (!strcmp(subcmd, "start", true))
{
new race = GetPVarInt(playerid, PVAR_TAG"currentRaceID");
if (!race)
{
SendClientMessage(playerid, COL_TEXT_ERROR, " [!] ERROR: You have not created a race yet.");
return 1;