Advertisement
Guest User

Untitled

a guest
Mar 15th, 2012
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. /*==========================================
  2. * @itemmap
  3. * A way of giving items to all players on a whole map
  4. *------------------------------------------*/
  5. ACMD_FUNC(itemmap)
  6. {
  7. struct map_session_data *pl_sd = NULL;
  8. struct s_mapiterator* iter;
  9. int j;
  10. int level;
  11. int map_id = 0;
  12. char map_name[MAP_NAME_LENGTH];
  13. char item_name[100];
  14. int number = 0, item_id, flag;
  15. struct item item_tmp;
  16. struct item_data *item_data;
  17. int get_count, count=0;
  18.  
  19. memset(item_name, '\0', sizeof(item_name));
  20. memset(map_name, '\0', sizeof(map_name));
  21.  
  22.  
  23. nullpo_retr(-1, sd);
  24.  
  25.  
  26. if( !message || !*message ||
  27. sscanf( message, "%11s \"%99[^\"]\" %d", map_name, item_name, &number ) != 3 &&
  28. sscanf( message, "%11s %99s %d", map_name, item_name, &number) != 3)
  29. {
  30. clif_displaymessage( fd, "Please, enter an item name/id (usage: @itemmap <mapname> <item name or ID> [quantity])." );
  31. return 0;
  32. }
  33.  
  34.  
  35. if (number <= 0)
  36. number = 1;
  37.  
  38. if ((item_data = itemdb_searchname(item_name)) == NULL &&
  39. (item_data = itemdb_exists(atoi(item_name))) == NULL)
  40. {
  41. clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  42. return -1;
  43. }
  44.  
  45. item_id = item_data->nameid;
  46. get_count = number;
  47. //Check if it's stackable.
  48. if (!itemdb_isstackable2(item_data))
  49. get_count = 1;
  50.  
  51. level = pc_get_group_level(sd);
  52.  
  53. if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < MAP_NAME_LENGTH-4) // 16 - 4 (.gat)
  54. strcat(map_name, ".gat");
  55. if ((map_id = map_mapname2mapid(map_name)) < 0)
  56. map_id = sd->bl.m;
  57.  
  58. iter = mapit_getallusers();
  59. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  60. {
  61. if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  62. {
  63.  
  64. if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || (pl_sd->sc.option & OPTION_INVISIBLE)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level
  65. if (pl_sd->bl.m == map_id) { // If the player is on the map
  66.  
  67. for (j = 0; j < number; j += get_count) {
  68. memset(&item_tmp, 0, sizeof(item_tmp));
  69. item_tmp.nameid = item_id;
  70. item_tmp.identify = 1;
  71.  
  72. if ((flag = pc_additem(pl_sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  73. clif_additem(pl_sd, 0, 0, flag);
  74.  
  75. }
  76.  
  77.  
  78. count ++;
  79. clif_displaymessage(pl_sd->fd, "Something is falling from the sky."); // Message for all players on the map (can't use "mercy.." because we can use a Support or a Attack skill with @skillmap)
  80. }
  81. }
  82. }
  83. }
  84.  
  85.  
  86. snprintf(atcmd_output, sizeof(atcmd_output) ,"You give the item to : %d players.", count);
  87. clif_displaymessage(fd, atcmd_output);
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement