Advertisement
Guest User

Untitled

a guest
May 5th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h> // für atoi()
  4. #include "../common/HPMi.h"
  5. #include "../map/script.h"
  6. #include "../map/pc.h"
  7. #include "../map/map.h"
  8. #include "../map/itemdb.h"
  9. #include "../map/buyingstore.h"
  10. #include "../map/battle.h"
  11. #include "../map/atcommand.h"
  12. #include "../common/mapindex.h"
  13. #include "../common/nullpo.h" // für nullpo_retr
  14. #include "../common/HPMDataCheck.h"
  15.  
  16. // um funktions fehler zu beheben beim compilieren der plugins man atoi machen , oder nen anderen func namen
  17.  
  18. HPExport struct hplugin_info pinfo = {
  19. "whobuy", // Plugin name
  20. SERVER_TYPE_MAP,// Which server types this plugin works with?
  21. "1.0", // Plugin version
  22. HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
  23. };
  24.  
  25. ACMD(whobuy)
  26. {
  27. char item_name[100];
  28. char atcmd_output[255+1];
  29. int item_id, j, count = 0, sat_num = 0;
  30. bool flag = 0;
  31. struct map_session_data* pl_sd;
  32. struct s_mapiterator* iter;
  33. int MinPrice = 999999999, MaxPrice = 0;
  34. struct item_data *item_data;
  35.  
  36. if (!message || !*message || sscanf(message, "%99[^\n]", item_name) < 1)
  37. {
  38. clif->message(fd, "Input item name or ID (use: @whobuy <name or ID>).");
  39. return false;
  40. }
  41.  
  42. if ((item_data = itemdb->search_name(item_name)) == NULL &&
  43. (item_data = itemdb->exists(atoi(item_name))) == NULL)
  44. {
  45. clif->message(fd, msg_txt(19)); // Invalid item ID or name.
  46. return false;
  47. }
  48.  
  49. item_id = item_data->nameid;
  50.  
  51. iter = mapit_getallusers();
  52. for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) )
  53. {
  54. if( pl_sd->state.buyingstore)//check if player is autobuying
  55. {
  56. for (j = 0; j < pl_sd->buyingstore.slots; j++) {
  57. if(pl_sd->buyingstore.items[j].nameid == item_id) {
  58. snprintf(atcmd_output, CHAT_SIZE_MAX, "Price %d | Amount %d | Buyer %s | Map %s[%d,%d]",pl_sd->buyingstore.items[j].price,pl_sd->buyingstore.items[j].amount,pl_sd->status.name,mapindex_id2name(pl_sd->mapindex),pl_sd->bl.x, pl_sd->bl.y);
  59. if(pl_sd->buyingstore.items[j].price < MinPrice) MinPrice = pl_sd->buyingstore.items[j].price;
  60. if(pl_sd->buyingstore.items[j].price > MaxPrice) MaxPrice = pl_sd->buyingstore.items[j].price;
  61. clif->message(fd, atcmd_output);
  62. count++;
  63. flag = 1;
  64. }
  65. }
  66. if(flag && pl_sd->mapindex == sd->mapindex){
  67. clif->viewpoint(sd, 1, 1, pl_sd->bl.x, pl_sd->bl.y, ++sat_num, 0xFFFFFF);
  68. flag = 0;
  69. }
  70. }
  71. }
  72. mapit->free(iter);
  73.  
  74. if(count > 0)
  75. {
  76. snprintf(atcmd_output,CHAT_SIZE_MAX, "Found %d ea. Prices from %dz to %dz", count, MinPrice, MaxPrice);
  77. clif->message(fd, atcmd_output);
  78. } else
  79. clif->message(fd, "Nobody buying it now.");
  80.  
  81. return true;
  82. }
  83.  
  84.  
  85. /* Server Startup */
  86. HPExport void plugin_init (void)
  87. {
  88. clif = GET_SYMBOL("clif");
  89. script = GET_SYMBOL("script");
  90. battle = GET_SYMBOL("battle");
  91. mapit = GET_SYMBOL("mapit");
  92. map = GET_SYMBOL("map");
  93. itemdb = GET_SYMBOL("itemdb");
  94. buyingstore = GET_SYMBOL("buyingstore");
  95. atcommand = GET_SYMBOL("atcommand");
  96. mapindex = GET_SYMBOL("mapindex");
  97.  
  98. addAtcommand("whobuy",whobuy);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement