Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script.cpp:
- static int buildin_getplayersarea_sub(struct block_list *bl, va_list ap)
- {
- struct map_session_data *sd = (struct map_session_data *)bl;
- struct script_state* st = va_arg(ap, struct script_state*);
- int j;
- if (sd == NULL || st == NULL)
- return SCRIPT_CMD_SUCCESS;
- j = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), j), ".@area_players_cid", (void*)__64BPRTSIZE(sd->status.char_id), NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), j), ".@area_players_aid", (void*)__64BPRTSIZE(sd->status.account_id), NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), j), ".@area_players_name$", (void *)__64BPRTSIZE(sd->status.name), NULL);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getplayersarea)
- {
- const char *str;
- int16 m, x1, y1, x2, y2, count = 0;
- int i;
- str = script_getstr(st, 2);
- x1 = script_getnum(st, 3);
- y1 = script_getnum(st, 4);
- x2 = script_getnum(st, 5);
- y2 = script_getnum(st, 6);
- if ((m = map_mapname2mapid(str)) < 0) {
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- // Clean up any leftovers that weren't overwritten
- count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
- for (i = 0; i < count; i++) {
- set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), i), ".@area_players_cid", (void*)0, NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), i), ".@area_players_aid", (void*)0, NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), i), ".@area_players_name$", (void *)"", NULL);
- }
- // Enter new values
- map_foreachinallarea(buildin_getplayersarea_sub, m, x1, y1, x2, y2, BL_PC, st);
- count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
- set_reg(st, NULL, add_str(".@area_players_count"), ".@area_players_count", (void*)__64BPRTSIZE(count), NULL);
- script_pushint(st, count);
- return SCRIPT_CMD_SUCCESS;
- }
- static int buildin_getplayersrange_sub(struct block_list *bl, va_list ap)
- {
- struct map_session_data *sd = (struct map_session_data *)bl;
- struct script_state* st = va_arg(ap, struct script_state*);
- int j;
- if (sd == NULL || st == NULL)
- return SCRIPT_CMD_SUCCESS;
- j = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), j), ".@area_players_cid", (void*)__64BPRTSIZE(sd->status.char_id), NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), j), ".@area_players_aid", (void*)__64BPRTSIZE(sd->status.account_id), NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), j), ".@area_players_name$", (void *)__64BPRTSIZE(sd->status.name), NULL);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getplayersrange)
- {
- const char *str;
- int16 m, x, y, range, count = 0;
- int i;
- str = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- range = script_getnum(st,5);
- if ((m = map_mapname2mapid(str)) < 0) {
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- // Clean up any leftovers that weren't overwritten
- count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
- for (i = 0; i < count; i++) {
- set_reg(st, NULL, reference_uid(add_str(".@area_players_cid"), i), ".@area_players_cid", (void*)0, NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_aid"), i), ".@area_players_aid", (void*)0, NULL);
- set_reg(st, NULL, reference_uid(add_str(".@area_players_name$"), i), ".@area_players_name$", (void *)"", NULL);
- }
- // Enter new values
- map_foreachinallrange2(buildin_getplayersrange_sub, m, x, y, range, BL_PC, st);
- count = script_array_highest_key(st, NULL, ".@area_players_cid", NULL);
- set_reg(st, NULL, add_str(".@area_players_count"), ".@area_players_count", (void*)__64BPRTSIZE(count), NULL);
- script_pushint(st, count);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_DEF(getplayersarea, "siiii"),
- BUILDIN_DEF(getplayersrange, "siii"),
- --
- map.cpp:
- /*==========================================
- * Adapted from foreachinrangeV for an easier invocation. [CreativeSD]
- *------------------------------------------*/
- 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)
- {
- int bx, by;
- int returnCount = 0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl;
- int blockcount = bl_list_count, i;
- int x0, x1, y0, y1;
- va_list ap_copy;
- if( m < 0 )
- return 0;
- struct map_data *mapdata = map_getmapdata(m);
- x0 = i16max(x - range, 0);
- y0 = i16max(y - range, 0);
- x1 = i16min(x + range, mapdata->xs - 1);
- y1 = i16min(y + range, mapdata->ys - 1);
- if ( type&~BL_MOB ) {
- for( by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++ ) {
- for( bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++ ) {
- for(bl = mapdata->block[ bx + by * mapdata->bxs ]; bl != NULL; bl = bl->next ) {
- if( bl->type&type
- && bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1
- #ifdef CIRCULAR_AREA
- && check_distance_bl(center, bl, range)
- #endif
- && ( !wall_check || path_search_long(NULL, m, x, y, bl->x, bl->y, CELL_CHKWALL) )
- && bl_list_count < BL_LIST_MAX )
- bl_list[ bl_list_count++ ] = bl;
- }
- }
- }
- }
- if ( type&BL_MOB ) {
- for( by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++ ) {
- for( bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++ ) {
- for(bl = mapdata->block_mob[ bx + by * mapdata->bxs ]; bl != NULL; bl = bl->next ) {
- if( bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1
- #ifdef CIRCULAR_AREA
- && check_distance_bl(center, bl, range)
- #endif
- && ( !wall_check || path_search_long(NULL, m, x, y, bl->x, bl->y, CELL_CHKWALL) )
- && bl_list_count < BL_LIST_MAX )
- bl_list[ bl_list_count++ ] = bl;
- }
- }
- }
- }
- if( bl_list_count >= BL_LIST_MAX )
- ShowWarning("map_foreachinallrange2: block count too many!\n");
- map_freeblock_lock();
- for( i = blockcount; i < bl_list_count; i++ ) {
- if( bl_list[ i ]->prev ) { //func() may delete this bl_list[] slot, checking for prev ensures it wasn't queued for deletion.
- va_copy(ap_copy, ap);
- returnCount += func(bl_list[i], ap_copy);
- va_end(ap_copy);
- }
- }
- map_freeblock_unlock();
- bl_list_count = blockcount;
- return returnCount; //[Skotlex]
- }
- int map_foreachinallrange2(int(*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int16 range, int type, ...)
- {
- int returnCount = 0;
- va_list ap;
- va_start(ap,type);
- returnCount = map_foreachinrangeV2(func,m, x, y,range,type,ap,false);
- va_end(ap);
- return returnCount;
- }
- --
- map.hpp:
- 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)
- 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