summaryrefslogtreecommitdiff
path: root/npc/functions/input.txt
blob: 0a510b740f6490e820617cd6957232800a140ead (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
// Evol functions.
// Author:
//    4144
//    Jesusalva
// Description:
//    Input utility functions
// Variables:
//    none

function	script	menuint	{
    deletearray .@vals;
    .@menustr$ = "";
    .@cnt = 0;

    for (.@f = 0; .@f < getargcount(); .@f = .@f + 2)
    {
        if (getarg(.@f) != "")
        {
            .@menustr$ = .@menustr$ + getarg(.@f) + ":";
            .@vals[.@cnt] = getarg(.@f + 1);
            .@cnt ++;
        }
    }

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

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

    @menuret = .@vals[@menu];
    return @menuret;
}

function	script	menustr	{
    deletearray .@vals$;
    .@menustr$ = "";
    .@cnt = 0;

    for (.@f = 0; .@f < getargcount(); .@f = .@f + 2)
    {
        if (getarg(.@f) != "")
        {
            .@menustr$ = .@menustr$ + getarg(.@f) + ":";
            .@vals$[.@cnt] = getarg(.@f + 1);
            .@cnt ++;
        }
    }

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

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

    @menuret$ = .@vals$[@menu];
    return @menuret$;
}

// menuint2(<array>)
function	script	menuint2	{
    .@menustr$="";

    if (!(getdatatype(getarg(0)) & DATATYPE_VAR))
        Exception("Inadequate argument type - Must be var", RB_DEFAULT|RB_ISFATAL);

    copyarray(.@ar$, getarg(0), getarraysize(getarg(0)));

    if (getarraysize(.@ar$) % 2 != 0)
        Exception("Invalid array size: "+getarraysize(.@ar$), RB_DEFAULT|RB_ISFATAL);

    freeloop(true);
    for (.@f=0; .@f < getarraysize(.@ar$); .@f++) {
        // String vs Int
        if (.@f % 2 == 0) {
            .@menustr$+=.@ar$[.@f]+":";
        } else {
            array_push(.@vals, atoi(.@ar$[.@f]));
        }
    }
    freeloop(false);

    // Do the request
    // We have: .@vals and .@menustr$
    @menu = 255;
    @menuret = -1;
    select(.@menustr$);
    //debugmes "Option %d", @menu;
    //debugmes "Array size %d", getarraysize(.@vals);

    if (@menu == 255)
        return -1;

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

    @menuret = .@vals[@menu];
    return @menuret;
}