summaryrefslogtreecommitdiff
path: root/npc/003-3/malindou.txt
blob: e18d048fe1d2e6c8494dc8fea4b55c9eb06914d5 (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
// TMW-2 Script.
// Author:
//    Saulc
//    Jesusalva
// Notes:
//    Tulim banker, and also handles PCLogin events: CheckClientVersion, and bank
//    Take care of server updates, but instances are defined on their ships.

003-3,36,34,0	script	Malindou	NPC_LLOYD,{
    Banker(.name$, "Tulimshar", 9000);
    close;

OnInit:
    .sex = G_MALE;
    .distance = 4;

    // Update handler (use `date +%s` for this)
    // Current UPDATE value: Qui Jun  7 08:10:55 -03 2018
    if ($UPDATE  < 1528369855) {
        $UPDATE=1528369855;
        debugmes "Warning.";
        debugmes "Warning.";
        debugmes "Warning: This introduces a server update:";
        debugmes "";
        debugmes "* Automatic variable setup";
        debugmes "";
        $HASAN_GP=2000;
        $MANA_BINT=10;
        $MANA_BLVL=40;
        $MANA_JLVL=20;
        $VAULT_01738039=25;
        $TULIM_MAYOR$="Jesus Saves";
        $TULIM_TAX=100;
        $TULIM_EXPORT=5000;
        $TULIM_REPUTATION=50;
        $HALIN_MAYOR$="Jesus Saves";
        $HALIN_TAX=100;
        $HALIN_EXPORT=2000;
        $HALIN_REPUTATION=50;
        $HURNS_MAYOR$="Jesus Saves";
        $HURNS_TAX=100;
        $HURNS_EXPORT=3000;
        $HURNS_REPUTATION=50;
        $LOF_MAYOR$="Jesus Saves";
        $LOF_TAX=100;
        $LOF_EXPORT=4000;
        $LOF_REPUTATION=50;
        $NIVAL_MAYOR$="Jesus Saves";
        $NIVAL_TAX=100;
        $NIVAL_EXPORT=3000;
        $NIVAL_REPUTATION=50;
        $FROSTIA_MAYOR$="Jesus Saves";
        $FROSTIA_TAX=100;
        $FROSTIA_EXPORT=3000;
        $FROSTIA_REPUTATION=50;
        $CANDOR_MAYOR$="Jesus Saves";
        $CANDOR_TAX=1000;
        $CANDOR_EXPORT=0;
        $CANDOR_REPUTATION=100;
		$BCONFN_SPAWN = 70;
		$BCONFD_SPAWN = 100;
		$BCONFN_MOBHP = 100;
		$BCONFD_MOBHP = 90;
		$BCONFB_EXPR = 100;
		$BCONFN_EXPR = 5;
		$BCONFD_EXPR = 0;
		$BCONFB_DROP = 100;
		$BCONFN_DROP = 7;
		$BCONFD_DROP = 0;
		$BETASERVER = false;
		$AUTORESTART = false;
		$REFERRAL_ENABLED = false;
		//$NO_INTRO = false;
		//$HARDCORE = false;
		$CAPTCHA = 3; // Banhammer + Advance Warning (TMW Classic style)
		//$CAPTCHA = 28; // Syndrome + NoEvents + @treat (ML style)
		$ALLIANCE_TAX1 = 7500;
		$ALLIANCE_TAX2 = 60;
        $FIRESOFSTEAM[1] = 2000;
        $FIRESOFSTEAM[2] = 2000;
        $FIRESOFSTEAM[3] = 2000;
        $FIRESOFSTEAM[4] = 2000;
        $FIRESOFSTEAM[5] = 2000;
    }
    /*
    // Current UPDATE value: Dom Jun 17 21:32:45 -03 2018
    if ($UPDATE < 1529281965) {
        $UPDATE=1529281965;
        debugmes "";
        debugmes "* Please set #BankP for bankers";
        debugmes "* Automatically creatining minimal GP reserves for Hasan Autumn's Quest";
        debugmes "";
        $HASAN_GP=rand(3,12)+rand(3,12)+rand(3,12);
    }
    // Current UPDATE value: Dom Jun 30 22:44:46 -03 2018
    if ($UPDATE < 1530409486) {
        $UPDATE=1530409486;
        debugmes "";
        debugmes "* Clearing invalid (deleted) items";
        debugmes "";
        DelItemFromEveryPlayer(729);
    }
    // Current UPDATE value: Qui Jul 12 02:40:02 -03 2018
    if ($UPDATE < 1531374002) {
        $UPDATE=1531374002;
        debugmes "";
        debugmes "* WARNING! WARNING! WARNING!";
        debugmes "* ITEM ID VIOLATION DETECTED!";
        debugmes "";
        debugmes "* ALL POLISHED EMERALDS BECOME POLISHED AMETHYSTS, AND VICE-VERSA!";
        debugmes "* This should not have an effect ingame.";
        debugmes "";
    }
    // Current UPDATE value: Qui Ago  2 13:58:17 -03 2018
    if ($UPDATE < 1533229097) {
        $UPDATE=1533229097;
        debugmes "";
        debugmes "* ERASING all victories with Fafi Dragon";
        debugmes "";
        query_sql("UPDATE `quest` SET `count1` = '1' WHERE `quest`.`quest_id`="+LoFQuest_Fairy+" AND `count1` = '2'");
        query_sql("UPDATE `quest` SET `count1` = '2' WHERE `quest`.`quest_id`="+LoFQuest_Fairy+" AND `count1` = '3'");
        DelItemFromEveryPlayer(SkullMask);
    }
    // Current UPDATE value: Qua Ago  8 11:04:10 -03 2018
    if ($UPDATE < 1533737050) {
        $UPDATE=1533737050;
        debugmes "";
        debugmes "* REMOVING now rare items.";
        debugmes "";
        DelItemFromEveryPlayer(SilverMirror);
    }
    // Current UPDATE value: Seg Ago 27 20:20:21 -03 2018
    if ($UPDATE < 1535412021) {
        $UPDATE=1535412021;
        debugmes "";
        debugmes "* SETUP mana stone default values.";
        debugmes "";
        $MANA_BINT=30;
        $MANA_BLVL=30;
        $MANA_JLVL=15;
    }
    // Current UPDATE value: Qui Set 06 13:50:37 -03 2018
    if ($UPDATE < 1536252637) {
        $UPDATE=1536252637;
        debugmes "";
        debugmes "* Clearing invalid (deleted) items";
        debugmes "* Initial Vault Values";
        debugmes "";
        DelItemFromEveryPlayer(802);
        DelItemFromEveryPlayer(557);
        $VAULT_01738039=rand(5,25);
    }
    // Current UPDATE value: Qui Set 13 14:17:50 -03 2018
    if ($UPDATE < 1536859070) {
        $UPDATE=1536859070;
        debugmes "";
        debugmes "* Aisen already have a completed node at PETMEMO.";
        debugmes "* This was handled automatically, no special care is required.";
        debugmes "";
    }
    // Current UPDATE value: Dom Set 16 22:21:05 -03 2018
    if ($UPDATE < 1537147265) {
        $UPDATE=1537147265;
        debugmes "";
        debugmes "* My Money quest state modified";
        debugmes "* Foxhound Famine quest state modified";
        debugmes "* Life Delight quest state modified"; // “A True Chef” is the LoF version of this quest
        debugmes "";
        query_sql("UPDATE `quest` SET `count1` = '1' WHERE `quest`.`quest_id`="+ShipQuests_ArpanMoney+" AND `count1` = '2'");
        query_sql("UPDATE `quest` SET `count2` = `count1` WHERE `quest`.`quest_id`="+HalinarzoQuest_Foxhound+" AND `count1` >= '6'");
        query_sql("UPDATE `quest` SET `count1` = '6' WHERE `quest`.`quest_id`="+HalinarzoQuest_Foxhound+" AND `count1` > '6'");
        query_sql("UPDATE `quest` SET `count2` = `count1` WHERE `quest`.`quest_id`="+HalinarzoQuest_LifeDelight);
        query_sql("UPDATE `quest` SET `count1` = '1' WHERE `quest`.`quest_id`="+HalinarzoQuest_LifeDelight+" AND `count1` > '1'");
    }
    // Current UPDATE value: Seg Set 17 16:02:27 -03 2018
    if ($UPDATE < 1537210947) {
        $UPDATE=1537210947;
        debugmes "";
        debugmes "* Referral Hack System";
        debugmes "";
        setarray $REFERRAL_IDS, 0;
    }
    // Current UPDATE value: Ter Out 16 17:17:20 -03 2018
    // This is a hack because I'm too lazy to be bothered with standard SQL Upgrade system
    if ($UPDATE < 1539721040) {
        query_sql("CREATE TABLE IF NOT EXISTS `discord` (`account_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',`discord_id` VARCHAR(255) NOT NULL DEFAULT '',`discord_name` VARCHAR(255) NOT NULL DEFAULT '',`verified` ENUM('0', '1') NOT NULL DEFAULT '0') ENGINE=MyISAM");
        $UPDATE=1539721040;
        //$NIVALIS_LIBDATE=1539721040;
        debugmes "";
        debugmes "* SQL Upgrade (no effect on new installations)";
        //debugmes "* Nivalis Liberation Day event skipped";
        debugmes "";
    }
    // Current UPDATE value: Dom Nov 18 17:40:30 -02 2018
    // Update players position
    if ($UPDATE < 1542570030) {
        query_sql("UPDATE `char` SET `last_x` = '35' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `char` SET `last_y` = '102' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `char` SET `save_x` = '35' WHERE `char`.`save_map`='005-1'");
        query_sql("UPDATE `char` SET `save_y` = '102' WHERE `char`.`save_map`='005-1'");
        $UPDATE=1542570030;
        debugmes "";
        debugmes "* Update Candor players position";
        debugmes "";
    }
    // Current UPDATE value: Sab Dez 15 21:45:15 -02 2018
    // Upgrade every Wooden Sword in a Bug Slayer
    if ($UPDATE < 1544917515) {
        ReplaceItemFromEveryPlayer(WoodenSword, BugSlayer);
        $UPDATE=1544917515;
        debugmes "";
        debugmes "* Replaced Wooden Swords with Bug Slayer";
        debugmes "";
    }
    // Current UPDATE value: Sab Dez 17 13:52:54 -02 2018
    // Fix a critical bug because Nard's ship doors logic was changed. Upgrade premium weapons in rare weapons
    if ($UPDATE < 1545061974) {
        //query_sql("UPDATE `quest` SET `count1` = '3' WHERE `quest`.`quest_id`='0' AND `quest`.`count1` = '2' AND `quest`.`char_id` IN (SELECT `quest`.`char_id` WHERE  `quest`.`quest_id` = '12' AND  `quest`.`count1`>='1')");

        ReplaceItemFromEveryPlayer(MiereCleaver, LEGACY_MiereCleaver);
        ReplaceItemFromEveryPlayer(Broadsword, LEGACY_Broadsword);
        $UPDATE=1545061974;
        debugmes "";
        debugmes "* Replaced Miere Cleaver and Broad Sword with a special version specific for old players";
        debugmes "* Fix critical bug with Nard (not needed on Main Server)";
        debugmes "";
    }
    // Current UPDATE value: Qua Dez 26 21:45:10 -02 2018
    // Update item id
    if ($UPDATE < 1545867910) {
        ReplaceItemFromEveryPlayer(6000, 9990);
        ReplaceItemFromEveryPlayer(6001, 9991);
        ReplaceItemFromEveryPlayer(6004, 9994);
        ReplaceItemFromEveryPlayer(6005, 9995);

        ReplaceItemFromEveryPlayer(9990, 6001);
        ReplaceItemFromEveryPlayer(9991, 6000);
        ReplaceItemFromEveryPlayer(9994, 6005);
        ReplaceItemFromEveryPlayer(9995, 6004);

        $UPDATE=1545867910;
        debugmes "";
        debugmes "* Update Bows IDs";
        debugmes "";
    }
    // Current UPDATE value: Seg Dez 31 11:45:35 -02 2018
    // Update players position (002-x). Update Peter Quest. Update Main quest.
    if ($UPDATE < 1546263935) {
        query_sql("UPDATE `char` SET `last_x` = '53' WHERE `char`.`last_map`='002-1'");
        query_sql("UPDATE `char` SET `last_y` = '38' WHERE `char`.`last_map`='002-1'");
        query_sql("UPDATE `char` SET `last_x` = '53' WHERE `char`.`last_map`='002-3'");
        query_sql("UPDATE `char` SET `last_y` = '38' WHERE `char`.`last_map`='002-3'");
        query_sql("UPDATE `char` SET `last_x` = '53' WHERE `char`.`last_map`='002-4'");
        query_sql("UPDATE `char` SET `last_y` = '38' WHERE `char`.`last_map`='002-4'");

        query_sql("UPDATE `quest` SET `count1` = '2' WHERE `quest`.`quest_id`="+ShipQuests_Peter+" AND `count1` >= '3'");
        query_sql("UPDATE `quest` SET `count1` = '1' WHERE `quest`.`quest_id`="+General_Narrator+" AND `count1` >= '2'");
        $UPDATE=1546263935;
        debugmes "";
        debugmes "* Update players position (Nard's Ship)";
        debugmes "* Update Peter Quest";
        debugmes "";
    }
    // Current UPDATE value: Ter Jan 8 11:14:04 -02 2019
    // Update arrow IDs
    if ($UPDATE < 1546953244) {
        ReplaceItemFromEveryPlayer(CursedArrow, 9990);
        ReplaceItemFromEveryPlayer(IronArrow, 9991);
        ReplaceItemFromEveryPlayer(9990, IronArrow);
        ReplaceItemFromEveryPlayer(9991, CursedArrow);

        // Maybe we should make Tolchi Arrow greater than Training Arrow?

        // PlatinumQuiver - DragonStar - MichelSoul
        // Terranite Quiver was broken in two, they'll keep the weaker version
        ReplaceItemFromEveryPlayer(1174, 9991);
        ReplaceItemFromEveryPlayer(1175, 9992);
        ReplaceItemFromEveryPlayer(1176, 9993);

        ReplaceItemFromEveryPlayer(9991, 1175);
        ReplaceItemFromEveryPlayer(9992, 1176);
        ReplaceItemFromEveryPlayer(9993, 1177);

        $UPDATE=1546953244;
        debugmes "";
        debugmes "* Update Arrows IDs";
        debugmes "* Update Quiver IDs";
        debugmes "";
    }
    // Current UPDATE value: Ter Jan 15 02:07:40 -02 2019
    // Reset all thief/merc ranks back to 1.
    // If
    if ($UPDATE < 1547525260) {

        // Already rank 2? Give enough exp to get rank 2 easily.
        query_sql("UPDATE `char_reg_num_db` SET `value` = '30' WHERE `char_reg_num_db`.`key`='THIEF_EXP' AND `char_reg_num_db`.`char_id` IN (SELECT `char_reg_num_db`.`char_id` WHERE `char_reg_num_db`.`key` = 'THIEF_RANK' AND  `char_reg_num_db`.`value`>='2')");
        // Didn't wanted to rank up? Reset exp to 30!
        query_sql("UPDATE `char_reg_num_db` SET `value` = '30' WHERE `char_reg_num_db`.`key`='THIEF_EXP' AND `char_reg_num_db`.`value` >= '32' AND `char_reg_num_db`.`char_id` IN (SELECT `char_reg_num_db`.`char_id` WHERE `char_reg_num_db`.`key` = 'THIEF_RANK' AND  `char_reg_num_db`.`value`<='1')");
        // Already rank 2? Return to rank 1.
        query_sql("UPDATE `char_reg_num_db` SET `value` = '1' WHERE `char_reg_num_db`.`key`='THIEF_RANK' AND `char_reg_num_db`.`value` >= '2'");

        // The same thing, now for merchants

        // Already rank 2? Give enough exp to get rank 2 easily.
        query_sql("UPDATE `char_reg_num_db` SET `value` = '30' WHERE `char_reg_num_db`.`key`='MERC_EXP' AND `char_reg_num_db`.`char_id` IN (SELECT `char_reg_num_db`.`char_id` WHERE `char_reg_num_db`.`key` = 'MERC_RANK' AND  `char_reg_num_db`.`value`>='2')");
        // Didn't wanted to rank up? Reset exp to 30!
        query_sql("UPDATE `char_reg_num_db` SET `value` = '30' WHERE `char_reg_num_db`.`key`='MERC_EXP' AND `char_reg_num_db`.`value` >= '32' AND `char_reg_num_db`.`char_id` IN (SELECT `char_reg_num_db`.`char_id` WHERE `char_reg_num_db`.`key` = 'MERC_RANK' AND  `char_reg_num_db`.`value`<='1')");
        // Already rank 2? Return to rank 1.
        query_sql("UPDATE `char_reg_num_db` SET `value` = '1' WHERE `char_reg_num_db`.`key`='MERC_RANK' AND `char_reg_num_db`.`value` >= '2'");

        $UPDATE=1547525260;
        debugmes "";
        debugmes "* Merc/Thief ranks reset to 1";
        debugmes "Improving past rank 2 helps on minigame";
        debugmes "";
    }
    // Current UPDATE value: Qui Fev 28 19:42:12 -03 2019
    // Late fix for Nard Ship Bug
    if ($UPDATE < 1551393732) {
        query_sql("UPDATE `quest` SET `count1` = '3' WHERE `quest`.`quest_id`="+ShipQuests_Julia+" AND `count1` <= '2'");
        $UPDATE=1551393732;
        debugmes "";
        debugmes "* Late fix for Nard Ship Bug";
        debugmes "";
    }
    // Current UPDATE value: Qui Mar  7 23:15:54 -03 2019
    // Map Update
    if ($UPDATE < 1552011354) {
        query_sql("UPDATE `char` SET `last_x` = '22' WHERE `char`.`last_map`='014-3'");
        query_sql("UPDATE `char` SET `last_y` = '22' WHERE `char`.`last_map`='014-3'");
        query_sql("UPDATE `char` SET `last_map` = '000-1' WHERE `char`.`last_map`='014-3'");

        query_sql("UPDATE `char` SET `last_x` = '22' WHERE `char`.`last_map`='003-1'");
        query_sql("UPDATE `char` SET `last_y` = '22' WHERE `char`.`last_map`='003-1'");
        query_sql("UPDATE `char` SET `last_map` = '000-1' WHERE `char`.`last_map`='003-1'");
        $UPDATE=1552011354;
        debugmes "";
        debugmes "* Map Updates";
        debugmes "";
    }
    // Current UPDATE value: Sáb Mar 23 11:11:32 -03 2019
    // Soul Menhir savepoint replaced
    if ($UPDATE < 1553350292) {
        query_sql("UPDATE `char` SET `save_map` = '000-1'");
        query_sql("UPDATE `char` SET `save_x` = '22'");
        query_sql("UPDATE `char` SET `save_y` = '22'");
        $UPDATE=1553350292;
        debugmes "";
        debugmes "* Soul Menhir Save Point replaced";
        debugmes "";
    }
    // Current UPDATE value: Sex Abr 26 00:12:35 -03 2019
    // Monster King & Main Storyline System
    if ($UPDATE < 1556248355) {
        query_sql("UPDATE `quest` SET `count3` = '0' WHERE `quest`.`quest_id`="+HurnscaldQuest_Arkim);
        query_sql("UPDATE `quest` SET `count2` = '0' WHERE `quest`.`quest_id`="+HurnscaldQuest_Arkim);
        $GAME_STORYLINE=2;

        $UPDATE=1556248355;
        debugmes "";
        debugmes "* Main Storyline system updated";
        debugmes "* Arkim updated";
        debugmes "";
    }
    // Current UPDATE value: Sab Mai 04 02:21:58 -03 2019
    // Remove Return Crystals
    if ($UPDATE < 1556947318) {
        query_sql("UPDATE `quest` SET `count2` = '7' WHERE `quest`.`quest_id`="+General_Narrator+" AND `count1` >= '6'");
        query_sql("UPDATE `quest` SET `count1` = '5' WHERE `quest`.`quest_id`="+General_Narrator+" AND `count1` >= '6'");

        DelItemFromEveryPlayer(ReturnPotion);

        $UPDATE=1556947318;
        debugmes "";
        debugmes "* Player Storyline modified";
        debugmes "* Return Crystals removed";
        debugmes "";
    }
    // Current UPDATE value: Seg mai 06 08:54:55 -03 2019
    // Remove Legendary Weapons
    if ($UPDATE < 1557143695) {
        DelItemFromEveryPlayer(Lightbringer);
        //DelItemFromEveryPlayer(DemureAxe); // Demure's Exception!
        DelItemFromEveryPlayer(Tyranny);
        DelItemFromEveryPlayer(Runestaff);
        DelItemFromEveryPlayer(AegisShield);

        $UPDATE=1557143695;
        debugmes "";
        debugmes "* Legendary Weapons removed";
        debugmes "";
    }
    // Current UPDATE value: Dom mai 26 23:00:52 -03 2019
    // Shovel Update
    if ($UPDATE < 1558922452) {
        DelItemFromEveryPlayer(527); // Old pumpkish juice nobody have
        ReplaceItemFromEveryPlayer(526, 527);

        $UPDATE=1558922452;
        debugmes "";
        debugmes "* Shovel Update";
        debugmes "";
    }
    // Current UPDATE value: Seg mai 27 10:57:02 -03 2019
    // Picklog Update
    if ($UPDATE < 1558965422) {
        query_sql("ALTER TABLE picklog MODIFY COLUMN `opt_val0` SMALLINT(5) NOT NULL DEFAULT '0';");
        query_sql("ALTER TABLE picklog MODIFY COLUMN `opt_val1` SMALLINT(5) NOT NULL DEFAULT '0';");
        query_sql("ALTER TABLE picklog MODIFY COLUMN `opt_val2` SMALLINT(5) NOT NULL DEFAULT '0';");
        query_sql("ALTER TABLE picklog MODIFY COLUMN `opt_val3` SMALLINT(5) NOT NULL DEFAULT '0';");
        query_sql("ALTER TABLE picklog MODIFY COLUMN `opt_val4` SMALLINT(5) NOT NULL DEFAULT '0';");

        // Replace all BugSlayer, ShortGladius, RealBronzeGladius and Backsword
        // With a version containing the critical damage option (bCritAtkRate)
        // auction table have no faulty items, nor do carts nor do I care w/ rodex
        // by the time this query was writen
        // IOPT_CRITDMG id is 199
        query_sql("UPDATE `inventory` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+BugSlayer);
        query_sql("UPDATE `storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+BugSlayer);
        query_sql("UPDATE `guild_storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+BugSlayer);

        query_sql("UPDATE `inventory` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+ShortGladius);
        query_sql("UPDATE `storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+ShortGladius);
        query_sql("UPDATE `guild_storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+ShortGladius);

        query_sql("UPDATE `inventory` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+RealBronzeGladius);
        query_sql("UPDATE `storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+RealBronzeGladius);
        query_sql("UPDATE `guild_storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+RealBronzeGladius);

        query_sql("UPDATE `inventory` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+Backsword);
        query_sql("UPDATE `storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+Backsword);
        query_sql("UPDATE `guild_storage` SET `opt_idx0` = '199', `opt_val0` = '30'"+
        " WHERE `nameid`="+Backsword);

        $UPDATE=1558965422;
        debugmes "";
        debugmes "* picklog options Update";
        debugmes "";
    }
    // Current UPDATE value: Sex Jun 21 13:20:21 -03 2019
    // Tulimshar Sailors quest was split in two
    if ($UPDATE < 1561134021) {
        query_sql("UPDATE `quest` SET `count1` = '4' WHERE `quest`.`quest_id`="+TulimsharQuest_Sailors+" AND `count1` >= '2'");

        query_sql("UPDATE `char` SET `last_x` = '22' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `char` SET `last_y` = '22' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `char` SET `last_map` = '000-1' WHERE `char`.`last_map`='005-1'");
        $UPDATE=1561134021;
        debugmes "";
        debugmes "* Tulimshar Sailors split in two";
        debugmes "";
    }
    // Current UPDATE value: Seg Jul 15 22:10:00 -03 2019
    // Candor Redesign
    if ($UPDATE < 1563239400) {
        query_sql("UPDATE `char` SET `last_x` = '22' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `char` SET `last_y` = '22' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `char` SET `last_map` = '000-1' WHERE `char`.`last_map`='005-1'");
        query_sql("UPDATE `skill` SET `id` = '20010' WHERE `skill`.`id`='20011'");
        $UPDATE=1563239400;
        debugmes "";
        debugmes "* Candor Redesign";
        debugmes "* Magic Class Removed";
        debugmes "";
    }
    // Current UPDATE value: Sab Ago 24 17:42:24 -03 2019
    // Political System
    if ($UPDATE < 1566679344) {
        $UPDATE=1566679344;
        // $LOC_MAYOR$ - Stores the name of current Hurnscald Mayor
        // $LOC_MONEY - Total money reserves of Hurnscald
        // $LOC_TAX - How much in % is charged as taxes. (OnBuy income)
        // $LOC_EXPORT - Defines how much Hurnscald exports (weekly income)
        // $LOC_REPUTATION - Town reputation. Affects Max Tax and Weekly Income.

        // Tulim
        $TULIM_MAYOR$="Saulc GM";
        $TULIM_TAX=100;
        $TULIM_EXPORT=5000;
        $TULIM_REPUTATION=50;
        // Halin
        $HALIN_MAYOR$="Saulc GM";
        $HALIN_TAX=100;
        $HALIN_EXPORT=2000;
        $HALIN_REPUTATION=50;
        // Hurns
        $HURNS_MAYOR$="Saulc GM";
        $HURNS_TAX=100;
        $HURNS_EXPORT=3000;
        $HURNS_REPUTATION=50;
        // LoF
        $LOF_MAYOR$="Jesus Saves";
        $LOF_TAX=100;
        $LOF_EXPORT=4000;
        $LOF_REPUTATION=50;
        // Nival
        $NIVAL_MAYOR$="Jesus Saves";
        $NIVAL_TAX=100;
        $NIVAL_EXPORT=3000;
        $NIVAL_REPUTATION=50;
        // Frostia
        $FROSTIA_MAYOR$="Jesus Saves";
        $FROSTIA_TAX=100;
        $FROSTIA_EXPORT=3000;
        $FROSTIA_REPUTATION=50;

        debugmes "";
        debugmes "* Political System Base";
        debugmes "";
    }
    // Current UPDATE value: Sex Jan 17 14:42:37 BRT 2020
    // Remove Junk
    if ($UPDATE < 1579282957) {
        DelItemFromEveryPlayer(748);
        DelItemFromEveryPlayer(1166);
        $UPDATE=1579282957;
        debugmes "";
        debugmes "* Blanket fix";
        debugmes "";
    }
    // Current UPDATE value: Dom Fev 16 14:54:30 BRT 2020
    // Language over simplification
    if ($UPDATE < 1581875670) {
        $UPDATE=1581875670;
        query_sql("DELETE FROM `char_reg_num_db` WHERE `key`='INN_REGISTER'");
        DelAccRegFromEveryPlayer("#RARE_POINTS");
        debugmes "";
        debugmes "* Variable cleanup";
        debugmes "";
    }
    // Current UPDATE value: Sex Fev 24 12:15:12 BRT 2020
    // Release 11.1 final
    if ($UPDATE < 1582557312) {
        $UPDATE=1582557312;
        ReplaceItemFromEveryPlayer(RiceHat, BullHelmet);
        DelItemFromEveryPlayer(SilverEasteregg);
        query_sql("UPDATE `quest` SET `count1` = '2' WHERE `quest`.`quest_id`="+General_Narrator+" AND `count1` = '3'");
        query_sql("UPDATE `quest` SET `count2` = '0' WHERE `quest`.`quest_id`="+General_Narrator+" AND `count1` = '2'");
		$BCONFN_SPAWN = 70;
		$BCONFD_SPAWN = 100;
		$BCONFN_MOBHP = 95;
		$BCONFD_MOBHP = 85;
		$BCONFB_EXPR = 100;
		$BCONFN_EXPR = 5;
		$BCONFD_EXPR = 0;
		$BCONFB_DROP = 100;
		$BCONFN_DROP = 7;
		$BCONFD_DROP = 0;
        debugmes "";
        debugmes "* Bull Helmet Fix";
        debugmes "* Remove Silver Easter Eggs";
        debugmes "* Lua Quest Reset";
        debugmes "* Battle Configuration is now volatile";
        debugmes "";
    }
    // Current UPDATE value: Dom Abr 26 12:41:55 BRT 2020 [1587915715]
    // Current UPDATE value: Qua Mai 27 18:56:15 BRT 2020
    // Fix Tolchi mess
    if ($UPDATE < 1590616575) {
        if ($UPDATE < 1587915715) {
        query_sql("UPDATE `inventory` SET `opt_val0` = '20', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx0`='189' OR `opt_idx0`='200') AND (`opt_idx1`='189' OR `opt_idx1`='200') AND (`opt_val0` > '18' AND `opt_val1` > '18')");
        query_sql("UPDATE `cart_inventory` SET `opt_val0` = '20', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx0`='189' OR `opt_idx0`='200') AND (`opt_idx1`='189' OR `opt_idx1`='200') AND (`opt_val0` > '18' AND `opt_val1` > '18')");
        query_sql("UPDATE `storage` SET `opt_val0` = '20', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx0`='189' OR `opt_idx0`='200') AND (`opt_idx1`='189' OR `opt_idx1`='200') AND (`opt_val0` > '18' AND `opt_val1` > '18')");
        query_sql("UPDATE `guild_storage` SET `opt_val0` = '20', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx0`='189' OR `opt_idx0`='200') AND (`opt_idx1`='189' OR `opt_idx1`='200') AND (`opt_val0` > '18' AND `opt_val1` > '18')");
        query_sql("UPDATE `rodex_items` SET `opt_val0` = '20', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx0`='189' OR `opt_idx0`='200') AND (`opt_idx1`='189' OR `opt_idx1`='200') AND (`opt_val0` > '18' AND `opt_val1` > '18')");
        query_sql("UPDATE `auction` SET `opt_val0` = '20', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx0`='189' OR `opt_idx0`='200') AND (`opt_idx1`='189' OR `opt_idx1`='200') AND (`opt_val0` > '18' AND `opt_val1` > '18')");
        }

        // Destroy duplicates (should not exist)
        query_sql("UPDATE `inventory` SET `opt_val0` = '15', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx1`=`opt_idx0`) AND (`opt_val0` > '15' AND `opt_val1` > '15')");
        query_sql("UPDATE `storage` SET `opt_val0` = '15', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx1`=`opt_idx0`) AND (`opt_val0` > '15' AND `opt_val1` > '15')");
        query_sql("UPDATE `guild_storage` SET `opt_val0` = '15', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx1`=`opt_idx0`) AND (`opt_val0` > '15' AND `opt_val1` > '15')");
        query_sql("UPDATE `rodex_items` SET `opt_val0` = '15', `opt_val1` = '0', `opt_idx1` = '0' WHERE (`opt_idx1`=`opt_idx0`) AND (`opt_val0` > '15' AND `opt_val1` > '15')");

        // Magic v3
        $REBIRTH_WINNER$="Crazyfefe";
        DelChrRegFromEveryPlayer("MAGIC_SUBCLASS");
        ReplaceSkillFromEveryPlayer(MG_FIREBALL, TMW2_FIREARROW); // 1 MSP

        // These skills MSP cost was switched
        ReplaceSkillFromEveryPlayer(AL_HOLYLIGHT, TMW2_NAPALMBEAT);
        ReplaceSkillFromEveryPlayer(MG_NAPALMBEAT, TMW2_HOLYLIGHT);

        ReplaceSkillFromEveryPlayer(MG_SOULSTRIKE, TMW2_MAGICSTRIKE);
        ReplaceSkillFromEveryPlayer(WZ_EARTHSPIKE, TMW2_METEORSTRIKE);

        ReplaceSkillFromEveryPlayer(MG_COLDBOLT, TMW2_FROSTDIVER);
        ReplaceSkillFromEveryPlayer(MG_FROSTDIVER, TMW2_FROSTNOVA);
        ReplaceSkillFromEveryPlayer(WZ_FROSTNOVA, TMW2_NILFHEIM);

        ReplaceSkillFromEveryPlayer(AL_HEAL, TMW2_FIRSTAID);
        ReplaceSkillFromEveryPlayer(AB_HIGHNESSHEAL, TMW2_HEALING);

        debugmes "";
        debugmes "* Tolchi mess cleanup";
        debugmes "* Rebirth Hero";
        debugmes "";
        $UPDATE=1590616575;
    }
    // Current UPDATE value: Ter Jul 28 22:49:52 BRT 2020
    // Tulimshar Volcano
    if ($UPDATE < 1595987392) {
        $UPDATE=1595987392;
        ReplaceItemFromEveryPlayer(816, IcedBottle);
        debugmes "";
        debugmes "* Iced Water re-id";
        debugmes "";
    }
    // Current UPDATE value: Ter Mar 9 18:45:00 BRT 2021
    // Easter Upgrade
    if ($UPDATE < 1615326300) {
        $UPDATE=1615326300;
        DelChrRegFromEveryPlayer("EASTER_EVENT");
        debugmes "";
        debugmes "* Easter changes";
        debugmes "";
    }
    // Current UPDATE value: Qua Abr 7 13:32:35 BRT 2021
    // Skill Update
    if ($UPDATE < 1617813155) {
        $UPDATE=1617813155;
        ReplaceSkillFromEveryPlayer(SM_BASH,            TMW2_FALKONSTRIKE);
        ReplaceSkillFromEveryPlayer(ASC_METEORASSAULT,  TMW2_GROUNDSTRIKE);
        ReplaceSkillFromEveryPlayer(MC_MAMMONITE,       TMW2_SUPREMEATTACK);
        ReplaceSkillFromEveryPlayer(AC_CHARGEARROW,     TMW2_CHARGEDARROW);
        ReplaceSkillFromEveryPlayer(AC_SHOWER,          TMW2_ARROWSHOWER);
        debugmes "";
        debugmes "* Skill changes";
        debugmes "";
    }
    */
    // Current UPDATE value: Qui Set 23 18:46:36 BRT 2021
    // Variable Update
    if ($UPDATE < 1632433596) {
        $UPDATE=1632433596;
        $ALLIANCE_TAX1 = 7500;
        $ALLIANCE_TAX2 = 60;
        debugmes "";
        debugmes "* New global variables";
        debugmes "";
    }
    // Current UPDATE value: Qui Dez 20 13:47:10 BRT 2021
    // Homun Skill Update
    if ($UPDATE < 1640882830) {
        $UPDATE=1640882830;
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8047 WHERE `id`=8013"); // HVAN_CAPRICE
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8048 WHERE `id`=8002"); // HLIF_AVOID
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8050 WHERE `id`=8008"); // HAMI_BLOODLUST
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8049 WHERE `id`=8006"); // HAMI_DEFENSE
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8051 WHERE `id`=8009"); // HFLI_MOON
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8053 WHERE `id`=8011"); // HFLI_SPEED
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8052 WHERE `id`=8010"); // HFLI_FLEET
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8054 WHERE `id`=8020"); // MH_POISON_MIST
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8055 WHERE `id`=8032"); // MH_GOLDENE_FERSE
        query_sql("UPDATE IGNORE `skill_homunculus` SET `id`=8056 WHERE `id`=8031"); // MH_STAHL_HORN
        debugmes "";
        debugmes "* New homunculus skills";
        debugmes "";
    }
    // The following UPDATE value on: Sun Aug 20 17:11:45 CEST 2023
    // Typo update: FMOLY -> FYMOLY.
    if ($UPDATE < 1692544305) {
        $UPDATE = 1692544305;
        DelChrRegFromEveryPlayer("FMOLY_FRIEND");
    }
    // Current UPDATE value: Sex Dez 15 20:30:00 BRT 2023
    // Find the one with highest Lightbringer score and give it
    // Would be unfair otherwise. query_sql to select most active players
    // Then get their points in matrix_lb so on so forth. But this is also unfair
    // So instead, loop through accounts order by activity limit 20
    // Select first char from each account ID, and manually run the most important
    // parts. As we know at least one is eligible, the one with highest score is
    // deemed the victor. Disable Lightbringer NPC afterwards (so a sleep before).
    if ($UPDATE < 1702683000) {
        freeloop(true);
        DelItemFromEveryPlayer(Lightbringer);
        $LIGHT_HOLDER$ = "Jesus Saves";
        debugmes "PLEASE WAIT, LIGHTBRINGER SELECTION IN PROGRESS";
        sleep(3000); // Wait long enough for Scoreboards initialization
        .@nb = query_sql("SELECT `account_id` FROM `login` WHERE `lastlogin` > '"+escape_sql(sqldate(-6))+"' AND `group_id` < 5 ORDER BY `lastlogin` DESC LIMIT 15", .@acids); // Select the 15 most active eligible non-GM accounts
        .@winner = 0; // CharID
        .@wscore = 0;
        for (.@xi=0; .@xi <= getarraysize(.@acids); .@xi++) {
            .@score = 0; .@cid=0; .@name$=""; .@blvl=0; .@jlvl=0;
            deletearray(.@quest_id);
            deletearray(.@qv);
            deletearray(.@var_id$);
            deletearray(.@vv);
            // Select only one char from the account, the one with highest job
            .@nb = query_sql("SELECT `char_id`, `name`, `base_level`, `job_level` FROM `char` WHERE `account_id` = "+.@acids[.@xi]+" ORDER BY `job_level` DESC LIMIT 1", .@cid, .@name$, .@blvl, .@jlvl);
            // Eliminate if .@name$ in the list of legendary holders
            if (islegendary(.@name$))
                continue;
            // Load quests and variables (up to 128 - query_sql's limit)
            .@nb = query_sql("SELECT `quest_id`, `count1` FROM `quest` WHERE `char_id` = "+.@cid+" ORDER BY `count1` DESC LIMIT 128", .@quest_id, .@qv);
            .@nb = query_sql("SELECT `key`, `value` FROM `char_reg_num_db` WHERE `index` = 0 AND `char_id` = "+.@cid+" ORDER BY `value` DESC LIMIT 128", .@var_id$, .@vv);
            // Are you eligible for the Lightbringer? Otherwise, it is expensive
            .@i = array_find(.@quest_id, General_Narrator);
            if (.@i < 0)
                continue;
            if (.@qv[.@i] < 19)
                continue;
            // Begin score calculation
            debugmes "Tallying %s[%d]...", .@name$, .@cid;
            // Magic matrice
            .@i = array_find(.@var_id$, "MAGIC_LVL");
            if (.@i >= 0)
                .@score += min(7, .@vv[.@i]);
            // Deeds matrix (NOT CAPPED, unlike original)
            if (array_find(.@var_id$, "YETIKING_WINNER") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "HEROESHOLD_WINNER") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "QUIRINO_WINNER") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "GEMINI_WINNER") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "GHQ_WINNER") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "FORT_1ST_VISIT") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "MOUBOOTAUR_WINNER") >= 0)
                .@score += 1;
            if (array_find(.@var_id$, "MK_WINNER") >= 0)
                .@score += 1;
            // Rebirth matrice
            .@i = array_find(.@var_id$, "REBIRTH");
            if (.@i >= 0)
                .@score += min(10, .@vv[.@i]*2);
            debugmes "First bout: %d points", .@score;
            // If you didn't made at least two points, you're inelegible
            if (.@score < 2)
                continue;
            // Level matrice
            .@score += min( 5, .@blvl / 30);
            .@score += min(10, .@jlvl / 15);
            // You're also disqualified if you have no chance to win the race
            if (.@score <= (.@wscore - 57))
                continue;
            // Scoreboards matrix
            .@br=array_find($@hoblvl_name$, .@name$);
            .@jr=array_find($@hojlvl_name$, .@name$);
            .@mr=array_find($@hofortune_name$, .@name$);
            .@dr=array_find($@udt_name$, .@name$);
            .@br=limit(0, (.@br >= 0 ? 10-.@br : 0), 10);
            .@jr=limit(0, (.@jr >= 0 ? 10-.@jr : 0), 10);
            .@mr=limit(0, (.@mr >= 0 ? 10-.@mr : 0), 10);
            .@dr=limit(0, (.@dr >= 0 ? 3-.@dr  : 0), 3);
            .@score+=.@br;
            .@score+=.@jr;
            .@score+=.@mr;
            .@score+=.@dr;
            debugmes "Second bout: %d points", .@score;
            // Before we calculate the reputation,
            // You must have accrued a minimum of 10 points
            // Otherwise you're disqualified (new player?)
            if (.@score < 10)
                continue;
            // You're also disqualified if you have no chance to win the race
            if (.@score <= (.@wscore - 24))
                continue;
            // Reputation matrix
            // Tulimshar
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, TulimsharQuests_Fishman);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Sarah);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_WaterForGuard);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_MobTutorial);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 8 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Swezanne);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Lifestone);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Eistein);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 6 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Hasan);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 5 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Devoir);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Sailors);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_DarkInvocator);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 7 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_AnwarField);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 10 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_Neko);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, MineQuest_Tycoon);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 15 ? 1 : 0);
            .@i = array_find(.@quest_id, MineQuest_Dracoula);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, MineQuest_Caelum);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, MineQuest_Naem);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            .@i = array_find(.@quest_id, TulimsharQuest_WoodenSword);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/17) / 33);
            // Hurnscald
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, HurnscaldQuest_ForestBow);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_HarkEye);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 6 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_TeaParty);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_Farmers);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 5 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_Bandits);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 8 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_InjuriedMouboo);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_BloodDonor);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_Woody);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 5 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_Lieutenant);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 10 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_Thorn);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_Blossom);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_LOFPass);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/12) / 33);
            // You must have accrued a minimum of 14 points by now
            // Otherwise you're disqualified
            if (.@score < 14)
                continue;
            // Land of Fire
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, LoFQuest_EPISODE);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2  ? 1 : 0);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 6  ? 1 : 0);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 13 ? 1 : 0);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 17 ? 1 : 0);
            .@i = array_find(.@quest_id, LoFQuest_George);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 5 ? 1 : 0);
            .@i = array_find(.@quest_id, LoFQuest_Fairy);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            .@i = array_find(.@quest_id, LoFQuest_Pets);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/7) / 33);
            // Nivalis
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, NivalisQuest_Well);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, NivalisQuest_Cindy);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 5 ? 1 : 0);
            .@i = array_find(.@quest_id, NivalisQuest_BlueSage);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 12 ? 1 : 0);
            .@i = array_find(.@quest_id, NivalisQuest_BlueSageSlimes);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, NivalisQuest_BlueSagePagemaker);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, NivalisQuest_BlueSagePagefinder);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, NivalisQuest_Henry);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/7) / 33);
            // You must have accrued a minimum of 18 points by now
            // Otherwise you're disqualified
            if (.@score < 18)
                continue;
            // Halinarzo
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, HalinarzoQuest_Foxhound);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 6 ? 1 : 0);
            .@i = array_find(.@quest_id, HalinarzoQuest_TraderKing);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HalinarzoQuest_SickWife);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 5 ? 1 : 0);
            .@i = array_find(.@quest_id, HalinarzoQuest_LifeDelight);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HurnscaldQuest_ForestBow);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HalinarzoQuest_Alvasus);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, HalinarzoQuest_Sawis);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, HalinarzoQuest_Speed);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/8) / 33);
            // Frostia
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, FrostiaQuest_Homunculus);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 4 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_AFKCap);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Jeremy);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Erlan);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Rydel);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Meriel);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Taenya);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Talindra);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Gaelira);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_Saevel);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FrostiaQuest_JhonH);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/11) / 33);
            // You must have accrued a minimum of 22 points by now
            // Otherwise you're disqualified
            if (.@score < 22)
                continue;

            // Candor
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, CandorQuest_Trainer);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 14 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Barrel);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 4 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_HAS);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 4 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Sailors);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_SailorCure);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Vincent);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Tolchi);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Maya);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 4 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Rosen);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 3 ? 1 : 0);
            .@i = array_find(.@quest_id, CandorQuest_Marggo);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 1 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/10) / 33);
            // Fortress Town
            .@i = 0; .@t = 0;
            .@i = array_find(.@quest_id, General_Narrator);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 22 ? 2 : 0);
            .@i = array_find(.@quest_id, FortressQuest_SlimeHunter);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FortressQuest_Over100);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            .@i = array_find(.@quest_id, FortressQuest_RangedHunt);
            if (.@i >= 0) .@t += (.@qv[.@i] >= 2 ? 1 : 0);
            // Final result
            .@score += min(3, (.@t*100/5) / 33);
            debugmes "Final bout: %d points", .@score;

            // Now we determine if you have enough points to surpass #1
            // More active players are evaluated first and have priority.
            if (.@score > .@wscore) {
                .@winner = .@cid;
                .@wscore = .@score;
                $LIGHT_HOLDER$ = .@name$;
            }
        }
        freeloop(false);
        kamibroadcast("The Lightbringer has elected "+$LIGHT_HOLDER$+" as its holder.");
        consolewarn("Elected %s[%d] with %d points for Lightbringer.", $LIGHT_HOLDER$, .@winner, .@wscore);
        disablenpc "Lightbringer";
        $UPDATE = 1702683000;
    }


    // This mensures Contributors Credits, and changes only during updates.
    // All names in lower case. Only TMW2 direct work! Non-TMW2 contributors
    // should be disregarded if they're not involved with the project.
    // Standard patch (DIY); 10 points
    // Reports: 1 point if relevant enough

    // You may get more points for complexity, difficulty, usability, etc.
    // You may get less points if you don't do it yourself, eg. a bug report.
    // Relevance of the contribution is also to be taken in account.

    // See 003-2/lua.txt for rewards
    // Lower case only!

    $@CONTRIBUTORS = htnew;
    htput($@CONTRIBUTORS, "jesusalva",      250);
    htput($@CONTRIBUTORS, "saulc",          250);
    htput($@CONTRIBUTORS, "lawncable",      180);
    htput($@CONTRIBUTORS, "thinksome",      75);
    htput($@CONTRIBUTORS, "crazyfefe",      70);
    htput($@CONTRIBUTORS, "mishana",        70);
    htput($@CONTRIBUTORS, "esteria",        70);
    htput($@CONTRIBUTORS, "arthur",         50);
    htput($@CONTRIBUTORS, "rakinorf",       40);
    htput($@CONTRIBUTORS, "dangerduck",     40);
    htput($@CONTRIBUTORS, "pookie",         36);
    htput($@CONTRIBUTORS, "xanofire",       32);
    htput($@CONTRIBUTORS, "kolchak",        30);
    htput($@CONTRIBUTORS, "jak1",           30);
    htput($@CONTRIBUTORS, "meway",          25);
    htput($@CONTRIBUTORS, "HoraK",          20);
    htput($@CONTRIBUTORS, "dustman",        18);
    htput($@CONTRIBUTORS, "povo",           10);
    htput($@CONTRIBUTORS, "manatauro",      10);
    htput($@CONTRIBUTORS, "minegamerbr",    10);
    htput($@CONTRIBUTORS, "yuckfou",        10);
    htput($@CONTRIBUTORS, "kytty",          10);
    htput($@CONTRIBUTORS, "ledmitz",        10);
    htput($@CONTRIBUTORS, "testuser",       10);
    htput($@CONTRIBUTORS, "liangtai",       4);
    htput($@CONTRIBUTORS, "demure",         2);
    htput($@CONTRIBUTORS, "seeds",          2);
    htput($@CONTRIBUTORS, "lilanna",        1);

    htput($@CONTRIBUTORS, "hocus pocus fidibus", 40);
    htput($@CONTRIBUTORS, "cadis etrama di raizel", 20);
    //htput($@CONTRIBUTORS, "", 1);
    end;

