summaryrefslogtreecommitdiff
path: root/npc/012-1/guards.txt
blob: 17fb366244a32bf8ebedf0c1f98d8ae6900f8294 (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
// TMW2 scripts.
// Authors:
//    Jesusalva
// Description:
//    Protect Hurnscald

012-1,71,24,0	script	Lieutenant Paul	NPC_PLAYER,{
    .@q=getq(HurnscaldQuest_Lieutenant);
    .@k=getq2(HurnscaldQuest_Lieutenant);
    // The Monster King guild have a special menu
    if (!$HURNS_LIBDATE && is_admin()) goto L_Admus;
    if (strcharinfo(2) == "Monster King") goto L_MKControl;
    mesn;
    mesq l("We are @@ since the last great attack from the Monster King.", FuzzyTime($HURNS_LIBDATE,1,2));
    next;
    mesn;
    mesq l("Many citzens are still in fear. Paths are closed, economy is a disaster, things are not here.");
    next;
    mesn;
    mesq l("But we are working day and night. We hope that soon, more people come out and this place gets lively again.");
    if (BaseLevel >= 20 && MPQUEST && .@q <= 15) goto L_Quest;
    close;

// Paul's quest
L_Quest:
    next;
    // Quest State, Legacy value
    @fc=0;
    if (.@q == 0 && BaseLevel >= 20) @fc=1;
    if (.@q == 1 && BaseLevel >= 22) @fc=2;
    if (.@q == 2 && BaseLevel >= 24) @fc=3;
    if (.@q == 3 && BaseLevel >= 26) @fc=4;
    if (.@q == 4 && BaseLevel >= 28) @fc=5;
    if (.@q == 5 && BaseLevel >= 30) @fc=6;
    if (.@q == 6 && BaseLevel >= 32) @fc=7;
    if (.@q == 7 && BaseLevel >= 34) @fc=8;
    if (.@q == 8 && BaseLevel >= 36) @fc=9;
    if (.@q == 9 && BaseLevel >= 38) @fc=10;
    if (.@q == 10 && BaseLevel >= 40) @fc=11;
    if (.@q == 11 && BaseLevel >= 44) @fc=12;
    if (.@q == 12 && BaseLevel >= 48) @fc=13;
    if (.@q == 13 && BaseLevel >= 52) @fc=14;
    if (.@q == 14 && BaseLevel >= 56) @fc=15;
    if (.@q == 15 && BaseLevel >= 60) @fc=16;
    if (@fc)
        goto L_Assign;
    mesn;
    mesq l("I see you are a Monster Hunting Quest Participant, right? I don't need your help right now, but maybe later, who knows?");
    close;

L_Assign:
    // 2 ** 0 = 1 * 100 = 100 mob points
    // 2 ** 1 = 2 * 99  = 198 mob points
    // 2 ** 2 = 4 * 98  = 392 mob points
    // ...
    // 2 ** 9 = 512 * 91 = 46592 mob points (when fc = 10)
    // Then comes the stupdly high table
    // 2 ** 10 = 1024 * 90 = 92,160 mpt (when fc = 11)
    // 2 ** 11 = 2048 * 89 = 182k
    // 2 ** 12 = 4096 * 88 = 360k
    // 2 ** 13 = 8192 * 87 = 712k
    // ... 2 ^ 15 * 85 = 2.8 million
    @rq=(2**(@fc-1))*(101-@fc);
    if (@fc == 16) @rq=1500000;

    // Check if you already met objective
    if (.@k > 0 && Mobpt >= .@k+@rq) {
        setq HurnscaldQuest_Lieutenant, @fc, 0;
        Mobpt-=@rq;
        mesn;
        mesq l("Good job collecting the monster points for me. Here's your reward.");
        @xp=1000;
        // reward is 30% from reference level exp to level up
        switch (@fc) {
            case 1: @xp=486; break;
            case 2: @xp=597; break;
            case 3: @xp=751; break;
            case 4: @xp=1028; break;
            case 5: @xp=1342; break;
            case 6: @xp=2399; break;
            case 7: @xp=3128; break;
            case 8: @xp=4190; break;
            case 9: @xp=5303; break;
            case 10: @xp=6532; break;
            /* After this it demands so much XP, I raised the rate from 30 to 100%
            case 11: @xp=10234; break;
            case 12: @xp=12630; break;
            case 13: @xp=15908; break;
            case 14: @xp=19212; break;
            case 15: @xp=22792; break;
            case 16: @xp=34577; break;
            */
            case 11: @xp=34212; break;
            case 12: @xp=53026; break;
            case 13: @xp=75973; break;
            case 14: @xp=142784; break;
            case 15: @xp=215198; break;
            case 16: @xp=365914; break;
        }
        getexp @xp, @fc*3;
        Zeny=Zeny+@fc*15+@fc;
        mesc l("* Gained @@ EXP and @@ Job Exp", @xp, @fc*3);
        mesc l("* Gained @@ GP", @fc*15+@fc);
        // Welcome to the stupid table
        if (@fc >= 10) {
            switch (@fc) {
                case 10:
                    .@tea=Coffee; .@gift=BronzeGift; .@rare=Grenade;
                    break;
                case 11:
                    .@tea=ChamomileTea; .@gift=SilverGift; .@rare=WhiskeyAle;
                    break;
                case 12:
                    .@tea=SpearmintTea; .@gift=SilverGift; .@rare=PrecisionPotion;
                    break;
                case 13:
                    .@tea=OolongTea; .@gift=GoldenGift; .@rare=SacredLifePotion;
                    break;
                case 14:
                    .@tea=JasmineTea; .@gift=GoldenGift; .@rare=MercBoxEE;
                    break;
                case 15:
                    .@tea=YerbaMate; .@gift=PrismGift; .@rare=MysteriousFruit;
                    break;
                default: // 16+
                    .@tea=ElixirOfLife; .@gift=PrismGift; .@rare=MylarinDust;
                    break;
            }
            mesc l("For your incredibly hard work, you got:");
            mesf("* %d %s", 1, getitemlink(.@tea));
            mesf("* %d %s", 1, getitemlink(.@gift));
            mesf("##B* %d %s##b", 1, getitemlink(.@rare));
            getitem .@rare, 1;
            getitem .@gift, 1;
            getitem .@tea, 1;
        }
        close;
    }
    // Assign quest
    else if (.@k == 0) {
        mesn;
        mesq l("Maybe you can help our city guard. I see you are a Monster Hunting Quest Participant, right?");
        next;
        mesn;
        mesq l("So, I'm placing a special bounty for @@ Mob Points.", @rq);
        mesq l("You currently have @@, so if you accept and come back later with @@ Mob Points, I'll mark the bounty as complete.", Mobpt, Mobpt+@rq);
        next;
        mesc l("Accept quest?");
        if (askyesno() == ASK_YES) {
            setq HurnscaldQuest_Lieutenant, @fc-1, Mobpt;
        }
    }
    // Resume quest
    else {
        // Reset if needed
        if (Mobpt-.@k < 0) {
            setq2 HurnscaldQuest_Lieutenant, Mobpt;
            .@k=0;
        }
        mesn;
        mesq l("You have collected and additional of @@/@@ Mob Points.", Mobpt-.@k, @rq);
    }
    close;












// Liberation Day facility
L_Admus:
    mes ".:: " + col("HURNSCALD LIBERATION DAY - ADMUS PANEL", 2) + " ::.";
    mesc l("For HLib, a GM must take the role of the Monster King");
    mesc l("Protip: Use @hide to don't interfer.");
    mes l("Determine Team Size (If everyone is ready and stdby at Tulimshar, use: @@. Minimum 2 players.)", getusers(1)-1);
    input $@BG1_SIZE;
    if ($@BG1_SIZE < 2 && !$@GM_OVERRIDE) close;
    $@BG1_SIZE=$@BG1_SIZE+1;

    kickwaitingroomall("Hurnsguard");
    setmapflagnosave("012-1", "000-1", 22, 22);
    //setmapflag("012-1", mf_nocommand); // This is just too powerful!
    setmapflag("012-1",mf_zone,"MMO"); // MMO Zone: Overrides GM Commands
    setmapflag("012-1", mf_battleground);
    setmapflag("012-1", mf_nopenalty);
    setmapflag("012-1",mf_bexp,126);
    enablenpc "Hurnsguard";
	donpcevent "Hurnsguard::OnSet";
	donpcevent "Lieutenant Paul::OnSet";
    addmapmask "012-1", MASK_MATTACK;
    addmapmask "012-1", MASK_EVILSANCTUM;
    pvpon("012-1");
    disablenpc "#012-1_22_62";
    disablenpc "#012-1_79_17";
    disablenpc "#012-1_79_102";
    disablenpc "#012-1_132_101";
    disablenpc "#012-1_65_55";
    disablenpc "#012-1_89_58";
    disablenpc "#012-1_101_55";
    disablenpc "#012-1_121_71";
    disablenpc "#012-1_116_66";
    disablenpc "#012-1_110_56";
    disablenpc "#012-1_102_69";
    disablenpc "Andrei Sakar";
    disablenpc "Dyrin The Traveler";
    disablenpc "Gwendolyn";
    disablenpc "Jack";
    disablenpc "Locamit";
    disablenpc "Richard";
    disablenpc "Soul Menhir#hurns";
    disablenpc "HurnsShip#M";
    disablenpc "Hinnak";
    disablenpc "Tezzerin";
    disablenpc "Luffyx";
    disablenpc "Shoppa Kep";
    announce "##1Hear ya, hear ya! There are "+str($@BG1_SIZE-1)+" vacant slots at Hurnsguard to LIBERATE HURNSCALD!", bc_all | bc_npc;
    mesc "You are assigned to Monster Forces. Do not leave Hurnscald.", 1;
    close;

// Monster King Siege (deprecated)
L_MKControl:
    mesn;
    mes l("Oh noes! You've found the Hurnscald control panel!");
    next;
    select
        l("Abort"),
        l("Initiate a siege");
    mes "";
    if (@menu == 2) {
        doevent "#HurnscaldSiege::OnStartSiege";
        closedialog;
    }
    close;

// Hurnscald Liberation Day Core Logic
OnSet:
    .CYCLES=0;
	waitingroom("Monster Army", 2, "start#hurns_lib::OnReadyCheck", 1);
    end;

OnEnterBG:
    debugmes "Paul::OnEnterBG";
	$@FK_Team2 = waitingroom2bg("012-1",141, 65,"start#hurns_lib::OnPlayer2Quit","start#hurns_lib::OnPlayer2Death");
    setbgteam $@FK_Team2, 2;
	end;

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

    .@npcId = getnpcid(.name$);
    setunitdata(.@npcId, UDT_HEADTOP, BullHelmet);
    setunitdata(.@npcId, UDT_HEADMIDDLE, LieutenantArmor);
    setunitdata(.@npcId, UDT_HEADBOTTOM, RaidTrousers);
    setunitdata(.@npcId, UDT_SHIELD, LousyMoccasins);    // TODO FIXME: Display Boots
    setunitdata(.@npcId, UDT_WEAPON, Backsword);
    setunitdata(.@npcId, UDT_HAIRSTYLE, 12);
    setunitdata(.@npcId, UDT_HAIRCOLOR, 15);

    end;
}















// Liberation Day Script
012-1,122,25,0	script	Hurnsguard	NPC_PLAYER,{
    query_sql("SELECT online FROM `char` WHERE name='Saulc GM'", .@online);
    if (!.@online) {
        mesn;
        mesq l("We are planning to take over Hurnscald from the Monster King, and we will need everybody's help.");
        next;
        mesn;
        mesq l("As soon that Saulc GM get back, we can start.");
        close;
    }
    mesc l("Hurnscald Liberation Day special event"), 3;
    mes "";
    mesc l("The objective of this event is to ##Bslay the Monster Admiral##b.");
    mesc l("If you die, you ##Bwon't##b be able to rejoin, but you won't suffer the penalty.");
    next;
    mesc l("If all players there die, Hurnscald WON'T BE LIBERATED.");
    mesc l("This basically means that it'll be another day without it.");
    mesc l("Also, the more players survive, the better rewards will be given.");
    next;
    mesc l("Right click on this NPC to join the Hurnscald Alliance."), 3;
    mesc l("The number of players must be precise, meaning if someone doesn't joins,");
    mesc l("the event won't start and HURNSCALD WON'T BE LIBERATED.");
    next;
    mesc l("Once you join the Alliance, you won't be able to talk with people outside it.");
    mesc l("Additionaly, all your movement will be restricted until either you're warped or log out.");
    close;

OnSet:
	waitingroom("Hurnscald Alliance", $@BG1_SIZE, "start#hurns_lib::OnReadyCheck", $@BG1_SIZE-1);
    end;

OnInit:
    .CYCLES=0;
    .@npcId = getnpcid(.name$);
    setunitdata(.@npcId, UDT_HEADTOP, GoldenWarlordPlate); // Light armor
    setunitdata(.@npcId, UDT_HEADMIDDLE, JeansChaps); // Pants
    setunitdata(.@npcId, UDT_HEADBOTTOM, DeepBlackBoots); // Shoes
    setunitdata(.@npcId, UDT_WEAPON, BugSlayer);
    setunitdata(.@npcId, UDT_HAIRSTYLE, 13);
    setunitdata(.@npcId, UDT_HAIRCOLOR, 7);
    if ($HURNS_LIBDATE)
        disablenpc(.name$);
	end;

OnEnterBG:
    debugmes "Alliance::OnEnterBG";
	$@FK_Team1 = waitingroom2bg("012-1",141, 65,"start#hurns_lib::OnPlayerQuit","start#hurns_lib::OnPlayerDeath");
    setbgteam $@FK_Team1, 1;
	end;

OnDoEvent:
    debugmes "OnDoEvent";
	mapannounce("012-1", "Find and slay the Monster Admiral! DO NOT ATTACK GUARDS. Don't let everyone die!", bc_map);
    .@Pl=getmapusers("012-1");
    .CYCLES=0;

    // Guards won't attack the Monster Staff
    areamonster("012-1", 52, 45, 127, 80, "Monster Sergeant", Forain, .@Pl/3+1, "Hurnsguard::OnXtreem");
    areamonster("012-1", 52, 45, 127, 80, "Monster Sergeant", Moonshroom, .@Pl/2+1, "Hurnsguard::OnXtreem");
    areamonster("012-1", 52, 45, 127, 80, "Monster Soldier", AngryScorpion, .@Pl, "Hurnsguard::OnSkip");
    for (.@i = 0; .@i < .@Pl; .@i++)
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Friendly Guard", FallenGuard1, "Cassia::OnSkip");
	initnpctimer();
    end;

OnSkip:
    // Here, coins drop rate are based on REMAINING PLAYERS and DEFEATED MONSTER LEVEL.
    // A level 100 monster can have a 5% drop bonus against a level 0 monster.
    // You have 1.2% of base chance, plus 0.5% each player + 0.05% each monster level.
    if (rand(10000) <= 120 + (getmapusers("012-1")*50) + (strmobinfo(3,killedrid)*5))
        getmapxy(.@m$, .@x, .@y, 0);
        makeitem(any(Plushroom, Chagashroom, Bread, HalfCroconut, Aquada, CasinoCoins, CactusCocktail, AppleCocktail, CherryCocktail), any(1,1,2), "012-1", .@x, .@y);
    end;

OnTimer300000:
    .@Pl=getmapusers("012-1")+mobcount("012-1", "Cassia::OnSkip")-1;
    .@Pla=getmapusers("012-1");
    .@Mb=mobcount("012-1", "Hurnsguard::OnSkip")+mobcount("012-1", "Hurnsguard::OnXtreem")+2; // Saulc GM is an enemy for server code
    for (.@i = 0; .@i < .@Pla; .@i++)
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Friendly Guard", FallenGuard1, "Cassia::OnSkip");

    // See if we need extra guards, depending on how outnumbered allied forces are.
    if ((.@Mb / .@Pl) > 7) {
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Additional Guard", FallenGuard2, "Cassia::OnSkip");
    }
    if ((.@Mb / .@Pl) > 6) {
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Additional Guard", FallenGuard2, "Cassia::OnSkip");
    }
    if ((.@Mb / .@Pl) > 5) {
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Additional Guard", FallenGuard2, "Cassia::OnSkip");
    }
    if ((.@Mb / .@Pl) > 4) {
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Additional Guard", FallenGuard2, "Cassia::OnSkip");
    }
    if ((.@Mb / .@Pl) > 3) {
    	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Additional Guard", FallenGuard2, "Cassia::OnSkip");
    }
    .@Pl=getmapusers("012-1")+mobcount("012-1", "Cassia::OnSkip")-1;
    .@Pla=getmapusers("012-1")-1;

	mapannounce("012-1", "Survivors: "+.@Pla+" Hurnscald Alliance: "+.@Pl+"  Monsters: "+.@Mb, bc_map);
    initnpctimer;
    end;

OnTimer10000:
OnTimer120000:
OnTimer240000:
    .CYCLES=.CYCLES+1;

    // Scripted monsters
    if (.CYCLES == 2) {
    	mapannounce("012-1", "Monster Lieutenant appears! Watch out!", bc_map);
    	bg_monster($@FK_Team2, "012-1", 65, 71, "Monster Lieutenant", NightScorpion, "Hurnsguard::OnXtreem");
    } else if (.CYCLES == 3) {
    	mapannounce("012-1", "Monster Admiral appears! Kill it to liberate Hurns!", bc_map);
    	.@boss=bg_monster($@FK_Team2, "012-1", 65, 71, "Monster Admiral", GiantMutatedBat, "Hurnsguard::OnVictory");
        // Give huge amounts of health to the boss (Default: 43310)
        setunitdata(.@boss, UDT_MAXHP, 100000);
        setunitdata(.@boss, UDT_HP,    100000);
    }

    // One monster per user alive
    .@Pl=getmapusers("012-1");
    for (.@i = 0; .@i < .@Pl; .@i++) {
        .@monsterId=any(CaveMaggot, RedSlime, LavaSlime, BlackScorpion,
        AngryRedScorpion, Sarracenus, Snake, MountainSnake, GreenSlime,
        Bandit, BlackScorpion, HouseMaggot, AngryScorpion, MagicGoblin,
        Pinkie, Mouboo, Scorpion, Yeti);

    	bg_monster($@FK_Team2, "012-1", rand(69, 136), rand(83, 74), "Monster Soldier", .@monsterId, "Hurnsguard::OnSkip");
        // 40% odds of having an extra monster spawned (player loop)
        if (rand(1,5) % 2 == 0)
        	bg_monster($@FK_Team2, "012-1", rand(69, 136), rand(83, 74), "Monster Soldier", .@monsterId, "Hurnsguard::OnSkip");
    }
    // One slime blast per general
    .@Mgg=mobcount("012-1", "Hurnsguard::OnXtreem");
    for (.@i = 0; .@i < .@Mgg; .@i++) {
    	bg_monster($@FK_Team2, "012-1", rand(69, 136), rand(83, 74), "Monster Soldier", SlimeBlast, "Cassia::OnSkip");
    }
    // One Magic Goblin or Pinkie per cycle
    for (.@i = 0; .@i < .CYCLES; .@i++) {
        if (rand(1,2) == 1)
        	bg_monster($@FK_Team2, "012-1", rand(69, 136), rand(83, 74), "Monster Soldier", Pinkie, "Hurnsguard::OnSkip");
        else
        	bg_monster($@FK_Team2, "012-1", rand(69, 136), rand(83, 74), "Monster Soldier", MagicGoblin, "Hurnsguard::OnSkip");
    }
    // Spawn Angry Scorpions on the whole map. These monsters are neutral!
    areamonster("012-1", 33, 16, 137, 100, "Monster Soldier", AngryScorpion, .CYCLES, "Hurnsguard::OnSkip");

    // One extra guard on every summon
	bg_monster($@FK_Team1, "012-1", rand(131, 136), rand(64, 80), "Additional Guard", FallenGuard2, "Cassia::OnSkip");
    end;

OnXtreem:
    if (rand2(0,100) > 50)
        getitem StrangeCoin, 2;
    // Here, the drop is a Bronze Gift, based on living players and players nearby.
    // You have 0.1% of base chance, plus 0.2% each fighting player + 1% each near player.
    getmapxy(.@m$, .@x, .@y, 0);
    if (rand(10000) <= 10 + (getmapusers("012-1")*20) + (getareausers("012-1", .@x-8, .@x+8, .@y-8, .@y+8)*100))
        makeitem(BronzeGift, 1, "012-1", .@x, .@y);
    end;

OnVictory:
    $HURNS_LIBDATE=gettimetick(2);
    removemapflag("012-1", mf_nosave);
    disablenpc "Hurnsguard";
    pvpoff("012-1");
    removemapmask "012-1", MASK_MATTACK;
    removemapmask "012-1", MASK_EVILSANCTUM;
    //removemapflag("012-1", mf_nocommand);
    setmapflag("012-1",mf_zone,"Normal2"); // Revert MMO Zone
    removemapflag("012-1", mf_battleground);
    removemapflag("012-1", mf_bexp);
    setmapflag("012-1",mf_bexp,100);
    enablenpc "#012-1_22_62";
    enablenpc "#012-1_79_17";
    enablenpc "#012-1_79_102";
    enablenpc "#012-1_132_101";
    enablenpc "#012-1_65_55";
    enablenpc "#012-1_89_58";
    enablenpc "#012-1_101_55";
    enablenpc "#012-1_121_71";
    enablenpc "#012-1_116_66";
    enablenpc "#012-1_110_56";
    enablenpc "#012-1_102_69";
    enablenpc "Andrei Sakar";
    enablenpc "Dyrin The Traveler";
    enablenpc "Gwendolyn";
    enablenpc "Jack";
    enablenpc "Locamit";
    enablenpc "Richard";
    enablenpc "Soul Menhir#hurns";
    enablenpc "HurnsShip#M";
    enablenpc "Hinnak";
    enablenpc "Tezzerin";
    enablenpc "Luffyx";
    enablenpc "Shoppa Kep";
    announce "##2Hurnscald was recovered!", bc_all | bc_npc;
    killmonster("012-1", "All");
    changemusic "012-1", "tws_birds_in_the_sunrise.ogg"; // Play a more peaceful tune.
    stopnpctimer;
    maptimer("012-1", 10, "Hurnsguard::OnReward");
    // Here, coins drop rate are based on REMAINING PLAYERS and DEFEATED MONSTER LEVEL.
    // You have $coinsrate of base chance, plus 2% for each living player.
    // $coinsrate is set on Aeros Event Master, and defaults to 6%
    if (rand(10000) <= $coinsrate + (getmapusers("012-1")*200))
        getmapxy(.@m$, .@x, .@y, 0);
        makeitem(StrangeCoin, 1, "012-1", .@x, .@y);
    //Karma=Karma+1;
    $MOST_HEROIC$=strcharinfo(0);
    bg_destroy(1);
    bg_destroy(2);
    end;

OnReward:
	bg_leave();
    // Let's say we have 5 players for reference. Subtract a Game Master, he doesn't counts.
    .@Pl=getmapusers("012-1")-1;
    getexp .@Pl*600, .@Pl*30; // 3,000 exp, 150 jxp
    Zeny=Zeny+.@Pl*300; // 1,500 gp
    end;

}












//== Battleground Engine ======================
012-1,0,0,0	script	start#hurns_lib	NPC_HIDDEN,{
OnInit:
	end;

OnEnable:
	end;

OnPlayerQuit:
OnPlayerDeath:
OnPlayer2Quit:
OnPlayer2Death:
	bg_leave();
    // Check if we are done for.
    warp "000-1", 22, 22;
    .@Pl=getmapusers("012-1");
    if (.@Pl <= 1 && !$@GM_OVERRIDE) {
        announce "##1Hurnscald is lost!", bc_all | bc_npc;
        disablenpc "Hurnsguard";
        pvpoff("012-1");
        removemapmask "012-1", 10;
        removemapflag("012-1", mf_nocommand);
        removemapflag("012-1", mf_battleground);
        killmonster("012-1", "all");
        bg_destroy(1);
        bg_destroy(2);
    }
	end;

OnReadyCheck:
	.@Alliance = getwaitingroomstate(0,"Hurnsguard");
    debugmes "Check:" +str(.@Alliance)+"<"+ str($@BG1_SIZE-1);
	if ( .@Alliance < $@BG1_SIZE-1 )
		end;
	donpcevent "Hurnsguard::OnEnterBG";
	donpcevent "Lieutenant Paul::OnEnterBG";
    debugmes "Prepare Warp";
	bg_warp $@FK_Team1,"012-1",141, 65;
	bg_warp $@FK_Team2,"012-1",69, 71;
    changemusic "012-1", "misuse.ogg";
	donpcevent "Hurnsguard::OnDoEvent";
	//initnpctimer;
	end;
}









