Let me show you 3 different methods
1. loop the value back in another array, almost similar to meko did
prontera,155,185,5 script kjdshfsk 1_F_MARIA,{
getinventorylist;
for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
.@j = 0;
while ( .@j < .@itemtotal && .@itemid[.@j] != @inventorylist_id[.@i] ) ++.@j;
if ( .@j == .@itemtotal )
.@itemid[.@itemtotal++] = @inventorylist_id[.@i];
}
for ( .@i = 0; .@i < .@itemtotal; ++.@i )
dispbottom getitemname( .@itemid[.@i] ) +" -> "+ countitem( .@itemid[.@i] ) +"x";
end;
}
most people will show you this method, and this method is usable in almost all programming language
BUT ... in my opinion this method use lots of loops ...
2. store the value in a string, then compare them later
prontera,158,185,5 script dskjfhsdfk 1_F_MARIA,{
getinventorylist;
.@compare$ = "#";
for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
if ( !compare( .@compare$, "#"+ @inventorylist_id[.@i] +"#" ) ) {
.@compare$ += @inventorylist_id[.@i] +"#";
.@itemid[.@itemtotal++] = @inventorylist_id[.@i];
}
}
for ( .@i = 0; .@i < .@itemtotal; ++.@i )
dispbottom getitemname( .@itemid[.@i] ) +" -> "+ countitem( .@itemid[.@i] ) +"x";
end;
}
I have used this method in https://rathena.org/board/topic/91826-special-party-warper/#comment-241434 https://rathena.org/board/topic/91723-please-help-this-script-about-mac_address/?do=findComment&comment=240887
I used this method a lot before Ind upgrade our scripting engine,
but search using strings is quite slow in C language, hercules script language included
and comes the recommended method below
3. abuse hercules script engine, array is store in a pointer.
prontera,161,185,5 script zcxvsfer 1_F_MARIA,{
getinventorylist;
for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
if ( !.@compare[ @inventorylist_id[.@i] ] ) {
.@compare[ @inventorylist_id[.@i] ] = true;
.@itemid[.@itemtotal++] = @inventorylist_id[.@i];
}
}
for ( .@i = 0; .@i < .@itemtotal; ++.@i )
dispbottom getitemname( .@itemid[.@i] ) +" -> "+ countitem( .@itemid[.@i] ) +"x";
end;
}
ever since Ind upgrade our scripting engine, this is my latest method, and I think this is the fastest way -> compare to all 3 methods
I have used in getitemname2 function soul linker spirit
As you can see, I used Method 2 while still on rAthena forum, and switch to Method 3 after switch to Hercules
And for your 2nd question, you can solve it yourself after you learn any of these techniques