Advertisement
Guest User

Untitled

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