BUILDIN_FUNC(checkweight3) { //variable sub checkweight int nameid=-1, amount=-1, weight=0; int i=0, amount2=0, slots=0; //variable for array parsing struct script_data* data_it; struct script_data* data_nb; const char* name_it; const char* name_nb; int32 id_it, id_nb; int32 idx_it, idx_nb; int32 idr_it, idr_nb; int nb_it, nb_nb; //array size TBL_PC *sd = script_rid2sd(st); nullpo_retr(1,sd); data_it = script_getdata(st, 2); data_nb = script_getdata(st, 3); if( !data_isreference(data_it) || !data_isreference(data_nb)) { ShowError("script:checkweight3: parameter not a variable\n"); script_pushint(st,0); return 1;// not a variable } id_it = reference_getid(data_it); id_nb = reference_getid(data_nb); idx_it = reference_getindex(data_it); idx_nb = reference_getindex(data_nb); name_it = reference_getname(data_it); name_nb = reference_getname(data_nb); if( not_array_variable(*name_it) || not_array_variable(*name_nb)) { ShowError("script:checkweight3: illegal scope\n"); script_pushint(st,0); return 1;// not supported } if(is_string_variable(name_it) || is_string_variable(name_nb)){ ShowError("script:checkweight3: illegal type, need int\n"); script_pushint(st,0); return 1;// not supported } nb_it = getarraysize(st, id_it, idx_it, 0, reference_getref(data_it)); nb_nb = getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb)); ShowInfo("nb_it=%d, nb_nb=%d\n",nb_it,nb_nb); if(nb_it != nb_nb){ ShowError("Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb); script_pushint(st,-1); return 1;// not supported } slots = pc_inventoryblank(sd); for(i=0; iweight > sd->max_weight ) {// too heavy script_pushint(st,0); return 0; } switch( pc_checkadditem(sd, nameid, amount) ) { case ADDITEM_EXIST: // item is already in inventory, but there is still space for the requested amount break; case ADDITEM_NEW: if( itemdb_isstackable(nameid) ) {// stackable amount2++; if( slots < amount2 ) { script_pushint(st,0); return 0; } } else {// non-stackable amount2 += amount; if( slots < amount2 ) { script_pushint(st,0); return 0; } } break; case ADDITEM_OVERAMOUNT: script_pushint(st,0); return 0; } } script_pushint(st,1); return 0; } //declaration BUILDIN_DEF(checkweight3, "rr"), //[Lighta] //test npc izlude,150,127,3 script chkweight 83,{ //part1 script variable setarray .@item[0], 970,717,510,508; setarray .@count[0], 10,5,9,12; if(checkweight3(.@item,.@count)) debugmes "Test1 seem ok"; setarray .@item2[0], 970,703,510; if(checkweight3(.@item2,.@count)==-1) debugmes "Test2 seem ok size mistmatch"; set .@item3,970; if(checkweight3(.@item3,.@count)==-1) debugmes "Test4 seem ok size mistmatch"; setarray .item[0], 970,717,510,508; setarray .count[0], 10,5,9,12; if(checkweight3(.item,.count)) debugmes "Test5 seem ok"; //part2 char variable setarray @item[0], 970,717,510,508; setarray @count[0], 10,5,9,12; if(checkweight3(@item,@count)) debugmes "Test6 seem ok"; setarray item[0], 970,717,510,508; setarray count[0], 10,5,9,12; if(checkweight3(item,count)) debugmes "Test7 seem ok"; //part3 server variable setarray $item[0], 970,717,510,508; setarray $count[0], 10,5,9,12; if(checkweight3($item,$count)) debugmes "Test8 seem ok"; setarray $@item[0], 970,717,510,508; setarray $@count_ch[0], 10,5,9,12; if(checkweight3($@item,$@count)) debugmes "Test9 seem ok"; //part4 string variable setarray @item$[0], 970,717,510,508; setarray @count$[0], 10,5,9,12; if(checkweight3(@item$,@count$)==0) debugmes "Test10 seem ok, type unsuported"; if(checkweight3(@item$,@count)==0) debugmes "Test11 seem ok, type unsuported"; if(checkweight3(@item,@count$)==0) debugmes "Test12 seem ok, type unsuported"; end; }