summaryrefslogtreecommitdiff
path: root/npc/functions/quest-debug/functions.txt
blob: f89adfab752ad7d628b6ecf02f69ae163608241e (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
// Evol functions.
// Author:
//     gumi
// Description:
//     generic quest debug functions



// GenericQuestDebug
//     makes a generic quest debug menu for the given quest when the server
//     is in debug mode.

function	script	GenericQuestDebug	{
    if (!debug && !is_admin())
    {
        select
            menuimage("actions/back", l("Go back"));

        @menuret = -0x7FFFFFFF;
        return 1;
    }

    mes l("Choose desired quest state:");

    deletearray .@vals;
    .@menustr$ = menuimage("actions/abort", l("Do nothing")) + ":";
    .@vals[0] = -0x7FFFFFFF;
    .@cnt = 1;

    for (.@f = 1; .@f < getargcount(); .@f += 2)
    {
        if (getarg(.@f) != "")
        {
            .@qv = getarg(.@f + 1);
            .@s$ = menuimage("actions/" + (.@qv ? "edit" : "reset"), "[" + .@qv + "] " + getarg(.@f));
            .@menustr$ += (.@qv < 0 ? getarg(.@f) : .@s$) + ":";
            .@vals[.@cnt] = .@qv;
            ++.@cnt;
        }
    }

    if (is_admin())
    {
        .@menustr$ += menuimage("actions/nuke", l("Set state manually"));
        .@vals[.@cnt] = -0x7FFFFFFE;
    }


    @menu = 255;
    @menuret = -1;
    select(.@menustr$);
    if (@menu == 255)
        return -1;

    --@menu;
    if (@menu < 0 || @menu >= getarraysize(.@vals))
        return -1;

    @menuret = .@vals[@menu];

    switch (@menuret)
    {
        case -0x7FFFFFFE: input @menuret; setq getarg(0,0), @menuret;
        case -0x7FFFFFFF: return 1;
    }

    if (@menuret >= 0)
    {
        setq getarg(0,0), @menuret;
    }
    return;
}



// selectd
//     like a normal select() but gives access to quest debug
//
//     quest id can either be passed as first argument
//     or as the .quest_debug npc variable

function	script	selectd	{
    .@menustr$ = rif(debug, menuaction(l("debug")));
    .@count = getargcount();
    .@f = 0;
    .@questID = getvariableofnpc(.quest_debug, strnpcinfo(0));

    if (.@count > 1 && !isstr(getarg(0)))
    {
        ++.@f;
        .@questID = getarg(0);
    }

    for (; .@f < .@count; ++.@f)
    {
        .@menustr$ += ":" + getarg(.@f);
    }

    @menu = 255;
    select .@menustr$;

    switch (@menu)
    {
        case -1:
        case 255: return -1;
        default: @menu -= 1; return @menu; // FIXME: here I would have done `return --@menu;` but hercules prevents this
        case 1: callfunc "QuestDebug" + .@questID; closedialog; end;
    }
}