Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==========================================
- * @itemmap
- * A way of giving items to all players on a whole map
- *------------------------------------------*/
- ACMD_FUNC(itemmap)
- {
- struct map_session_data *pl_sd = NULL;
- struct s_mapiterator* iter;
- int j;
- int level;
- int map_id = 0;
- char map_name[MAP_NAME_LENGTH];
- char item_name[100];
- int number = 0, item_id, flag;
- struct item item_tmp;
- struct item_data *item_data;
- int get_count, count=0;
- memset(item_name, '\0', sizeof(item_name));
- memset(map_name, '\0', sizeof(map_name));
- nullpo_retr(-1, sd);
- if( !message || !*message ||
- sscanf( message, "%11s \"%99[^\"]\" %d", map_name, item_name, &number ) != 3 &&
- sscanf( message, "%11s %99s %d", map_name, item_name, &number) != 3)
- {
- clif_displaymessage( fd, "Please, enter an item name/id (usage: @itemmap <mapname> <item name or ID> [quantity])." );
- return 0;
- }
- if (number <= 0)
- number = 1;
- if ((item_data = itemdb_searchname(item_name)) == NULL &&
- (item_data = itemdb_exists(atoi(item_name))) == NULL)
- {
- clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
- return -1;
- }
- item_id = item_data->nameid;
- get_count = number;
- //Check if it's stackable.
- if (!itemdb_isstackable2(item_data))
- get_count = 1;
- level = pc_get_group_level(sd);
- if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < MAP_NAME_LENGTH-4) // 16 - 4 (.gat)
- strcat(map_name, ".gat");
- if ((map_id = map_mapname2mapid(map_name)) < 0)
- map_id = sd->bl.m;
- iter = mapit_getallusers();
- for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
- {
- if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
- {
- 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
- if (pl_sd->bl.m == map_id) { // If the player is on the map
- for (j = 0; j < number; j += get_count) {
- memset(&item_tmp, 0, sizeof(item_tmp));
- item_tmp.nameid = item_id;
- item_tmp.identify = 1;
- if ((flag = pc_additem(pl_sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
- clif_additem(pl_sd, 0, 0, flag);
- }
- count ++;
- 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)
- }
- }
- }
- }
- snprintf(atcmd_output, sizeof(atcmd_output) ,"You give the item to : %d players.", count);
- clif_displaymessage(fd, atcmd_output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement