summaryrefslogtreecommitdiff
path: root/npc/functions/warp.txt
blob: 46c390adb086be13d972f90ae9b44a4aea2ca756 (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
// Evol functions.
// Authors:
//    gumi



// map_exists
//     self-explanatory

function	script	map_exists	{
    return getmapinfo(MAPINFO_ID, getarg(0)) >= 0;
}



// slide_or_warp
//     Slides the player instead of warping, when possible.
// usage:
//     slide_or_warp({<aid>});
//     slide_or_warp(<x>, <y>{, <aid>});
//     slide_or_warp("<map>", <x>, <y>{, <aid>});

function	script	slide_or_warp	{
    if (getargcount() <= 1) {
        .@aid = getarg(1, 0);
    } else {
        if (getargcount() >= 3 && getdatatype(getarg(0)) & DATATYPE_STR) {
            .@map$ = getarg(0);
            .@x = getarg(1);
            .@y = getarg(2);
            .@aid = getarg(3, 0);
        } else {
            .@x = getarg(0);
            .@y = getarg(1);
            .@aid = getarg(2, 0);
        }
    }

    if (!isloggedin(.@aid)) {
        if ((.@aid = playerattached()) == 0) {
            consolemes(CONSOLEMES_DEBUG, "slide_or_warp: no player attached!");
            return false;
        }
    }

    getmapxy(.@pc_map$, .@pc_x, .@pc_y, UNITTYPE_PC, .@aid); // get char location
    .@cid = getcharid(CHAR_ID_CHAR, strcharinfo(PC_NAME, .@aid)); // FIXME: [Hercules] make it so you can pass account id directly to getcharid

    if (getargcount() < 1) {
        warpchar(.@pc_map$, .@pc_x, .@pc_y, .@cid); // no arguments, just refresh
    } else if (.@map$ == .@pc_map$ && (.@pc_x != .@x || .@pc_y != .@y)) {
        slide(.@x, .@y); // same map, slide instead of full warp
        // FIXME: make slide take GID as optional arg
    } else {
        warpchar(.@map$, .@x, .@y, .@cid); // different map, warp to given location
    }
    return true;
}