// Maintain only 7 days of chatlog and 2 months of picklog
OnClock0500:
    if (gettime(GETTIME_DAYOFMONTH) >= 7)
        query_sql("DELETE FROM `chatlog` WHERE `time` < '"+sqldate(-7)+"'");
    // Flush picklog
    if ($@HAS_API) {
        query_sql("DELETE FROM `picklog` WHERE `time` < '"+sqldate(0, -1)+"'");
    } else {
        apiasync("SQL", "DELETE FROM `picklog` WHERE `time` < '"+sqldate(0, -1)+"'");
        apiasync("SQLRUN", "");
    }
    // TODO: Have crontab make monthly .gz backup?
    // Remove overhead from picklog
    if (gettime(GETTIME_DAYOFMONTH) == 14) {
        apiasync("SQL", "OPTIMIZE TABLE `picklog`");
        apiasync("SQLRUN", "");
    }
    end;

// This is for HUB
OnSkillInvoke:
    if (!playerattached())
        end;
    HUB_SkillInvoke();
    @skillId=0;
    end;

OnPCBonusEvent:
    if (!playerattached())
        end;
    HUB_PCBonus();
    end;

OnGlobalChat:
    .@msg$ = @chat$;

    // We don't care with punctuation or capitalization
    .@msg$ = strtolower(.@msg$);
    .@msg$ = replacestr(.@msg$, ",", "");
    .@msg$ = replacestr(.@msg$, ".", "");
    .@msg$ = replacestr(.@msg$, "!", "");
    .@msg$ = replacestr(.@msg$, ":", "");
    .@msg$ = replacestr(.@msg$, ";", "");
    .@msg$ = replacestr(.@msg$, "(", "");
    .@msg$ = replacestr(.@msg$, ")", "");
    .@msg$ = replacestr(.@msg$, "<", "");
    .@msg$ = replacestr(.@msg$, ">", "");
    .@msg$ = replacestr(.@msg$, "*", "");

    SK_Scripture(.@msg$);
    end;