// Handle Guard's logic
function	script	CheckpointGuard	{
    mesn;
    mesq l("I am stationed here to protect Hurnscald from monsters.");
    next;
    mesn;
    mesq l("If the Monster King attack, I will try to control inbound monsters here.");
    close;
    return;
}

012-1,81,18,0	script	Checkpoint Guard#1	NPC_GUARD2,{
    CheckpointGuard();
    end;

OnInit:
    .sex = G_FEMALE;
    .distance = 5;
    end;
}


012-1,26,60,0	script	Checkpoint Guard#2	NPC_GUARD1,{
    CheckpointGuard();
    end;

OnInit:
    .sex = G_MALE;
    .distance = 5;
    end;
}

012-1,80,98,0	script	Checkpoint Guard#3	NPC_GUARD2,{
    CheckpointGuard();
    end;

OnInit:
    .sex = G_FEMALE;
    .distance = 5;
    end;
}


012-1,134,98,0	script	Checkpoint Guard#4	NPC_GUARD1,{
    CheckpointGuard();
    end;

OnInit:
    .sex = G_MALE;
    .distance = 5;
    end;
}

012-1,94,56,0	script	Guard#012-1.1	NPC_GUARD1,{
    .@q=getq(HurnscaldQuest_HungryGuard);
    if (.@q == 0) {
        mesn l("Guard");
        mesq l("Hey, you! Could you bring me an @@?", getitemlink(RedApple));
        next;
        mesn l("Guard");
        mesq l("I'm hungry like a bear :b");
        if (!countitem(RedApple))
            close;
        select
            l("Here, you can have this one!"),
            l("Nope, sorry!");
        mes "";
        if (@menu == 1) {
            delitem RedApple, 1;
            setq HurnscaldQuest_HungryGuard, 1;
            getexp 500, 0;
            mesn l("Guard");
            mesq l("Oooh, many thanks! ^.^");
        }
        close;
    }
    legiontalk;
    end;

