forked from hayakawakaki/rathena-script-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.c
More file actions
276 lines (236 loc) · 7.51 KB
/
Copy pathFunction.c
File metadata and controls
276 lines (236 loc) · 7.51 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//= Function for accessing npc variables from another NPC without using 'getvariableofnpc' and can have dynamic names
//= Use Cases:
/*
//===== getnpc_var("<Variable Name>",{,<Target NPC>});
**
** .@value = getnpc_var("target_var","npc_name");
** .@value$ = getnpc_var("target_var$","npc_name");
** .@value$ = getnpc_var("target_var$[2]","npc_name");
** .@size = getarraysize(getnpcvar("target_array","npc_name"));
**
//===== setnpc_var("<Variable Name>",<New Value>,{,<Target NPC>});
**
** setnpc_var("target_var",10,"npc_name");
** setnpc_var("target_var$","HELLO","npc_name");
** setnpc_var("target_var$[2]","Change Array Value 2","npc_name");
**
*/
function script getnpc_var {
return getvariableofnpc(getd((compare(getarg(0),".")?"":".") + getarg(0)),getarg(1,strnpcinfo(3)));
}
function script setnpc_var {
set getvariableofnpc(getd((compare(getarg(0),".")?"":".") + getarg(0)),getarg(2,strnpcinfo(3))),getarg(1);
return;
}
//= Function for copying an array from another NPC and return the size of the copied array
//= getnpc_array("<Target Array Variable>",<Copied Array Variable>{,<"Target NPC">});
//= .@array_size = getnpc_array(".target_array",.@temp_array,"npc_name");
function script getnpc_array {
.@type$ = (compare(getarg(0),"$") ? "$" : "");
copyarray getd(".@temp_array" + .@type$ + "[0]"),getnpc_var(getarg(0),getarg(2,strnpcinfo(3))),getarraysize(getnpc_var(getarg(0),getarg(2,strnpcinfo(3))));
.@size = getarraysize(getd(".@temp_array" + .@type$));
if(.@size < 1){
debugmes "getnpc_array : The target array " + getarg(0) + " is empty.";
return 0;
}
for(.@i = 0; .@i < .@size; .@i++)
set getelementofarray(getarg(1),.@i),getd(".@temp_array" + .@type$ + "[" + .@i + "]");
return .@size;
}
//= Basically inarray but for the target npc
//= getnpc_arrindex("<Target Array Variable>",<Search Value>{,<"Target NPC">});
//= .@array_size = getnpc_array(".target_array",.@temp_array,"npc_name");
function script getnpc_arrindex {
return inarray(getnpc_var(getarg(0),getarg(2,strnpcinfo(3))),getarg(1));
}
//= Push an element to the target array and returns the current array size.
function script array_push {
set getelementofarray(getarg(0),(.@size = getarraysize(getarg(0)))), getarg(1);
return .@size;
}
/* Functions for storing/fetching multiple array of data without using unreadable getd
** SprintVar("<Base Array Variable>",<Value>{,<"NPC Name">};
** SprintIndex"<Base Array Variable>",<Value>,<Index>{,<"NPC Name">};
-- Use Cases
set SprintVar(".var", 1), 20;
Equivalent : .var_1 = 20;
.@value = SprintVar(".var", 1); //Returns 20
set SprintVar(".name$, 1), "Hello";
Equivalent : .name_1$ = "Hello";
.@value$ = SprintVar(".name$, 1); //Returns Hello
//= Usage with array_push function
array_push(SprintVar(".var", 1), 30);
.@index_0 = SprintIndex(".var", 1, 0); //Returns 20
.@index_1 = SprintIndex(".var", 1, 1); //Returns 30
//= Usage with getarraysize
.@size = getarraysize(SprintVar(".var", 1)); // Returns 2
*/
function script SprintVar {
return getvariableofnpc(getd(sprintf((compare(getarg(0), "$") ? (delchar(getarg(0), getstrlen(getarg(0)) - 1) + "_%d$") : (getarg(0) + "_%d")), getarg(1))), getarg(2,strnpcinfo(3)));
}
function script SprintIndex {
return getvariableofnpc(getd(sprintf((compare(getarg(0), "$") ? (delchar(getarg(0), getstrlen(getarg(0)) - 1) + "_%d$[%d]") : (getarg(0) + "_%d[%d]")), getarg(1), getarg(2))), getarg(3,strnpcinfo(3)));
}
/* Instance commands shorcuts
instance_warning(<TYPE>);
instance_hide(<NPC Name>,<bool>);
instance_enable(<NPC Name>,<bool>);
instance_event(<NPC Name>,<Event Name>,<Attach Player Bool>);
*/
function script instance_warning {
.@type = (getargcount() < 1 ? 0 : getarg(0));
.@md_name$ = (getargcount() == 2 ? getarg(1,"") : "");
switch(.@type){
case 0:
mes "^FF0000Please note that, any abnormal monster handling inside the instance such as taming is not considered normal and may hinder the instance progress.^000000";
break;
case 1:
mes "^4D4DFFThis place is a memorial dungeon.";
mes "Please form a party and try again.^000000";
mes "To create a party with the following command ^4D4DFF'/organize PARTY NAME'.^000000";
end;
case 2:
dispbottom "The reservation of the instance '" + .@md_name$ + "' has failed due to an active instance.";
break;
case 3:
mes "^FF0000In beginners mode, the player transform into a monster. Please not that existing transformation effect will disappear after entering and proceeding.^000000";
break;
case 4:
mes "^4D4DFFThis place is a memorial dungeon.";
mes "You have to be a party leader to create a memorial dungeon.^000000";
end;
}
return;
}
//= Instance event control so I don't have to type instance_npcname and concatinate something every single time I have to do an event call.
function script instance_hide {
if(getarg(1))
hideonnpc instance_npcname(getarg(0));
else
hideoffnpc instance_npcname(getarg(0));
return;
}
function script instance_enable {
if(getarg(1))
enablenpc instance_npcname(getarg(0));
else
disablenpc instance_npcname(getarg(0));
return;
}
function script instance_event {
if(getarg(2))
doevent instance_npcname(getarg(0)) + "::" + getarg(1);
else
donpcevent instance_npcname(getarg(0)) + "::" + getarg(1);
return;
}
//= Instance variable control because I hate how 'variables breaks my IDE.
function script get_instance_var {
return getd("'" + getarg(0));
}
function script set_instance_var {
setd("'" + getarg(0),getarg(1));
return;
}
function script inc_instance_var {
setd("'" + getarg(0), getd("'" + getarg(0)) + 1);
return;
}
//= Shortcut Functions
function script cloaknpc {
if(getargcount() > 2){
if(getarg(1))
cloakonnpc getarg(0),getarg(2);
else
cloakoffnpc getarg(0),getarg(2);
} else {
if(getarg(1))
cloakonnpc getarg(0);
else
cloakoffnpc getarg(0);
}
return;
}
function script pctalk {
unittalk getcharid(3),strcharinfo(0) + ":" + getarg(0),bc_self;
return;
}
function script pcblock {
if(getargcount() < 2)
setpcblock PCBLOCK_NPC,getarg(0);
else
setpcblock PCBLOCK_NPC,getarg(0),getarg(1);
return;
}
/* Search the index of a value in from another NPC Variable
** npc_resize(<SIZE>);
Sizes :
Size_Small
Size_Medium
Size_Large
-- Use Cases
OnInit:
OnInstanceInit:
npc_resize(Size_Large);
*/
function script npc_resize {
.@npc$ = .@name$ = strnpcinfo(0);
if(instance_live_info(ILI_NAME) != "")
.@npc$ = instance_npcname(.@npc$);
getunitdata getnpcid(0,.@npc$),.@npc;
setnpcdisplay(.@npc$,.@name$,.@npc[UNPC_CLASS],getarg(0));
return;
}
function script mapexists {
return getmapusers(getarg(0));
}
function script create_menu {
return implode(getarg(0),":");
}
function script getday {
switch(getarg(0)) {
case SUNDAY: .@d$ = "Sunday"; break;
case MONDAY: .@d$ = "Monday"; break;
case TUESDAY: .@d$ = "Tuesday"; break;
case WEDNESDAY: .@d$ = "Wednesday"; break;
case THURSDAY: .@d$ = "Thursday"; break;
case FRIDAY: .@d$ = "Friday"; break;
case SATURDAY: .@d$ = "Saturday"; break;
}
return .@d$;
}
function script safe_rand {
if ( !getargcount() )
return;
.@min = getarg(0);
if ( getargcount() > 1 )
.@max = getarg(1);
else {
if ( .@min == 0 ) {
errormes "safe_rand : Random value can't be 0.";
end;
}
if ( .@min == 1 )
return 0;
else
return rand(.@min);
}
if ( .@min == .@max )
return .@min;
if ( .@max < .@min ) {
.@temp = .@min;
.@min = .@max;
.@max = .@temp;
}
return rand(.@min, .@max);
}
function script validate_itemid {
return getiteminfo(getarg(0), ITEMINFO_TYPE);
}
//= DUMMY NPC's
- script(CLOAKED) dummynpc -1,{
end;
}
- script dummynpc2 -1,{
end;
}