summaryrefslogtreecommitdiff
path: root/npc/015-6/treasure.txt
blob: 5fc1a1c0f55f14bf28eadd8ad8170232deda5878 (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
// TMW2 Script

// (Random) Treasure Chest
//  Authored by Jesusalva
// Regenerates every 6 hours

015-6,0,0,0	script	#chest_01560	NPC_CHEST,{

   if (!.busy && !.empty) {
        TreasureBox();

        .empty=true;
        specialeffect(.dir == 0 ? 24 : 25, AREA, getnpcid()); // closed ? opening : closing
        .dir = .dir == 0 ? 2 : 6; // closed ? opening : closing
        .busy = true; // lock until available again
        initnpctimer;
    } else if (!.busy) {
        mesc l("Someone looted this treasure box already...");
    } else {
        end;
    }
    close;

OnTimer160:
    .dir = .dir == 6 ? 0 : 4; // closing ? closed : open
    end;

OnTimer500:
    .busy = false; // unlock
    if (.dir == 0 || .dir == 4)
        stopnpctimer; // stop here if the chest is closed
    end;

OnInit:
    .busy = false;
    .distance = 2;
    .empty = false;

OnClock0156:
OnClock0756:
OnClock1356:
OnClock1956:
    // Try to warp randomly to a walkable spot, up to 20 attempts
    // Otherwise, it'll stay where it already is (but will close and refill).
    .@e=0; .@x=0; .@y=0;
   while (!checkcell(.map$, .@x, .@y, cell_chkpass))
    {
        if (.@e == 20) {
            .@x=.x;
            .@y=.y;
            break;
        }
        // Remember the +20 -20 margin adjustment
        .@x = rand(20, 500);
        .@y = rand(20, 190);
        ++.@e;
    }
    .busy=false;
    .empty=false;
    movenpc .name$, .@x, .@y, 0;
    end;
}

015-6,0,0,0	duplicate(#chest_01560)	#chest_01561	NPC_CHEST