// Level up events
OnPCBaseLvUpEvent:
    switch (BaseLevel) {
    case 3:
    case 5:
    case 7:
    case 10:
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    case 19:
        // Recalculate the bonus
        NewcomerEXPDROPUP();
        break;
    case 20:
        if (!REBIRTH) {
            sc_end SC_CASH_PLUSEXP;
            sc_end SC_CASH_RECEIVEITEM;
        }
        break;
	// Events
	case 40:
		if (countitem(MercCard_EH))
			delitem MercCard_EH, countitem(MercCard_EH);
		break;
	// Referral and Eisten
    case 25:
        if (#REFERRAL_PROG && BaseLevel == 25 && #REFERRAL_CTRL < 1) {
            #REFERRAL_CTRL=1;
        	rodex_sendmail(atoi(gf_charid(#REFERRAL_PROG)), "TMW2 Team", "Recruited Player got Lv 25!", strcharinfo(0)+" just got level 25!\nAs they get stronger, more rewards will be sent to you!", 0, SilverGift, 1);
        }
    case 50:
        if (#REFERRAL_PROG && BaseLevel == 50 && #REFERRAL_CTRL < 2) {
            #REFERRAL_CTRL=2;
        	rodex_sendmail(atoi(gf_charid(#REFERRAL_PROG)), "TMW2 Team", "Recruited Player got Lv 50!", strcharinfo(0)+" just got level 50!\nAs they get stronger, more rewards will be sent to you!", 0, ArcmageBoxset, 1);
        }
    case 75:
        if (#REFERRAL_PROG && BaseLevel == 75 && #REFERRAL_CTRL < 3) {
            #REFERRAL_CTRL=3;
        	rodex_sendmail(atoi(gf_charid(#REFERRAL_PROG)), "TMW2 Team", "Recruited Player got Lv 75!", strcharinfo(0)+" just got level 75!\nAs they get stronger, more rewards will be sent to you!", 0, PrismGift, 1);
        }
    case 100:
        if (#REFERRAL_PROG && BaseLevel == 100 && #REFERRAL_CTRL < 4) {
            #REFERRAL_CTRL=4;
        	rodex_sendmail(atoi(gf_charid(#REFERRAL_PROG)), "TMW2 Team", "Recruited Player got Lv 100!", strcharinfo(0)+" just got level 100!\nTime to reap what you've sow for so long!", 0, SupremeGift, 1);
        }
    case 125:
    case 150:
        dispbottom l("Milestone levelup: A reward can now be claimed in Tulimshar.");
        break;
    }
    end;

// Every time the server starts, clean up possibly broken data about treasures.
// NPC ID might have changed.
OnInterIfInitOnce:
    atcommand("@channel setopt #world MessageDelay 1");
    $@HAS_API=apiasync("PING", "");
    query_sql("DELETE FROM `char_reg_num_db` WHERE `key`='RNGTREASURE_DATE'");
    query_sql("DELETE FROM `char_reg_num_db` WHERE `key`='PVP_COOLDOWN'");
    query_sql("DELETE FROM `char_reg_num_db` WHERE `key`='CHAREG_CLEANUP'");
    // Some wildcard deletions
    query_sql("DELETE FROM `char_reg_str_db` WHERE `key` LIKE 'CAPTCHA%'");
    query_sql("DELETE FROM `char_reg_num_db` WHERE `key` LIKE 'CAPTCHA%'");
    end;

// This control all PC Login events
// Position matters!
OnPCLoginEvent:
    // Vault override
    if (#MerchantBank) {
        if (#MerchantBank < 0)
            consolebug("Negative bank data for %s!", strcharinfo(0));
        BankVault += #MerchantBank;
        #MerchantBank = 0;
    }

    // Cannot login with outdated client
    checkclientversion();

    // Message of the Day have priority
    MOTDHandler();

    // Scheduled Announces
    StoneBoardRead();

    // TODO: npc/commands/rate-management.txt

    // Main update handler
    clientupdater();

    // Position and gameplay fixes
    HUB_Login();

    // Alcohol system reset
    ALCReset();

    // Newbie bonuses recalc
    if (BaseLevel < 20 || REBIRTH) NewcomerEXPDROPUP();

    // Daily rewards (The first with dialog interactions)
    daily_login_bonus_handler();

    // Guild Weekly Login Bonus
    guild_login_bonus();

    // Thanksgiving Event
    sThanksgiving();
    end;
}