summaryrefslogtreecommitdiff
path: root/world/map/npc/functions/default_npc_checks.txt
blob: 4ddd00ca1a329305b6d95832bebae3f58ad0777c (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
// Default NPC Checks
// Author: Wushin

// Range
// Map, X, Y, Distance in Tiles
// setarray $@npc_loc, 24, 113, 4;
function|script|PCtoNPCRange|,
{
    set @npc_check, 0;
    set $@Nmap$, getmap() + ".gat";
    set $@Nx1, ($@npc_loc[0] - $@npc_loc[2]);
    set $@Ny1, ($@npc_loc[1] - $@npc_loc[2]);
    set $@Nx2, ($@npc_loc[0] + $@npc_loc[2]);
    set $@Ny2, ($@npc_loc[1] + $@npc_loc[2]);
    if (isin($@Nmap$, $@Nx1, $@Ny1, $@Nx2, $@Ny2))
        goto L_Return;
    set @npc_check, 1;
    goto L_Return;

L_Return:
    return;
}

// Inventory & Weight
// setarray @delitem_names$ Items to delete
// @delitem_counts Counts of Items to delete
// @getitem_names$ Items to get
// @getitem_counts Counts of Items to get
function|script|CheckInventory|,
{
    set @del_loop, 0;
    set @get_loop, 0;
    set @delitem_loop, 0;
    set @getitem_loop, 0;
    set @check_fail, 0;

    if (getarraysize(@delitem_names$))
        goto L_DelItemsLoop;
    goto L_CheckGet;

L_DelItemsLoop:
    if(countitem(@delitem_names$[@delitem_loop]) >= @delitem_counts[@delitem_loop])
        goto L_DelLoopAgain;
    goto L_ReturnMissing;

L_DelLoopAgain:
    if((@delitems_loop + 1) == getarraysize(@delitems_names$))
        goto L_CheckGet;
    set @delitems_loop, (@delitems_loop + 1);
    goto L_DelItemsLoop;

L_CheckGet:
    if (getarraysize(@getitem_names$))
        goto L_CheckWeight;
    goto L_DelCheck;

L_CheckWeight:
    getinventorylist;
    if (@inventorylist_count < (101 - getarraysize(@getitem_names$)))
        goto L_ReturnSpace;
    goto L_GetItemsLoop;

L_GetItemsLoop:
    if (checkweight(@getitem_names$, 1) == 0)
        goto L_GetLoopAgain;
    goto L_ReturnWeight;

L_GetLoopAgain:
    if((@getitems_loop + 1) == getarraysize(@getitems_names$))
        goto L_DelCheck;
    set @getitems_loop, (@getitems_loop + 1);
    goto L_GetItemsLoop;

L_DelCheck:
    if (getarraysize(@delitem_names$))
        goto L_DelLoop;
    goto L_CheckGet2;

L_DelLoop:
    delitem @delitem_names$[@del_loop], @delitem_counts[@del_loop];
    goto L_DelAgain;

L_DelAgain:
    if((@del_loop + 1) == getarraysize(@delitems_names$))
        goto L_GetLoop;
    set @del_loop, (@del_loop + 1);
    goto L_DelLoop;

L_CheckGet2:
    if (getarraysize(@getitem_names$))
        goto L_GetLoop;
    goto L_Return;

L_GetLoop:
    getitem @getitem_names$[@get_loop], @getitem_counts[@get_loop];
    goto L_GetAgain;

L_GetAgain:
    if((@get_loop + 1) == getarraysize(@getitems_names$))
        goto L_Return;
    set @get_loop, (@get_loop + 1);
    goto L_GetLoop;

L_ReturnMissing:
    mes "\"You are missing required items.\"";
    set @check_fail, 1;
    goto L_Return;

L_ReturnWeight:
    mes "\"You need to be carrying less weight.\"";
    next;
    set @check_fail, 1;
    goto L_Return;

L_ReturnSpace:
    mes "\"You need more room in your inventory.\"";
    next;
    set @check_fail, 1;
    goto L_Return;

L_Return:
    cleararray @delitem_names$, "", getarraysize(@delitem_names$);
    cleararray @getitem_names$, "", getarraysize(@getitem_names$);
    return;
}