summaryrefslogtreecommitdiff
path: root/npc/functions/filters.txt
blob: 91e536dc71ad2ce22f57e2e9122ebbde316b32c5 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// TMW2 scripts.
// Authors:
//    Jesusalva
// Description:
//    Several filters

// filter_always( id )
function	script	filter_always	{
    return true;
}

// filter_onlyme( id )
function	script	filter_onlyme	{
    return (getarg(0) == getcharid(3));
}

// filter_notme( id )
function	script	filter_notme	{
    return (getarg(0) != getcharid(3));
}

// filter_sameguild( id )
function	script	filter_sameguild	{
    if (getarg(0) == getcharid(3))
        return true;
    if (getcharid(2) < 1)
        return false;
    return (strcharinfo(2, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(2));
}

// filter_sameguildnotyou( id )
function	script	filter_sameguildnotyou	{
    if (getcharid(2) < 1)
        return false;
    if (getarg(0) == getcharid(3))
        return false;
    return (strcharinfo(2, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(2));
}

// filter_sameparty( id )
function	script	filter_sameparty	{
    if (getarg(0) == getcharid(3))
        return true;
    if (getcharid(1) < 1 && getarg(0) != getcharid(3))
        return false;
    return (strcharinfo(1, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(1));
}

// filter_sameguildorparty( id )
function	script	filter_sameguildorparty	{
    if (getarg(0) == getcharid(3))
        return true;
    if (getcharid(2) < 1 && getcharid(1) < 1)
        return false;
    .@party=(strcharinfo(1, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(1));
    .@guild=(strcharinfo(2, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(2));
    return ((getcharid(1) > 0 && .@party) || (getcharid(2) > 0 && .@guild));
}

// filter_sameguildorpartynotyou( id )
function	script	filter_sameguildorpartynotyou	{
    if (getarg(0) == getcharid(3))
        return false;
    if (getcharid(2) < 1 && getcharid(1) < 1)
        return false;
    .@party=(strcharinfo(1, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(1));
    .@guild=(strcharinfo(2, "~!<mk>@tmw2.org", getarg(0)) == strcharinfo(2));
    return ((getcharid(1) > 0 && .@party) || (getcharid(2) > 0 && .@guild));
}

// filter_hostile( id )
function	script	filter_hostile	{
    //.@type=getunitdata(getarg(0), UDT_TYPE);
    .@type=getunittype(getarg(0));
    .@chkid=getarg(0);

    // Players outside PVP
    if (.@type == UNITTYPE_PC) {
        getmapxy(.@m$, .@x, .@y, .@type, .@chkid);
        if (!ispvpmap(.@m$))
            return false;
        // FIXME: We already have !(filter_sameguildorparty())
        // We might be over-processing this
        // Honor party flag
        if (!getmapflag(.@mapa$, mf_pvp_noparty) &&
             getcharid(1) == getcharid(1, strcharinfo(0, "", .@chkid)))
            return false;
        // Honor guild flag
        if (!getmapflag(.@mapa$, mf_pvp_noguild) &&
             getcharid(2) == getcharid(2, strcharinfo(0, "", .@chkid)))
            return false;
    }

    // Monsters
    if (.@type == UNITTYPE_MOB)
        return true;

    // NPCs
    if (.@type == UNITTYPE_NPC)
        return false;

    // Homunculus
    if (.@type == UNITTYPE_HOM)
        .@chkid=charid2rid(getunitdata(getarg(0), UDT_MASTERCID));

    // Pets
    if (.@type == UNITTYPE_PET)
        .@chkid=getunitdata(getarg(0), UDT_MASTERAID);

    // Mercenaries
    if (.@type == UNITTYPE_MER)
        .@chkid=charid2rid(getunitdata(getarg(0), UDT_MASTERCID));

    // Elementals
    if (.@type == UNITTYPE_ELEM)
        .@chkid=charid2rid(getunitdata(getarg(0), UDT_MASTERCID));

    //debugmes "filter_hostile: Filtering %d (original %d) (BL %d)", .@chkid, getarg(0), .@type;
    // Players (and slaves)
    return !(filter_sameguildorparty(.@chkid));
}

// filter_friendly( id )
function	script	filter_friendly	{
    return !(filter_hostile(getarg(0)));
}

// filter_notboss( id )
function	script	filter_notboss	{
    return (!(getunitdata(getarg(0), UDT_MODE) & MD_BOSS));
}