Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.93 KB | None | 0 0
  1. script.cpp:
  2.  
  3. static int buildin_getplayersarea_sub(struct block_list *bl, va_list ap)
  4. {
  5.     struct map_session_data *sd = (struct map_session_data *)bl;
  6.     struct script_state* st = va_arg(ap, struct script_state*);
  7.     int j;
  8.  
  9.     if (sd == NULL || st == NULL)
  10.         return SCRIPT_CMD_SUCCESS;
  11.  
  12.     j = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
  13.     set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), j), ".@area_players_cid", (void*)__64BPRTSIZE(sd->status.char_id), NULL);
  14.     set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), j), ".@area_players_aid", (void*)__64BPRTSIZE(sd->status.account_id), NULL);
  15.     set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), j), ".@area_players_name$", (void *)__64BPRTSIZE(sd->status.name), NULL);
  16.     return SCRIPT_CMD_SUCCESS;
  17. }
  18.  
  19. BUILDIN_FUNC(getplayersarea)
  20. {
  21.     const char *str;
  22.     int16 m, x1, y1, x2, y2, count = 0;
  23.     int i;
  24.  
  25.     str = script_getstr(st, 2);
  26.     x1 = script_getnum(st, 3);
  27.     y1 = script_getnum(st, 4);
  28.     x2 = script_getnum(st, 5);
  29.     y2 = script_getnum(st, 6);
  30.  
  31.     if ((m = map_mapname2mapid(str)) < 0) {
  32.         script_pushint(st, 0);
  33.         return SCRIPT_CMD_SUCCESS;
  34.     }
  35.  
  36.     // Clean up any leftovers that weren't overwritten
  37.     count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
  38.     for (i = 0; i < count; i++) {
  39.         set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), i), ".@area_players_cid", (void*)0, NULL);
  40.         set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), i), ".@area_players_aid", (void*)0, NULL);
  41.         set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), i), ".@area_players_name$", (void *)"", NULL);
  42.     }
  43.  
  44.     // Enter new values
  45.     map_foreachinallarea(buildin_getplayersarea_sub, m, x1, y1, x2, y2, BL_PC, st);
  46.     count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
  47.     set_reg(st, NULL, add_str(".@area_players_count"), ".@area_players_count", (void*)__64BPRTSIZE(count), NULL);
  48.     script_pushint(st, count);
  49.     return SCRIPT_CMD_SUCCESS;
  50. }
  51.  
  52. static int buildin_getplayersrange_sub(struct block_list *bl, va_list ap)
  53. {
  54.     struct map_session_data *sd = (struct map_session_data *)bl;
  55.     struct script_state* st = va_arg(ap, struct script_state*);
  56.     int j;
  57.  
  58.     if (sd == NULL || st == NULL)
  59.         return SCRIPT_CMD_SUCCESS;
  60.  
  61.     j = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
  62.     set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), j), ".@area_players_cid", (void*)__64BPRTSIZE(sd->status.char_id), NULL);
  63.     set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), j), ".@area_players_aid", (void*)__64BPRTSIZE(sd->status.account_id), NULL);
  64.     set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), j), ".@area_players_name$", (void *)__64BPRTSIZE(sd->status.name), NULL);
  65.     return SCRIPT_CMD_SUCCESS;
  66. }
  67.  
  68. BUILDIN_FUNC(getplayersrange)
  69. {
  70.     const char *str;
  71.     int16 m, x, y, range, count = 0;
  72.     int i;
  73.  
  74.     str = script_getstr(st,2);
  75.     x = script_getnum(st,3);
  76.     y = script_getnum(st,4);
  77.     range = script_getnum(st,5);
  78.  
  79.     if ((m = map_mapname2mapid(str)) < 0) {
  80.         script_pushint(st, 0);
  81.         return SCRIPT_CMD_SUCCESS;
  82.     }
  83.  
  84.     // Clean up any leftovers that weren't overwritten
  85.     count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
  86.     for (i = 0; i < count; i++) {
  87.         set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), i), ".@area_players_cid", (void*)0, NULL);
  88.         set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), i), ".@area_players_aid", (void*)0, NULL);
  89.         set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), i), ".@area_players_name$", (void *)"", NULL);
  90.     }
  91.  
  92.     // Enter new values
  93.     map_foreachinallrange2(buildin_getplayersrange_sub, m, x, y, range, BL_PC, st);
  94.     count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
  95.     set_reg(st, NULL, add_str(".@area_players_count"), ".@area_players_count", (void*)__64BPRTSIZE(count), NULL);
  96.     script_pushint(st, count);
  97.     return SCRIPT_CMD_SUCCESS;
  98. }
  99.  
  100. BUILDIN_DEF(getplayersarea, "siiii"),
  101. BUILDIN_DEF(getplayersrange, "siii"),
  102.  
  103. --
  104. map.cpp:
  105. /*==========================================
  106.  * Adapted from foreachinrangeV for an easier invocation. [CreativeSD]
  107.  *------------------------------------------*/
  108. int map_foreachinrangeV2(int (*func)(struct block_list*,va_list), int16 m, int16 x, int16 y, int16 range, int type, va_list ap, bool wall_check)
  109. {
  110.     int bx, by;
  111.     int returnCount = 0;    //total sum of returned values of func() [Skotlex]
  112.     struct block_list *bl;
  113.     int blockcount = bl_list_count, i;
  114.     int x0, x1, y0, y1;
  115.     va_list ap_copy;
  116.  
  117.     if( m < 0 )
  118.         return 0;
  119.  
  120.     struct map_data *mapdata = map_getmapdata(m);
  121.  
  122.     x0 = i16max(x - range, 0);
  123.     y0 = i16max(y - range, 0);
  124.     x1 = i16min(x + range, mapdata->xs - 1);
  125.     y1 = i16min(y + range, mapdata->ys - 1);
  126.  
  127.     if ( type&~BL_MOB ) {
  128.         for( by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++ ) {
  129.             for( bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++ ) {
  130.                 for(bl = mapdata->block[ bx + by * mapdata->bxs ]; bl != NULL; bl = bl->next ) {
  131.                     if( bl->type&type
  132.                         && bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1
  133. #ifdef CIRCULAR_AREA
  134.                         && check_distance_bl(center, bl, range)
  135. #endif
  136.                         && ( !wall_check || path_search_long(NULL, m, x, y, bl->x, bl->y, CELL_CHKWALL) )
  137.                         && bl_list_count < BL_LIST_MAX )
  138.                         bl_list[ bl_list_count++ ] = bl;
  139.                 }
  140.             }
  141.         }
  142.     }
  143.  
  144.     if ( type&BL_MOB ) {
  145.         for( by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++ ) {
  146.             for( bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++ ) {
  147.                 for(bl = mapdata->block_mob[ bx + by * mapdata->bxs ]; bl != NULL; bl = bl->next ) {
  148.                     if( bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1
  149. #ifdef CIRCULAR_AREA
  150.                         && check_distance_bl(center, bl, range)
  151. #endif
  152.                         && ( !wall_check || path_search_long(NULL, m, x, y, bl->x, bl->y, CELL_CHKWALL) )
  153.                         && bl_list_count < BL_LIST_MAX )
  154.                         bl_list[ bl_list_count++ ] = bl;
  155.                 }
  156.             }
  157.         }
  158.     }
  159.  
  160.     if( bl_list_count >= BL_LIST_MAX )
  161.         ShowWarning("map_foreachinallrange2: block count too many!\n");
  162.  
  163.     map_freeblock_lock();
  164.  
  165.     for( i = blockcount; i < bl_list_count; i++ ) {
  166.         if( bl_list[ i ]->prev ) { //func() may delete this bl_list[] slot, checking for prev ensures it wasn't queued for deletion.
  167.             va_copy(ap_copy, ap);
  168.             returnCount += func(bl_list[i], ap_copy);
  169.             va_end(ap_copy);
  170.         }
  171.     }
  172.  
  173.     map_freeblock_unlock();
  174.  
  175.     bl_list_count = blockcount;
  176.     return returnCount; //[Skotlex]
  177. }
  178.  
  179. int map_foreachinallrange2(int(*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int16 range, int type, ...)
  180. {
  181.     int returnCount = 0;
  182.     va_list ap;
  183.     va_start(ap,type);
  184.     returnCount = map_foreachinrangeV2(func,m, x, y,range,type,ap,false);
  185.     va_end(ap);
  186.     return returnCount;
  187. }
  188.  
  189. --
  190. map.hpp:
  191.  
  192. int map_foreachinrangeV2(int (*func)(struct block_list*,va_list), int16 m, int16 x, int16 y, int16 range, int type, va_list ap, bool wall_check)
  193. int map_foreachinallrange2(int(*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int16 range, int type, ...);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement