· 8 years ago · Apr 19, 2018, 10:46 PM
1//===== rAthena Script =======================================
2//= Yuchinin Common Library
3//===== By: ==================================================
4//= Yuchinin
5//===== Current Version: =====================================
6//= 2.4.1
7//===== Compatible With: =====================================
8//= rAthena Project
9//===== Description: =========================================
10//= A common useful function I wrote to make my life easier.
11//= Most of my release script will need this to work
12//=====******** Note ********=================================
13//= This will be the core of my other script.
14//= Better let it load first before adding my other script.
15//===== Additional Comments: =================================
16//= 1.0 Initial script.
17//= 1.1 Change function arrdel from using 'value' to 'index'
18//= 1.2 Fixed sql query bug
19//= 1.3 Added Url, npcmes
20//= 1.4 Added strcharinfo2 to avoid offline player return empty
21//= String
22//= 1.4a Fixed arrdel
23//= 1.4b Fixed arrfind
24//= 1.4c Add arrdel, arrfind notsensitive bool
25//= 1.5 Add answer_chk to check input value from define value
26//= 1.5a Optimize npcindistance
27//= 1.5b Try to fix npcindistance
28//= 1.6 Added marketshopcountitem, marketshopdelitem
29//= 1.7 Added itemcheck, varcheck
30//= 1.8 Added itemname
31//= 1.9 Revamped itemcheck and varcheck
32//= 1.9a Comment out the debugmes of function arradd
33//= 2.0 Added running Marquee
34//= 2.1 Added function itemtype to return item type in string
35//= 2.2 Added getcharid2 to counter getcharid which need attached
36//= 2.3 Added arrfind_db and arrget_db
37//= 2.3 Added elementname2id and elementid2name
38//= 2.3a Added sortstringarray
39//= 2.3b Added FAKE_EFFECT npc
40//= 2.4 Added itembreak (Use in Item Hunting Game)
41//= 2.4.1 Added explosion (Use in Cannon game)
42//============================================================
43
44- script CommonInitialize -1,{
45OnInit:
46 delmonsterdrop 1792,18503;
47 delmonsterdrop 1792,18503;
48 delmonsterdrop 1792,12326;
49 delmonsterdrop 1792,603;
50 delmonsterdrop 1792,617;
51}
52
53function script abs {
54 .@val = getarg(0);
55 if(.@val<0) .@val *= -1;
56 return .@val;
57}
58
59function script monster_fall {
60 .@map$ = getarg(0);
61 .@mapx = getarg(1);
62 .@mapy = getarg(2);
63 .@mobid = getarg(3,1002);
64 .@radius = getarg(4,0);
65 if(.@radius>2) .@radius = 2;
66 if(getmonsterinfo(.@mobid,MOB_NAME)=="null") .@mobid = 1002;
67 for(.@i=.@mapx-.@radius;.@i<=.@mapx+.@radius;.@i++){
68 for(.@j=.@mapy-.@radius;.@j<=.@mapy+.@radius;.@j++){
69 if( checkcell(.@map$,.@i,.@j,cell_chkpass) ){
70 .@gid = monster(.@map$,.@i,.@j,"Bomb",.@mobid,1);
71 unitkill .@gid;
72 }
73 }
74 }
75 return;
76}
77
78function script monster_bomb {
79 .@map$ = getarg(0);
80 .@mapx = getarg(1);
81 .@mapy = getarg(2);
82 .@power = getarg(3,100);
83 .@mobid = getarg(4,1792);
84 .@radius = getarg(5,0);
85 if(.@radius>2) .@radius = 2;
86 if(getmonsterinfo(.@mobid,MOB_NAME)=="null") .@mobid = 1792;
87 for(.@i=.@mapx-.@radius;.@i<=.@mapx+.@radius;.@i++){
88 for(.@j=.@mapy-.@radius;.@j<=.@mapy+.@radius;.@j++){
89 if( checkcell(.@map$,.@i,.@j,cell_chkpass) ){
90 .@gid = monster(.@map$,.@i,.@j,"Bomb",.@mobid,1);
91 if(.@power>0) setunitdata .@gid,UMOB_MAXHP,.@power;
92 unitskilluseid .@gid,173,1,.@gid,-99;
93 }
94 }
95 }
96 return;
97}
98
99function script explosion {
100 .@map$ = getarg(0);
101 .@mapx = getarg(1);
102 .@mapy = getarg(2);
103 .@power = getarg(3,100);
104 if( !checkcell(.@map$,.@mapx,.@mapy,cell_chkpass) ) return;
105 setnpcdisplay("FAKE_EFFECT",139);
106 unitwarp getnpcid(0,"FAKE_EFFECT"),.@map$,.@mapx,.@mapy;
107 setunitdata getnpcid(0,"FAKE_EFFECT"),UNPC_MAXHP,.@power;
108 unitskilluseid getnpcid(0,"FAKE_EFFECT"),173,1,getnpcid(0,"FAKE_EFFECT"),-99;
109 return;
110}
111
112function script tempeffect {
113 .@ef = getarg(0);
114 .@m$ = getarg(1);
115 .@mx = getarg(2);
116 .@my = getarg(3);
117 //dispbottom "tempeffect: Try to show effect "+.@ef+" at "+.@m$+","+.@mx+","+.@my;
118 //if( !checkcell(.@m$,.@mx,.@my,cell_chkpass) ) return;
119 setnpcdisplay("FAKE_EFFECT",139);
120 unitwarp getnpcid(0,"FAKE_EFFECT"),.@m$,.@mx,.@my;
121 callfunc("setVariable",".effect",.@ef,"FAKE_EFFECT");
122 donpcevent "FAKE_EFFECT::OnEffect";
123 return;
124}
125
126function script tempsoundeffect {
127 .@ef$ = getarg(0);
128 .@m$ = getarg(1);
129 .@mx = getarg(2);
130 .@my = getarg(3);
131 //dispbottom "tempeffect: Try to show effect "+.@ef+" at "+.@m$+","+.@mx+","+.@my;
132 if( !checkcell(.@m$,.@mx,.@my,cell_chkpass) ) return;
133 setnpcdisplay("FAKE_SOUND",139);
134 unitwarp getnpcid(0,"FAKE_SOUND"),.@m$,.@mx,.@my;
135 callfunc("setVariable",".effect$",.@ef$,"FAKE_SOUND");
136 donpcevent "FAKE_SOUND::OnEffect";
137 return;
138}
139
140prt_fild08,123,317,4 script FAKE_EFFECT 139,{
141end;
142OnEffect:
143 if(.effect) specialeffect(.effect);
144}
145
146prt_fild08,123,317,4 script FAKE_SOUND 139,{
147end;
148OnEffect:
149 if(.effect$!="") soundeffectall .effect$,0;
150}
151
152function script elementid2name {
153 setarray .@elementlist$,"Neutral","Water","Earth","Fire","Wind","Poison","Holy","Dark","Ghost","Undead";
154 return .@elementlist$[getarg(0)];
155}
156
157function script elementname2id {
158 setarray .@elementlist$,"Neutral","Water","Earth","Fire","Wind","Poison","Holy","Dark","Ghost","Undead";
159 for(.@x=0;.@x<getarraysize(.@elementlist$);.@x++){
160 if(.@elementlist$[.@x]==getarg(0)) return .@x;
161 }
162 return -1;
163}
164
165function script arrfind_db {
166 .@arrname$ = getarg(0);
167 .@arrfind$ = getarg(1);
168 for(.@x=0;.@x<getarraysize(getd(.@arrname$));.@x++){
169 explode(.@T$,getd(.@arrname$+"["+.@x+"]"),"|");
170 if(.@T$[0]==.@arrfind$) return .@x;
171 }
172 return -1;
173}
174
175function script arrget_db {
176 .@arrname$ = getarg(0);
177 .@index1 = getarg(1);
178 .@index2 = getarg(2);
179 explode(.@T$,getd(.@arrname$+"["+.@index1+"]"),"|");
180 return .@T$[.@index2];
181}
182
183//=========================================
184//= Marquee(<"string">,{<delay>})
185//=========================================
186function script Marquee {
187 .@str$ = " "+getarg(0);
188 .@delay = getarg(1,100);
189 do{
190 .@str$ = delchar(.@str$,0);
191 delwaitingroom;
192 waitingroom .@str$,0;
193 sleep .@delay;
194 }while(getstrlen(.@str$));
195 return;
196}
197
198//=========================================
199//= CStr(<"string to change color">,{<"color name">})
200//= return string with selected color
201//=========================================
202function script CStr {
203setarray .color_str$,"BLACK","RED","GREEN","BLUE","YELLOW","TEAL","PURPLE","GRAY","WHITE","BROWN","SILVER","GOLD","MITHRIL","NEUTRAL","WATER","EARTH","FIRE","WIND";
204setarray .color_code$,"000000","FF0000","04B404","0000FF","FFFF00","00FFFF","FF00FF","C0C0C0","FFFFFF","996600","999999","FFCC00","CCCCCC","777777","0000BB","cc5500","FF0000","7BCC70";
205.@color_in$ = getarg(1,"BLACK");
206.@str$ = getarg(0,"null");
207for(.@x=0; .@x < getarraysize(.color_str$); .@x++){
208 if(strtoupper(.@color_in$) == .color_str$[.@x]){
209 .@color$ = .color_code$[.@x];
210 break;
211 }
212}
213if(.@color$ == "") .@color$ = .color_code$[0]; // default to black if color not found in array
214return "^"+.@color$+.@str$+"^000000";
215}
216
217//=========================================
218//= CZeny(<zeny>,{<"delimiter">,<"symbol">})
219//= return ease look zeny string
220//=========================================
221function script CZeny {
222 .@number$ = getarg(0);
223 .@delimiter$ = getarg(1,",");
224 .@symbol$ = getarg(2,"z");
225 .@length = getstrlen(.@number$);
226 .@numberSeparated$ = "";
227 if ("" != .@number$ && 3 < .@length) {
228 while (.@length > 3) {
229 .@numberSeparated$ = ("" != .@numberSeparated$) ? substr(.@number$, .@length - 3, .@length - 1) + .@delimiter$ + .@numberSeparated$ : substr(.@number$, .@length - 3, .@length - 1);
230 .@length = .@length - 3;
231 }
232 .@numberSeparated$ = substr(.@number$, 0, .@length - 1) + .@delimiter$ + .@numberSeparated$;
233 }
234 return ((.@numberSeparated$ != "") ? .@numberSeparated$ : .@number$)+.@symbol$;
235}
236
237function script findinventoryitem {
238 getinventorylist;
239 for(.@x=0;.@x<inventorylist_count;.@x++){
240 if(getarg(0)==@inventorylist_id[.@x]) return .@x;
241 }
242 return -1;
243}
244
245// int getmarketvar(int itemid, string var, string marketname)
246function script getmarketvar {
247 .@marketname$ = getarg(2);
248 .@sql$ = "select "+getarg(1)+" from market where name = '"+.@marketname$+"' AND nameid = "+getarg(0);
249 //debugmes .@sql$;
250 .@count = query_sql(.@sql$,.@val);
251 if(.@count <= 0) return 0;
252 //debugmes getitemname(getarg(0))+": "+getarg(0)+" = "+.@val;
253 return .@val;
254}
255
256//===================================
257//= marketshopcountitem(<itemid>,"<marketname>")
258//= return item amount of the market npc
259//===================================
260function script marketshopcountitem {
261 .@sql$ = "select amount from market where nameid = "+getarg(0)+" AND name = '"+getarg(1)+"'";
262 .@size = query_sql(.@sql$,.@amt);
263 if(.@size <= 0){
264 debugmes "marketshopcountitem: .@sql$ "+.@sql$;
265 debugmes "marketshopcountitem: item id "+getarg(0)+" or market named "+getarg(1)+" not found!";
266 return 0;
267 }
268 if(.@amt > 0) return .@amt;
269 return 0;
270}
271
272//===================================
273//= marketshopcountitem2(<itemid>,"<townname>")
274//= return item amount of the town market npc
275//===================================
276function script marketshopcountitem2 {
277 return marketshopcountitem(getarg(0),getarg(1)+"#"+getiteminfo(getarg(0),2));
278}
279
280//===================================
281//= marketshopadditem(<itemid>,<amount>,"<marketname>"{,price})
282//===================================
283function script marketshopadditem {
284 .@id = getarg(0);
285 .@amt = getarg(1);
286 .@market$ = getarg(2);
287 .@price = getarg(3,0);
288 .@amtfound = marketshopcountitem(.@id,.@market$);
289 if(.@amtfound){
290 npcshopupdate .@market$,.@id,.@price,.@amt+.@amtfound;
291 showscript "Add "+.@amt+" x "+getitemname(.@id)+" = "+(.@amt+.@amtfound),getnpcid(0);
292 }else{
293 npcshopadditem .@market$,.@id,.@price,.@amt;
294 showscript "Create "+.@amt+" x "+getitemname(.@id),getnpcid(0);
295 }
296 return;
297}
298
299//===================================
300//= marketshopadditem2(<itemid>,<amount>,"<town>"{,price})
301//===================================
302function script marketshopadditem2 {
303 .@id = getarg(0);
304 .@amt = getarg(1);
305 .@market$ = getarg(2);
306 .@price = getarg(3,0);
307 marketshopadditem(.@id,.@amt,.@market$+"#"+getiteminfo(.@id,2),.@price);
308 return;
309}
310
311//===================================
312//= marketshopdelitem(<itemid>,<amount>,"<marketname>")
313//= return 1 on success
314//= return 0 on error
315//===================================
316function script marketshopdelitem {
317 .@sql$ = "select amount from market where nameid = "+getarg(0)+" AND name = '"+getarg(2)+"'";
318 .@size = query_sql(.@sql$,.@amt);
319 if(.@size <= 0){
320 debugmes "marketshopdelitem: .@sql$ "+.@sql$;
321 debugmes "marketshopdelitem: item id "+getarg(0)+" or market named "+getarg(2)+" not found!";
322 return 0;
323 }
324 .@amt = marketshopcountitem(getarg(0),getarg(2));
325 if(getarg(1) >= .@amt){
326 npcshopdelitem(getarg(2),getarg(0));
327 }else{
328 npcshopupdate getarg(2),getarg(0),0,.@amt-getarg(1);
329 }
330 return 1;
331}
332
333//===================================
334//= marketshopclear("<marketname>")
335//= clear all item on marketshop
336//===================================
337function script marketshopclear {
338 .@sql$ = "select nameid from market where name = '"+getarg(0)+"'";
339 .@size = query_sql(.@sql$,.@nameid);
340 if(.@size <= 0){
341 debugmes "marketshopclear: market named "+getarg(0)+" is empty. Nothing to clear.";
342 return 0;
343 }
344 for(.@x=0;.@x<.@size;.@x++){
345 npcshopupdate getarg(0),.@nameid[.@x],0,0;
346 }
347 showscript "Market Cleared",getnpcid(0);
348 return;
349}
350
351//===================================
352//= getcharid2(<mode>,"<charname>")
353//= work also on offline character
354//= to counter getcharid
355//= mode:
356//= 0 - Character ID
357//= 1 - Party ID
358//= 2 - Guild ID
359//= 3 - Account ID
360//= 4 - Clan ID
361//===================================
362function script getcharid2 {
363 .@size = query_sql("select char_id, party_id, guild_id, account_id, clan_id from `char` where name = '"+getarg(1)+"'",.@charid,.@pid,.@gid,.@aid,.@cid);
364 if(.@size < 0) return 0;
365 if(getarg(0)==0) return .@charid;
366 else if(getarg(0)==1) return .@pid;
367 else if(getarg(0)==2) return .@gid;
368 else if(getarg(0)==3) return .@aid;
369 else if(getarg(0)==4) return .@cid;
370 return 0;
371}
372
373//===================================
374//= strcharinfo2(<mode>,<charid>)
375//= work also on offline character
376//= to counter strcharinfo
377//= mode:
378//= 0 = return char name
379//= 1 = return party name
380//= 2 = return guild name
381//===================================
382function script strcharinfo2 {
383 .@size = query_sql("select name, party_id, guild_id from `char` where char_id = "+getarg(1),.@n$,.@p,.@g);
384 if(.@size < 0) return "";
385 if(getarg(0)==0) return .@n$;
386 else if(getarg(0)==1){
387 return getpartyname(.@p);
388 }else if(getarg(0)==2){
389 return getguildname(.@g);
390 }
391 return "";
392}
393
394//===================================
395//= unitwalkauto(<unitid>,<x>,<y>)
396//= walk character in npc <distance>
397//===================================
398function script unitwalkauto {
399 @rid = getarg(0,getcharid(3));
400 @x = getarg(1);
401 @y = getarg(2);
402 getmapxy(.@m$,.@x,.@y,0);
403 if(!checkcell( .@m$,@x,@y,cell_chkpass )){
404 //dispbottom "Coordinate not exists!";
405 return;
406 }
407 @auto_walk = 1;
408 viewpoint 1,@x,@y,1,0xFF0000;
409 do{
410 //dispbottom "auto walking to x = "+@x+" y = "+@y;
411 unitwalk @rid,@x,@y,strnpcinfo(3)+"::OnReach";
412 sleep2 1500;
413 }while(@auto_walk);
414 dispbottom "stop auto walking...";
415 return;
416}
417
418//===================================
419//= walktonpc({<unitid>,<distance>})
420//= walk character in npc <distance>
421//===================================
422function script walktonpc {
423 .@rid = getarg(0,getcharid(3));
424 .@distance = getarg(1,1);
425 getmapxy(.@mc$,.@xc,.@yc,0);
426 getmapxy(.@mn$,.@xn,.@yn,1);
427 if(.@xc > .@xn) .@xx = .@xn + .@distance;
428 else if(.@xc < .@xn) .@xx = .@xn - .@distance;
429 else .@xx = .@xn;
430 if(.@yc > .@yn) .@yy = .@yn + .@distance;
431 else if(.@yc < .@yn) .@yy = .@yn - .@distance;
432 else .@yy = .@yn;
433 unitwalk .@rid,.@xx,.@yy;
434 return;
435}
436
437//===================================
438//= npcindistance(<distance>)
439//= check if distance with npc smaller or equal to <distance>
440//= return to the caller
441//= else walk in npc <distance>
442//===================================
443function script npcindistance {
444 .@distance = getarg(0,1);
445 getmapxy(.@mc$,.@xc,.@yc,0);
446 getmapxy(.@mn$,.@xn,.@yn,1);
447 .@d = distance(.@xc,.@yc,.@xn,.@yn);
448 //debugmes "distance = "+.@d;
449 while(.@d > .@distance){
450 walktonpc(getcharid(3),.@distance);
451 sleep2 1000;
452 getmapxy(.@mc$,.@xc,.@yc,0);
453 getmapxy(.@mn$,.@xn,.@yn,1);
454 .@d = distance(.@xc,.@yc,.@xn,.@yn);
455 };
456 return;
457}
458
459function script display {
460 .@str$ = getarg(0,"");
461 delwaitingroom strnpcinfo(3);
462 if(.@str$!="") waitingroom .@str$,0,strnpcinfo(3);
463 return;
464}
465
466//===================================
467//= getVariable(<"npc variable name">,{"<owner>"})
468//= return variable value
469//= owner will be calling npc if omitted
470//===================================
471function script getVariable {
472 return getvariableofnpc(getd(getarg(0)),getarg(1,strnpcinfo(3)));
473}
474
475//===================================
476//= Prizer function (npc variable name)
477- script getvarilbprizetwitch -1,{
478OnWhisperGlobal:
479input .@itemid;
480input .@amount;
481getitem .@itemid,.@amount;
482
483end;
484}
485//===================================
486//= setVariable(<"npc variable name">,<val>,{<"owner">})
487//= set variable value
488//= owner will be calling npc if omitted
489//===================================
490function script setVariable {
491 set getvariableofnpc(getd(getarg(0)),getarg(2,strnpcinfo(3))),getarg(1);
492 return;
493}
494
495//===================================
496//= arradd("<arrayname>",<value>,{<"owner">})
497//= add value to array
498//= owner will be calling npc if omitted
499//===================================
500function script arradd {
501 .@size = getarraysize(getVariable(getarg(0),getarg(2,strnpcinfo(3))));
502 //debugmes ".@size = "+.@size;
503 setVariable(getarg(0)+"["+.@size+"]",getarg(1),getarg(2,strnpcinfo(3)));
504 .@size2 = getarraysize(getVariable(getarg(0),getarg(2,strnpcinfo(3))));
505 //debugmes ".@size2 = "+.@size2;
506 if(.@size==.@size2) return 0;
507 return getarg(1);
508}
509
510//===================================
511//= arrdel("<arrayname>",<index>,{<"owner">})
512//= delete index from array
513//= owner will be calling npc if omitted
514//===================================
515function script arrdel {
516 .@size = getarraysize(getVariable(getarg(0),getarg(2,strnpcinfo(3))));
517 deletearray getVariable(getarg(0)+"["+getarg(1)+"]",getarg(2,strnpcinfo(3))),1;
518/* for(.@x=0;.@x < .@size;.@x++){
519 if( getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3))) == getarg(1) ){
520 deletearray getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3))),1;
521 //debugmes getarg(1)+" delete from "+getarg(0);
522 return getarg(1);
523 }
524 }
525*/
526 return 0;
527}
528
529//===================================
530// arrhas("<arrayname>",<value>,{<"owner">,<notsensitive>})
531//= check if value in array
532//= return 1 if in else return 0
533//===================================
534function script arrhas {
535 .@size = getarraysize(getVariable(getarg(0),getarg(2,strnpcinfo(3))));
536 for(.@x=0;.@x < .@size;.@x++){
537 //dispbottom "Compare "+getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3)))+" == "+getarg(1);
538 if(getarg(3,0)){
539 if( strtolower(getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3)))) == strtolower(getarg(1)) ) return 1;
540 }else{
541 if( getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3))) == getarg(1) ) return 1;
542 }
543
544 }
545 return 0;
546}
547
548//===================================
549// arrfind("<arrayname>",<value>,{<"owner">,<notsensitive>})
550//= return first found value index in array
551//= return -1 if not found
552//===================================
553function script arrfind {
554 .@size = getarraysize(getVariable(getarg(0),getarg(2,strnpcinfo(3))));
555 for(.@x=0;.@x < .@size;.@x++){
556 //dispbottom "Compare "+getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3)))+" == "+getarg(1);
557 if(getarg(3,0)){
558 if( strtolower(getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3)))) == strtolower(getarg(1)) ) return .@x;
559 }else{
560 if( getVariable(getarg(0)+"["+.@x+"]",getarg(2,strnpcinfo(3))) == getarg(1) ) return .@x;
561 }
562 }
563 return -1;
564}
565
566//===================================
567// arrselect("<arrayname>",{<"label">,"<owner>"})
568//= return selected array value after selection
569//= label add before selection
570//= owner will be calling npc if omitted
571//===================================
572function script arrselect {
573 .@blist$ = "25003";
574 .@arrName$ = getarg(0);
575 .@owner$ = getarg(2,strnpcinfo(3));
576 .@label$ = getarg(1,"");
577 .@size = getarraysize(getVariable(.@arrName$,.@owner$));
578 .@m$ = "";
579 for(.@x=0;.@x<.@size;.@x++){
580 .@m$ = .@m$+.@label$+getVariable(.@arrName$+"["+.@x+"]",.@owner$)+":";
581 }
582 return getVariable(.@arrName$+"["+(select(.@m$)-1)+"]",.@owner$);
583}
584
585//==============================
586//= UpperFirst("<string>")
587//= return string with first string capital
588//==============================
589function script UpperFirst {
590 .@s$ = getarg(0);
591 return Strtoupper(charat(.@s$,0)) + delchar(.@s$,0);
592 //return setchar(.@s$, charat(.@s$,0), 0);
593}
594
595//group_chk("variable",valuetocompare{,mode})
596function script group_chk {
597 .@mode = getarg(2,0);
598 .@count = 0;
599 .@num = 0;
600 if(!.@mode){
601 getpartymember getcharid(1),1;
602 .@num = $@partymembercount;
603 for(.@x=0;.@x<.@num;.@x++){
604 if(getvar(getd(getarg(0)),$@partymembercid[.@x]) >= getarg(1)) .@count++;
605 }
606 }else{
607 getguildmember getcharid(2),1;
608 .@num = $@guildmembercount;
609 for(.@x=0;.@x<.@num;.@x++){
610 if(getvar(getd(getarg(0)),$@guildmembercid[.@x]) >= getarg(1)) .@count++;
611 }
612 }
613 if(.@count >= .@num) return 1;
614 return 0;
615}
616
617//===================================
618//= answer_chk(<"str1:str2:...">/<"str1|str2">)
619//= delimeter:
620//= ":" only need to meet any of these
621//= "|" will need to meet all of these inside (no need in order)
622//= return 1 if condition meet
623//= return 0 if condition not meet
624//===================================
625function script answer_chk {
626 deletearray @T$,getarraysize(@T$);
627 explode(@T$,getarg(0),":");
628 @size = getarraysize(@T$);
629 if(!compare(getarg(0),"|")){
630 input @in$;
631 for(.@i=0;.@i<@size;.@i++){
632 if(strtolower(@in$)==@T$[.@i]) return 1;
633 }
634 }else{
635 .@prefix$ = ".list";
636 .@char$ = strcharinfo(0)+"$"; // result will be .answerlist+charname+$ = .answerlistGM01$
637 .@var$ = .@prefix$+.@char$;
638 deletearray @T$,getarraysize(@T$);
639 explode(@T$,getarg(0),"|");
640 @size = getarraysize(@T$);
641 @count = 0;
642 for(.@i=0;.@i<@size;.@i++){
643 arradd(.@var$,@T$[.@i]);
644 }
645 for(.@i=0;.@i<@size;.@i++){
646 input @in$;
647 if(arrhas(.@var$,@in$,strnpcinfo(3),1)){
648 @count++;
649 mes "["+@count+"/"+@size+"] "+UpperFirst(@in$);
650 arrdel(.@var$,arrfind(.@var$,@in$,strnpcinfo(3),1));
651 }else{
652 return 0;
653 }
654 }
655 if(@count >= @size) return 1;
656 }
657 return 0;
658}
659
660// sortstringarray("<arrname>"{,<mode>})
661function script sortstringarray {
662 .@varname$ = getarg(0);
663 .@mode = getarg(1,0); // 0 ascending , 1 descending
664 copyarray .@temparr$[0],getVariable(.@varname$+"[0]"),getarraysize(getVariable(.@varname$));
665 setarray .@T$,"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z";
666 for( .@x=(!.@mode?0:getarraysize(.@T$)-1) ; (!.@mode?.@x<getarraysize(.@T$):.@x>=0) ; .@x+=(!.@mode?1:-1) ){
667 for(.@y=0;.@y<getarraysize(.@temparr$);.@y++){
668 if( strtoupper(charat(.@temparr$[.@y],0)) == strtoupper(.@T$[.@x]) ){
669 .@SortedString$[getarraysize(.@SortedString$)] = .@temparr$[.@y];
670 deletearray .@temparr$[.@y],1;
671 .@y--;
672 }
673 }
674 if(!getarraysize(.@temparr$)) break; // stop sorting if no more item left
675 }
676 for(.@x=0;.@x<getarraysize(.@SortedString$);.@x++)
677 setVariable(.@varname$+"["+.@x+"]",.@SortedString$[.@x]);
678 return;
679}
680
681function script BubbleComb {
682// BubbleComb(arr[,type]); Sorts the given array (type 1 = ascending (default); 2 = descending)
683 set .@Type,(getarg(1,1) == 2 ? -1 : 1);
684 set .@Gap,set(.@Size,getarraysize(getarg(0)));
685 do {
686 if(.@Gap>1) set .@Gap,(.@Gap*100)/140;
687 set .@Swap,0;
688 for(set .@i,0; (.@i+.@Gap)<.@Size; set .@i,.@i+1){
689 sleep( (.@i%1024==0)*20 );
690 if(getelementofarray(getarg(0),.@i)*.@Type > getelementofarray(getarg(0),.@i+.@Gap)*.@Type){
691 set .@tmp,getelementofarray(getarg(0),.@i);
692 set getelementofarray(getarg(0),.@i),getelementofarray(getarg(0),.@i+.@Gap);
693 set getelementofarray(getarg(0),.@i+.@Gap),.@tmp;
694 set .@Swap,1;
695 }
696 }
697 } while(.@Swap || .@Gap>1);
698 return;
699}
700
701//=========================================
702//= getpercent(<currentval>,<maxval>)
703//= return percent rate
704//=========================================
705function script getpercent {
706 .@current = getarg(0);
707 .@max = getarg(1);
708 if(!.@current) return 0;
709 return .@current*100/.@max;
710}
711
712function script getpercentbar {
713 .@current = getarg(0,0);
714 .@max = getarg(1,100);
715 .@color1$ = getarg(2,"GREEN");
716 .@color2$ = getarg(3,"RED");
717 .@char$ = "l";
718 .@dot = 4;
719 if(.@current>.@max) .@current = .@max;
720 if(!.@current || .@max<0){
721 for(.@x=0;.@x<=6*.@dot;.@x++){
722 set .@t1$,.@t1$+.@char$;
723 }
724 return callfunc("CStr",.@t1$,.@color2$)+" [ 0% ]";
725 }
726 .@cal = .@current*100/.@max;
727 for(.@x=0;.@x<.@cal/.@dot;.@x++){
728 set .@t1$,.@t1$+.@char$;
729 .@c++;
730 }
731 for(.@x=0;.@x<((100/.@dot)-.@c);.@x++){
732 set .@t2$,.@t2$+.@char$;
733 }
734 return callfunc("CStr",.@t1$,.@color1$)+callfunc("CStr",.@t2$,.@color2$)+" [ "+callfunc("CStr",.@cal)+"% ]";
735}
736
737//=========================================
738//= getRemain(<sec>,{<langtype>})
739//= return remaining time string
740//=========================================
741function script getRemain {
742 .@timeL = getarg(0);
743 .@lang = getarg(1,0);
744 setarray .@day$," Day "," “ْ ";
745 setarray .@hour$," Hour "," ژ†";
746 setarray .@min$," Min "," •ھ ";
747 setarray .@sec$," Sec "," •b ";
748 if(((((.@timeL)/60)/60)/24)>0){
749 return (((((.@timeL)/60)/60)/24)>0?((((.@timeL)/60)/60)/24)+.@day$[.@lang]:"");
750 }
751 //.@outstr$ = .@outstr$+(((((.@timeL)/60)/60)/24)>0?((((.@timeL)/60)/60)/24)+" Day ":"");
752 .@outstr$ = .@outstr$+((((.@timeL)/60)/60)>0?(((.@timeL)/60)/60)+.@hour$[.@lang]:"");
753 .@outstr$ = .@outstr$+((((.@timeL)/60)%60)>0?(((.@timeL)/60)%60)+.@min$[.@lang]:"");
754 .@outstr$ = .@outstr$+(((.@timeL)%60)>0?((.@timeL)%60)+.@sec$[.@lang]:"");
755 return .@outstr$;
756}
757
758function script showscript2 {
759 showscript getarg(0),getcharid(3);
760 return;
761}
762
763//=========================================
764//= npcmes(<"npcname">,"mes1:mes2|mes1:mes2")
765//= npcmes("Kafra","Hello adventurer, how are you?:This is my 2rd message.|Hmm... ok..:See you soon.|Bye.")
766//= after the delimiter | will auto next
767//=========================================
768function script npcmes {
769 .@n$ = getarg(0);
770 deletearray .@T$,getarraysize(.@T$);
771 explode(.@T$,getarg(1),"|");
772 for(.@x=0;.@x<getarraysize(.@T$);.@x++){
773 mes .@n$;
774 deletearray .@TT$,getarraysize(.@TT$);
775 explode(.@TT$,.@T$[.@x],":");
776 for(.@y=0;.@y<getarraysize(.@TT$);.@y++){
777 mes .@TT$[.@y];
778 }
779 if(.@x+1 < getarraysize(.@T$)) next;
780 }
781 return;
782}
783
784//=========================================
785//= Navi(<"name">,<"mapname">{,< x >,< y >})
786//= return string with navigation added
787//=========================================
788function script Navi {
789 .@name$ = getarg(0);
790 .@map$ = getarg(1);
791 .@x = getarg(2,0);
792 .@y = getarg(3,0);
793 return "<NAVI>"+.@name$+"<INFO>"+.@map$+","+.@x+","+.@y+",0,000,1</INFO></NAVI>";
794}
795
796//=========================================
797//= Url(<"url">{,<"Url Name">})
798//= return url link which open in ingame browser
799//=========================================
800function script Url {
801 return "<URL>"+getarg(1,getarg(0))+"<INFO>"+getarg(0)+",300,300</INFO></URL>";
802}
803
804//=========================================
805//= itembreak(<itemid>,<rate>)
806//= delete worn out item with rate
807//=========================================
808function script itembreak {
809 if(rand(1,10000)<=getarg(1)){
810 showscript getitemname(getarg(0))+" worn out!";
811 delitem getarg(0),1;
812 }
813 return;
814}
815
816//=========================================
817//= itemname(<itemid>)
818//= return item string using internal client function
819//=========================================
820function script itemname {
821 .@id = getarg(0);
822 return "^nItemID^"+.@id;
823}
824
825//=========================================
826//= Itemlink(<itemid>)
827//= return item string with itemlink added
828//=========================================
829function script Itemlink {
830 .@id = getarg(0);
831 .@showslot = getarg(1,0);
832 .@slot = getitemslots(.@id);
833 return "<ITEM>"+(.@slot&&.@showslot?getitemname(.@id)+"["+.@slot+"]":getitemname(.@id))+"<INFO>"+.@id+"</INFO></ITEM>";
834}
835
836function script itemtype {
837 .@id = getarg(0);
838 setarray .ItemType$,"Healing","","Usable","Etc","Equipment","Weapon","Card","Pet Egg","Pet Equipment","","Ammunition","Consumable","Shadow Equipment","","","","","","Box";
839 return .ItemType$[getiteminfo(.@id,2)];
840}
841
842function script itemcheck {
843 .@iteminfo$ = getarg(0);
844 .@mode = getarg(1,0);
845 .@mul = getarg(2,1);
846 if(.@iteminfo$ == "") return 2;
847 explode(.@T$,.@iteminfo$,"|");
848 if(!.@mode){
849 mes "Item Requirement:";
850 .@bool = 1;
851 for(.@x=0;.@x<getarraysize(.@T$);.@x++){
852 explode(.@TT$,.@T$[.@x],":");
853 .@id = atoi(.@TT$[0]);
854 .@amt = atoi(.@TT$[1])*.@mul;
855 if(countitem(.@id) < .@amt){
856 mes " > "+Itemlink(.@id,1)+" ["+CStr(countitem(.@id),"red")+"/"+.@amt+"]";
857 .@bool = 0;
858 }else{
859 mes " > "+Itemlink(.@id,1)+" ["+CStr(countitem(.@id),(countitem(.@id)?"green":"red"))+"/"+(.@amt==0?"-":.@amt)+"]";
860 if(countitem(.@id)==0) .@bool = 0;
861 }
862 }
863 return .@bool;
864 }else{
865 for(.@x=0;.@x<getarraysize(.@T$);.@x++){
866 explode(.@TT$,.@T$[.@x],":");
867 .@id = atoi(.@TT$[0]);
868 .@amt = atoi(.@TT$[1])*.@mul;
869 if(.@amt>0) delitem .@id,.@amt;
870 }
871 return 1;
872 }
873 return 0;
874}
875
876function script varcheck {
877 .@iteminfo$ = getarg(0);
878 .@mode = getarg(1,0);
879 if(.@iteminfo$ == "") return 2;
880 explode(.@T$,.@iteminfo$,"|");
881 if(!.@mode){
882 mes "Variable Requirement:";
883 .@bool = 1;
884 for(.@x=0;.@x<getarraysize(.@T$);.@x++){
885 explode(.@TT$,.@T$[.@x],":");
886 .@var$ = .@TT$[0];
887 .@amt = atoi(.@TT$[1]);
888 if(getd(.@var$) < .@amt){
889 mes " > "+.@var$+" ["+CStr(getd(.@var$),"green")+"/"+.@amt+"]";
890 .@bool = 0;
891 }else{
892 mes " > "+.@var$+" ["+CStr(getd(.@var$),"red")+"/"+.@amt+"]";
893 }
894 }
895 return .@bool;
896 }else{
897 for(.@x=0;.@x<getarraysize(.@T$);.@x++){
898 explode(.@TT$,.@T$[.@x],":");
899 .@var$ = .@TT$[0];
900 .@amt = atoi(.@TT$[1]);
901 set getd(.@var$),getd(.@var$)-.@amt;
902 }
903 return 1;
904 }
905 return 0;
906}
907
908//= Below this will add a new custom inventory system ===============================
909//= This system are useful for someone that hope npc can have inventory
910//===================================================================================
911
912//=========================================
913//= Yuchinin Custom Setup Npc
914//=========================================
915- script Yuchinin_Custom_Setup -1,{
916OnInit:
917.install_custom_db = 1;
918
919.@sql$ = "CREATE TABLE IF NOT EXISTS `custom_inventory` (`itemid` int(11) NOT NULL,`amount` int(11) NOT NULL DEFAULT '0',`owner` varchar(25) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8";
920.@sql2$ = "CREATE TABLE IF NOT EXISTS `delay_item_db` (`charid` int(10) unsigned NOT NULL,`npcid` varchar(45) NOT NULL,`itemid` int(10) unsigned NOT NULL DEFAULT '0',`amount` int(10) unsigned NOT NULL DEFAULT '0',`timestamp` int(10) unsigned NOT NULL DEFAULT '0') ENGINE=InnoDB DEFAULT CHARSET=utf8;";
921if(.install_custom_db){
922 query_sql(.@sql$);
923 debugmes "table name [ custom_inventory ] installed!";
924 query_sql(.@sql2$);
925 debugmes "table name [ delay_item_db ] installed!";
926}
927end;
928}
929
930function script getdelayitemdata {
931 .@sql$ = "select "+getarg(0)+" from delay_item_db where charid = "+getcharid(0)+" AND npcid = '"+strnpcinfo(3)+"'";
932 .@size = query_sql(.@sql$,.@val);
933 if(.@size>0) return .@val;
934 return -1;
935}
936
937function script setdelayitemdata {
938 .@sql$ = "update delay_item_db set "+getarg(0)+" = "+getarg(1)+" where charid = "+getcharid(0)+" AND npcid = '"+strnpcinfo(3)+"'";
939 //dispbottom .@sql$;
940 query_sql(.@sql$);
941 return;
942}
943
944function script adddelayitemdata {
945 .@sql$ = "replace into delay_item_db set charid = "+getcharid(0)+", npcid = '"+strnpcinfo(3)+"'";
946 query_sql(.@sql$);
947 return;
948}
949
950function script deldelayitemdata {
951 .@sql$ = "delete from delay_item_db where charid = "+getcharid(0)+" AND npcid = '"+strnpcinfo(3)+"'";
952 query_sql(.@sql$);
953 return;
954}
955
956function script countdelayitemdata {
957 .@sql$ = "select timestamp from delay_item_db where npcid = '"+strnpcinfo(3)+"' AND timestamp > "+gettimetick(2);
958 .@size = query_sql(.@sql$,.@val);
959 if(.@size>0) return .@size;
960 return 0;
961}
962
963//===================================
964//= invcount("<owner>")
965//= return inventory count
966//===================================
967function script invcount {
968 .@owner$ = getarg(0,strnpcinfo(3));
969 if(.@owner$=="ALL") query_sql("SELECT COUNT(*) as count FROM custom_inventory",.@count);
970 else query_sql("SELECT COUNT(*) as count FROM custom_inventory where owner = '"+.@owner$+"'",.@count);
971 return .@count;
972}
973
974//===================================
975//= invcountitem(<itemid>,"<owner>")
976//= return item count in inventory
977//===================================
978function script invcountitem {
979 .@itemid = getarg(0);
980 .@owner$ = getarg(1,strnpcinfo(3));
981 if(.@owner$=="ALL") query_sql("SELECT sum as amount FROM custom_inventory where itemid = "+.@itemid,.@amount);
982 else query_sql("SELECT amount FROM custom_inventory where itemid = "+.@itemid+" AND owner = '"+.@owner$+"'",.@amount);
983 return .@amount;
984}
985
986//===================================
987//= invselect("<owner>","<blacklistid>","<label>")
988//= add label before selection
989//= return itemid after selection
990//===================================
991function script invselect {
992 .@blist$ = "25003";
993 .@owner$ = getarg(0,strnpcinfo(3));
994 .@blacklist$ = getarg(1,"");
995 .@label$ = getarg(2,"");
996 if(.@owner$=="ALL") .@sql = query_sql("SELECT itemid,amount,owner FROM custom_inventory",.@itemid,.@amount,.@owner$);
997 else .@sql = query_sql("SELECT itemid,amount,owner FROM custom_inventory where instr('"+.@blacklist$+.@blist$+"',itemid) = 0 AND owner = '"+.@owner$+"'",.@itemid,.@amount,.@owner$);
998 .@m$ = "";
999 for(.@x=0;.@x<.@sql;.@x++){
1000 .@m$ = .@m$+.@label$+(.@owner$=="ALL"?.@owner$[.@x]+" ":"")+"["+.@amount[.@x]+"]"+getitemname(.@itemid[.@x])+":";
1001 }
1002 return .@itemid[select(.@m$)-1];
1003}
1004
1005//===================================
1006//= invgetitem(<itemid>,"<owner>",{<amount>})
1007//= return itemid if success
1008//= return 0 if fail
1009//===================================
1010function script invgetitem {
1011 .@itemid = getarg(0);
1012 .@owner$ = getarg(1,strnpcinfo(3));
1013 .@amount = getarg(2,1);
1014 .@count = callfunc("invcountitem",.@itemid,.@owner$);
1015 if(getitemname(.@itemid)!="null"){
1016 if(.@count<=0) query_sql("INSERT INTO `custom_inventory` VALUES ("+.@itemid+","+.@amount+", '"+.@owner$+"')");
1017 else query_sql("UPDATE `custom_inventory` set amount = amount + "+.@amount+" where itemid = "+.@itemid+" AND owner = '"+.@owner$+"'");
1018 }else{
1019 debugmes "invgetitem id "+.@itemid+" is not a valid item";
1020 }
1021 .@count2 = callfunc("invcountitem",.@itemid,.@owner$);
1022 //debugmes "get .@count = "+.@count+" .@count2 = "+.@count2+" owner$ = "+.@owner$;
1023 if(.@count == .@count2){
1024 debugmes "invgetitem Fail to get "+.@amount+" x "+getitemname(.@itemid)+" ["+.@owner$+"]";
1025 return 0;
1026 }
1027 return .@itemid;
1028}
1029
1030//===================================
1031//= invhasitem(<itemid>,"<owner>")
1032//= return itemid if have item
1033//= return 0 if don't have item
1034//===================================
1035function script invhasitem {
1036 .@itemid = getarg(0);
1037 .@owner$ = getarg(1,strnpcinfo(3));
1038 if(.@owner$=="ALL") .@sql = query_sql("SELECT itemid FROM custom_inventory where itemid = "+.@itemid+";",.@item);
1039 else .@sql = query_sql("SELECT itemid FROM custom_inventory where owner = '"+.@owner$+"' AND itemid = "+.@itemid+";",.@item);
1040 if(.@sql>0) return .@itemid;
1041 return 0;
1042}
1043
1044//===================================
1045//= invdelitem(<itemid>,"<owner>",{<amount>})
1046//= return itemid if success
1047//= return 0 if fail
1048//===================================
1049function script invdelitem {
1050 .@itemid = getarg(0);
1051 .@owner$ = getarg(1,strnpcinfo(3));
1052 .@amount = getarg(2,1);
1053 .@count = callfunc("invcountitem",.@itemid,.@owner$);
1054 if(getitemname(.@itemid)!="null") {
1055 query_sql("UPDATE custom_inventory set amount = amount - "+.@amount+" where owner = '"+.@owner$+"' AND itemid = "+.@itemid+";");
1056 query_sql("DELETE FROM custom_inventory where amount <= 0 AND owner = '"+.@owner$+"' AND itemid = "+.@itemid+";");
1057 }else{
1058 debugmes "invdelitem id "+.@itemid+" is not a valid item";
1059 }
1060 .@count2 = callfunc("invcountitem",.@itemid,.@owner$);
1061 //debugmes "del .@count = "+.@count+" .@count2 = "+.@count2+" owner$ = "+.@owner$;
1062 if(.@count == .@count2){
1063 debugmes "invdelitem Fail to del "+.@amount+" x "+getitemname(.@itemid)+" ["+.@owner$+"]";
1064 return 0;
1065 }
1066 return .@itemid;
1067}
1068
1069//===================================
1070//= invclear("<owner>")
1071//= clear all inventory
1072//===================================
1073function script invclear {
1074 .@owner$ = getarg(0,strnpcinfo(3));
1075 .@count = callfunc("invcount",.@owner$);
1076 if(.@owner$=="ALL") query_sql("delete FROM custom_inventory");
1077 else query_sql("delete FROM custom_inventory where owner = '"+.@owner$+"'");
1078 .@count2 = callfunc("invcount",.@owner$);
1079 if(.@count==.@count2){
1080 return 0;
1081 }
1082 return 1;
1083}
1084
1085/*
1086e_gasp 0 = !
1087e_what 1 = ?
1088e_ho 2 = ho
1089e_lv 3 = lv
1090e_swt 4 = swt
1091e_ic 5 = ic
1092e_an 6 = an
1093e_ag 7 = ag
1094e_cash 8 = $
1095e_dots 9 = ...
1096e_scissors 10 = gawi
1097e_rock 11 = bawi
1098e_paper 12 = bo
1099e_korea 13 = flg1
1100e_lv2 14 = lv2
1101e_thx 15 = thx
1102e_wah 16 = wah
1103e_sry 17 = sry
1104e_heh 18 = heh
1105e_swt2 19 = swt2
1106e_hmm 20 = hmm
1107e_no1 21 = no1
1108e_no 22 = ??
1109e_omg 23 = omg
1110e_oh 24 = oh
1111e_X 25 = x
1112e_hlp 26 = hlp
1113e_go 27 = go
1114e_sob 28 = sob
1115e_gg 29 = gg
1116e_kis 30 = kis
1117e_kis2 31 = kis2
1118e_pif 32 = pif
1119e_ok 33 = ok
1120e_mute 34 = ""
1121e_indonesia 35 = flg2
1122e_bzz 36 = bzz
1123e_rice 37 = rice
1124e_awsm 38 = awsm
1125e_meh 39 = meh
1126e_shy 40 = shy
1127e_pat 41 = pat
1128e_mp 42 = mp
1129e_slur 43 = slur
1130e_com 44 = com
1131e_yawn 45 = yawn
1132e_grat 46 = grat
1133e_hp 47 = hp
1134e_philippines 48 = flg3
1135e_malaysia 49 = flg4
1136e_singapore 50 = flg5
1137e_brazil 51 = flg6
1138e_flash 52 = fsh
1139e_spin 53 = spin
1140e_sigh 54 = sigh
1141e_dum 55 = dum
1142e_loud 56 = crwd
1143e_otl 57 = otl
1144e_dice1 58 = dice1
1145e_dice2 59 = dice2
1146e_dice3 60 = dice3
1147e_dice4 61 = dice4
1148e_dice5 62 = dice5
1149e_dice6 63 = dice6
1150e_india 64 = flg7
1151e_luv 65 = luv
1152e_russia 66 = flg8
1153e_virgin 67 = flg9
1154e_mobile 68 = mobile
1155e_mail 69 = mail
1156e_chinese 70 = flg10
1157e_antenna1 71 = antenna1
1158e_antenna2 72 = antenna2
1159e_antenna3 73 = antenna3
1160e_hum 74 = hum
1161e_abs 75 = abs
1162e_oops 76 = oops
1163e_spit 77 = spit
1164e_ene 78 = ene
1165e_panic 79 = panic
1166e_whisp 80 = whisp
1167*/