utofaery 7 Posted January 23, 2019 getinventorylist(); for ( .@i = 0; .@i < @inventorylist_count; .@i++ ) { setarray .@IdList[.@i],@inventorylist_id[.@i]; } Q1 For above code how would I remove duplicates item ID or extract only Unique Item ID within array of .@idList so the end result would be array with no duplicated item id in it? ================================================================================================================================================= Peace dividing line! ================================================================================================================================================= [Error]: buildin_countitem: Invalid item '0'. [Debug]: Source (NPC): Mass Junk Seller at prontera (164,175) [Error]: buildin_countitem: Invalid item '0'. [Debug]: Source (NPC): Mass Junk Seller at prontera (164,175) [Error]: buildin_countitem: Invalid item '0'. [Debug]: Source (NPC): Mass Junk Seller at prontera (164,175) Q2 Above Error always happens whenever this part of function runs what can be done with it ? but server and client runs fine. Function \\// Down here: Spoiler function script F_SellEquips { setarray(.@noSell0x[0], 1231, 969, 4001 ); getinventorylist(); for ( set .@i,0; .@i < @inventorylist_count; set .@i,.@i + 1) { if ( ( getiteminfo(@inventorylist_id[.@i],ITEMINFO_TYPE) == IT_WEAPON ) || ( getiteminfo(@inventorylist_id[.@i],ITEMINFO_TYPE) == IT_ARMOR ) ) && ( @inventorylist_equip[.@i] == 0 ) && ( @inventorylist_refine[.@i] == 0 ) && ( @inventorylist_card1[.@i] == 0 ) && ( @inventorylist_card2[.@i] == 0 ) && ( @inventorylist_card3[.@i] == 0 ) && ( @inventorylist_card4[.@i] == 0 ) { .@FinishCheck = 0; for( .@c = 0; .@c < getarraysize(.@noSell0x); ++.@c ) { if ( @inventorylist_id[.@i] == .@noSell0x[.@c] ) { // Yes to sell .@FinishCheck++; } } if ( .@FinishCheck == 0 ) { setarray .@sellid[getarraysize(.@sellid)],@inventorylist_id[.@i]; } } } .@sellarraysize = getarraysize(.@sellid); .@xTItemCount = 0; .@xTItemZeny = 0; .@over = getskilllv("MC_OVERCHARGE"); if(.@over > 0) .@plus = 5 + 2*.@over - .@over/10; message strcharinfo(0),( " Sell array size " + .@sellarraysize ); if ( .@sellarraysize > 0) { .@i = 0; while (.@i <= .@sellarraysize) { .@SitemID = .@sellid[.@i]; if ( ( .@sellid[.@i] != 0 ) && ( .@sellid[.@i] > 0 ) && ( countitem(.@sellid[.@i] ) > 0 ) ) { .@SitemName$ = getitemname(.@sellid[.@i]); .@SitemCount = countitem(.@sellid[.@i]); .@SitemPrice = ( getiteminfo(.@sellid[.@i],1) * (100 + .@plus) / 100 ) ; .@xTItemZeny = .@xTItemZeny + ( .@SitemPrice * .@SitemCount ) ; .@xTItemCount = .@xTItemCount + .@SitemCount; dispbottom ("ItemCount :: " + .@SitemCount + " ItemPrice :: " + .@SitemPrice + " ItemID :: " + .@sellid[.@i] + " ItemName :: " + .@SitemName$ ); delitem2 (.@SitemID,.@SitemCount,true,0,0,0,0,0,0); } ++.@i; } Zeny = Zeny + .@xTItemZeny ; dispbottom ( " Total Zeny Gained :: " + .@xTItemZeny + " for total item sold :: " + .@xTItemCount ) ; } if ( .@sellarraysize == 0 ) { dispbottom ( " Nah ! no item can be sale, you liar! " ); } close2; end; } Quote Share this post Link to post Share on other sites
0 meko 170 Posted January 23, 2019 see array_unique() in 1 utofaery reacted to this Quote Share this post Link to post Share on other sites
0 AnnieRuru 957 Posted January 23, 2019 (edited) 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 inhttps://rathena.org/board/topic/91826-special-party-warper/#comment-241434https://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 ingetitemname2 functionsoul 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 Edited January 23, 2019 by AnnieRuru 2 utofaery and meko reacted to this Quote Share this post Link to post Share on other sites
0 utofaery 7 Posted January 24, 2019 Nice Case Closed Annie thanks for showing all this stuff Guess will go the 3rd options. since using hercules as main rathena as supportive testing only.. 1 AnnieRuru reacted to this Quote Share this post Link to post Share on other sites
Q1
For above code how would I remove duplicates item ID or extract only Unique Item ID within array of .@idList so the end result would be array with no duplicated item id in it?
=================================================================================================================================================
Peace dividing line!
=================================================================================================================================================
Q2
Above Error always happens whenever this part of function runs what can be done with it ?
but server and client runs fine.
Function \\// Down here:
Share this post
Link to post
Share on other sites