Jump to content
  • 0

Clear monsters in some areas of the map


Question

Posted

Hello, everybody!

I know that the commands 'killmonster' and 'killmonsterall' are used to clear monsters from the map, but they are used to clear all areas of the map, not parts of the map.

How to clear monsters in an area of the map.

3 answers to this question

Recommended Posts

  • 0
Posted

Heya,

You can create a new script command:

static int buildin_killmonsterarea_sub(struct block_list *bl,va_list ap)
{
	int   x1       = va_arg(ap, int);
	int   y1       = va_arg(ap, int);
	int   x2       = va_arg(ap, int);
	int   y2       = va_arg(ap, int);

	if (x1 <= bl->x && bl->x <= x2 &&
		y2 <= bl->y && bl->y <= y1)
		status_kill(bl);
	return 0;
}

BUILDIN_FUNC(killmonsterarea)
{
	const char *mapname;
	int16 m;
	int x1, x2, y1, y2;

	mapname=script_getstr(st,2);

	if( (m = map_mapname2mapid(mapname))<0 )
		return 0;

	x1=script_getnum(st,3);
	y1=script_getnum(st,4);
	x2=script_getnum(st,5);
	y2=script_getnum(st,6);

	map_foreachinmap(buildin_killmonsterarea_sub,m,BL_MOB, x1, y1, x2, y2);
	return SCRIPT_CMD_SUCCESS;
}
      
// def
BUILDIN_DEF(killmonsterarea,"siiii"),

 

  • Upvote 1
  • 0
Posted (edited)

Thank you.

I haven't tried to add a new script command myself.

Thank you for your answer.

On 11/18/2022 at 1:13 AM, Tokei said:

Heya,

You can create a new script command:

static int buildin_killmonsterarea_sub(struct block_list *bl,va_list ap)
{
	int   x1       = va_arg(ap, int);
	int   y1       = va_arg(ap, int);
	int   x2       = va_arg(ap, int);
	int   y2       = va_arg(ap, int);

	if (x1 <= bl->x && bl->x <= x2 &&
		y2 <= bl->y && bl->y <= y1)
		status_kill(bl);
	return 0;
}

BUILDIN_FUNC(killmonsterarea)
{
	const char *mapname;
	int16 m;
	int x1, x2, y1, y2;

	mapname=script_getstr(st,2);

	if( (m = map_mapname2mapid(mapname))<0 )
		return 0;

	x1=script_getnum(st,3);
	y1=script_getnum(st,4);
	x2=script_getnum(st,5);
	y2=script_getnum(st,6);

	map_foreachinmap(buildin_killmonsterarea_sub,m,BL_MOB, x1, y1, x2, y2);
	return SCRIPT_CMD_SUCCESS;
}
      
// def
BUILDIN_DEF(killmonsterarea,"siiii"),

 

Thank you.

I haven't tried to add a new script command myself.

Thank you for your answer.

Edited by shefer
  • 0
Posted

alternative using NPC script

-	script	sample	-1,{

	OnInit:
		bindatcmd("killmonsterarea", strnpcinfo(3)+"::OnStart");
		end;
		
	OnStart:
		if (.@atcmd_numparameters == 4) {
			.@map$ = strcharinfo(3);
			.@x1 = .@atcmd_parameters$[0];
			.@y1 = .@atcmd_parameters$[1];
			.@x2 = .@atcmd_parameters$[2];
			.@y2 = .@atcmd_parameters$[3];
		}
		else if (.@atcmd_numparameters == 5) {
			.@map$ = .@atcmd_parameters$[0];
			.@x1 = .@atcmd_parameters$[1];
			.@y1 = .@atcmd_parameters$[2];
			.@x2 = .@atcmd_parameters$[3];
			.@y2 = .@atcmd_parameters$[4];
		}
		else {
			getmapxy(.@map$, .@pc_x, .@pc_y, BL_PC);
			.@x1 = .@pc_x - 14;
			.@y1 = .@pc_y - 14;
			.@x2 = .@pc_x + 14;
			.@y2 = .@pc_y + 14;
		}
		
		if (getmapusers(.@map$) == -1) {
			dispbottom "Invalid map - "+.@map$+".";
		}
		else {
			.@size = getareaunits(BL_MOB, .@map$, .@x1, .@y1, .@x2, .@y2, .@gid);
			for (.@i = 0; .@i < .@size; .@i++) {
				if (unitexists(.@gid[.@i])) {
					unitkill .@gid[.@i];
					.@count++;
				}
			}
			dispbottom "Killed "+.@count+" monsters";
		}
		end;
}
@killmonsterarea    -> kill monster around you
@killmonsterarea 100 200 200 300   -> kill monster at current map (100,200) to (200,300)
@killmonsterarea prontera 100 200 200 300   -> kill monster at prontera (100,200) to (200,300)

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...