summaryrefslogtreecommitdiff
path: root/npc/functions/util.txt
blob: d5fe8bc4be3cd0bd6d77d20155b324b0c422082c (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
// Evol functions.
// Authors:
//    Jesusalva
//    Reid
// Description:
//    Util functions


// season_direction({day, month})
//    returns the direction that represents our current season (approximation)
//      DOWN:      Winter, 21/12
//      DOWNLEFT:  Spring, 20/03
//      LEFT:      Summer, 21/06
//      UPLEFT:    Autumn, 22/09

function	script	season_direction	{
    .@current_month = getarg(0, gettime(GETTIME_MONTH));

    if (.@current_month % 3 == 0)
    {
        .@current_day = getarg(1, gettime(GETTIME_DAYOFMONTH));

        switch (.@current_month)
        {
            case MARCH:     .@season_day = 20; break;
            case JUNE:      .@season_day = 21; break;
            case SEPTEMBER: .@season_day = 22; break;
            case DECEMBER:  .@season_day = 21; break;
            default: break;
        }

        .@is_after_season_day = .@current_day >= .@season_day ? 0 : -1;
    }

    return (.@current_month / 3 + .@is_after_season_day) % 4;
}

// This is part of Jesusalva script toolkit to make his life easier when writing
// quests. Many of these are actually redudant functions.

// Four different flavours of setq() to quickly preserve old values
function	script	setq1	{
    //   Quest,     val1     , val2            , val3            , time
    setq getarg(0), getarg(1), getq2(getarg(0)), getq3(getarg(0)), getqtime(getarg(0));
    return;
}

function	script	setq2	{
    //   Quest,     val1           , val2     , val3            , time
    setq getarg(0), getq(getarg(0)), getarg(1), getq3(getarg(0)), getqtime(getarg(0));
    return;
}

function	script	setq3	{
    //   Quest,     val1           , val2            , val3     , time
    setq getarg(0), getq(getarg(0)), getq2(getarg(0)), getarg(1), getqtime(getarg(0));
    return;
}

function	script	setqtime	{
    //   Quest,     val1           , val2            , val3     , time
    setq getarg(0), getq(getarg(0)), getq2(getarg(0)), getq3(getarg(0)), getarg(1);
    return;
}

// Function to quickly disregard part of getmapxy().
// If you use this function too much, you'll lose efficiency, and it'll be better
// to use getmapxy() normally to save to temporary variables.
// Can take one optional argument (unittype argument).
function	script	getmap	{
    if (getmapxy(.@mapName$, .@xpos, .@ypos, getarg(0,0)) != 0)
        return false;
    return .@mapName$;
}

// Returns the player race in plain text
// GETRACE_RACE - returns player race (default)
// GETRACE_SKIN - returns player skin
// GETRACE_FULL - returns player skin + race
// Can take an optional 2nd param with the class
// get_race( {Flag, {Class}} )
function	script	get_race	{
    .@m=getarg(0, GETRACE_RACE);
    .@g=getarg(1, Class);

    // We also allow this to run without player attached for... science.
    if (getarg(1,-1) >= 0)
    {
        setarray .@allraces$, l("Human"), l("Ukar"), l("Kralog"),
         l("Raijin"), l("Kralog"), l("Raijin"), l("Tritan"),
         l("Human"), l("Human"), l("Tritan"), l("Ukar");
        setarray .@allskins$, l("Kaizei"), l("Cave"), l("Fire"),
         l("Light"), l("Frost"), l("Dark"), l("Sea"), l("Argaes"),
         l("Tonori"), l("Lake"), l("Mountain");
    }
    else
    {
        setarray .@allraces$, "Human", "Ukar", "Kralog", "Raijin",
        "Kralog", "Raijin", "Tritan", "Human", "Human", "Tritan", "Ukar";
        setarray .@allskins$, "Kaizei", "Cave", "Fire", "Light",
        "Frost", "Dark", "Sea", "Argaes", "Tonori", "Lake", "Mountain";
    }

    if (.@m == GETRACE_RACE)
        return .@allraces$[.@g];
    else if  (.@m == GETRACE_SKIN)
        return .@allskins$[.@g];
    else
        return .@allskins$[.@g] + " " + .@allraces$[.@g];

}