OnInit:
    .sex = G_MALE;
    .distance = 5;
    end;
}


012-1,112,65,0	script	Guard#012-1.2	NPC_GUARD2,{
    legiontalk;
    end;

OnInit:
    .sex = G_FEMALE;
    .distance = 5;
    end;
}



012-1,0,0,0	script	#HurnscaldSiege	NPC_HIDDEN,{
    end;

// Begin Siege
OnMKSiege:
    $@SIEGE_ABORTED = false;
OnStartSiege:
    kamibroadcast(col("WARNING! WARNING! Monster Army is moving towards Hurnscald!!",1));
    do_siege("012-1", "014-3", "HURNS", TP_HURNS, .name$, .siegetime);
    initnpctimer;
    end;

// Timers
OnTimer5000:
    .siegetime+=5;
    do_siege("012-1", "014-3", "HURNS", TP_HURNS, .name$, .siegetime);
    switch (.siegetime) {
    // Monster Army arrives in town
    case 60:
        disablenpc "Oscar";
        disablenpc "Gwendolyn";
        disablenpc "Milly";
        disablenpc "LOFBot";
        disablenpc "Locamit";
        disablenpc "Andrei Sakar";
        disablenpc "Luffyx";
        disablenpc "Tezzerin";
        disablenpc "Hinnak";
        disablenpc "Igor";
        disablenpc "Dyrin The Traveler";
        disablenpc "Mahad";
        disablenpc "Jack";
        break;
    // Monster Army deployed in town
    case 90:
        disablenpc "Shoppa Kep";
        disablenpc "Richard";

        disablenpc "Celestia";
        disablenpc "Airlia";
        disablenpc "Nicholas";
        disablenpc "Wyara";
        disablenpc "Alan";
        disablenpc "Khafar";
        disablenpc "Melina";
        disablenpc "Helena";
        disablenpc "Rakinorf, Mayor";
        break;
    // Monster army have withdrawn completly
    case MK_SIEGE_DURATION:
        .siegetime=0;
        announce(("Hurnscald siege is over!"), bc_all);
        enablenpc "Gwendolyn";
        enablenpc "Milly";
        enablenpc "LOFBot";
        enablenpc "Locamit";
        enablenpc "Andrei Sakar";
        enablenpc "Luffyx";
        enablenpc "Tezzerin";
        enablenpc "Hinnak";
        enablenpc "Igor";
        enablenpc "Dyrin The Traveler";
        enablenpc "Mahad";
        enablenpc "Jack";
        enablenpc "Shoppa Kep";
        enablenpc "Richard";
        enablenpc "Celestia";
        enablenpc "Airlia";
        enablenpc "Nicholas";
        enablenpc "Wyara";
        enablenpc "Alan";
        enablenpc "Khafar";
        enablenpc "Melina";
        enablenpc "Helena";
        enablenpc "Rakinorf, Mayor";
        enablenpc "Oscar";
        stopnpctimer;
        end;
        break;
    }

    // Loop again
    initnpctimer;
    end;

OnInit:
    .siegetime=0;
    end;
}