Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. /*==========================================
  2. * @whosell command
  3. *------------------------------------------*/
  4. ACMD_FUNC(whosell)
  5. {
  6. struct map_session_data *pl_sd, *b_sd[MAX_SEARCH];
  7. struct s_mapiterator* iter;
  8.  
  9. struct item_data *item_array[MAX_SEARCH];
  10. int total[MAX_SEARCH], amount[MAX_SEARCH];
  11. unsigned int MinPrice[MAX_SEARCH], MaxPrice[MAX_SEARCH];
  12. char output[256];
  13. int i, j, count = 1;
  14.  
  15. if( !message || !*message )
  16. {
  17. clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @whosell <item name or ID>).");
  18. return -1;
  19. }
  20.  
  21. if( (item_array[0] = itemdb_exists(atoi(message))) == NULL )
  22. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  23.  
  24. if( count < 1 )
  25. { // No items found
  26. clif_displaymessage(fd, msg_txt(19));
  27. return -1;
  28. }
  29.  
  30. if( count > MAX_SEARCH ) count = MAX_SEARCH;
  31.  
  32. // Preparing Search Recorders
  33. for( i = 0; i < MAX_SEARCH; i++ )
  34. {
  35. total[i] = amount[i] = MaxPrice[i] = 0;
  36. MinPrice[i] = battle_config.vending_max_value + 1;
  37. b_sd[i] = NULL;
  38. }
  39.  
  40. iter = mapit_getallusers();
  41. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  42. {
  43. if( !pl_sd->vender_id ) continue;
  44. for( i = 0; i < pl_sd->vend_num; i++ )
  45. { // Searching in the Vending List
  46. for( j = 0; j < count; j++ )
  47. { // Compares with each search result
  48. if( pl_sd->status.cart[pl_sd->vending[i].index].nameid != item_array[j]->nameid )
  49. continue;
  50.  
  51. amount[j] += pl_sd->vending[i].amount;
  52. total[j]++;
  53.  
  54. if( pl_sd->vending[i].value < MinPrice[j] )
  55. { // Best Price
  56. MinPrice[j] = pl_sd->vending[i].value;
  57. b_sd[j] = pl_sd;
  58. }
  59. if( pl_sd->vending[i].value > MaxPrice[j] )
  60. MaxPrice[j] = pl_sd->vending[i].value;
  61. }
  62. }
  63. }
  64. mapit_free(iter);
  65.  
  66. for( i = 0; i < count; i++ )
  67. {
  68. if( total[i] > 0 && b_sd[i] != NULL )
  69. {
  70. sprintf(output, "[%d] The best price found for '%s' is %u sold by '%s' at %s <%d,%d>. Max Price %u. Item found in %d shops, %d pieces for sale.", item_array[i]->nameid, item_array[i]->jname, MinPrice[i], b_sd[i]->status.name, map[b_sd[i]->bl.m].name, b_sd[i]->bl.x, b_sd[i]->bl.y, MaxPrice[i], total[i], amount[i]);
  71. if( sd->bl.m == b_sd[i]->bl.m )
  72. clif_viewpoint(sd, 1, 1, b_sd[i]->bl.x, b_sd[i]->bl.y, i, 0xFFFFFF);
  73. }
  74. else
  75. sprintf(output, "[%d] '%s' is not being sold at the moment...", item_array[i]->nameid, item_array[i]->jname);
  76.  
  77. clif_displaymessage(sd->fd, output);
  78. }
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement