Jump to content
  • 0

NPC mob kill


Antares

Question


  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  420
  • Reputation:   89
  • Joined:  01/30/12
  • Last Seen:  

Dear scripter gods, I request your assistance!

 

Is the following possible?

  1. Create an NPC, that walks a large, path with many stops
  2. Upon every stop, the NPC should scan it's close area (eg.: 15X15) for any monsters
  3. If monster is present, rush next to it, show some flashy effect, and "kill" the monster, by either command or any other way, but only that one monster, so @killmonster is not good.
  4. After "killing" a monster, repeat step 2.
  5. If no more monsters are present, resume path.

As you can see, basically, I want a patrolling guard, mainly for cities.

 

Afaik, step 1. is possible. The questions are: scan area for mob, get mob pos, instakill only one mob.

 

Alternatively, if we can get mobs to walk paths, and kill other mobs, it would be good as well.

 

/+

Bonus track: Is this possible against specific players?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 1

  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

script

prontera,150,150,0	script	Cleaner	1002,15,15,{
end;
OnTouchNPC:
	.@gid = monsterattached();
	getmapxy .@map$, .@x, .@y, 3;
	
// move to 1 cell near the mob / min distance between npc-mob
	if ( .@x > .x0 )
		.@dx = -1;
	else if ( .@x < .x0 )
		.@dx = 1;
	if ( .@y > .y0 )
		.@dy = -1;
	else if ( .@y < .y0 )
		.@dy = 1;

	.@x_tmp = .@x + .@dx;
	.@y_tmp = .@y + .@dy;
	if ( !checkcell(.@map$,.@x_tmp,.@y_tmp,cell_chkpass) ) {
		for ( .@dx = -1; .@dx < 2 && .@break == 0; .@dx++ )
			for ( .@dy = -1; .@dy < 2; .@dy++ ) {
				if ( .@dx == 0 && .@dy == 0 ) continue;
				.@x_tmp = .@x + .@dx;
				.@y_tmp = .@y + .@dy;
				if ( checkcell(.@map$,.@x_tmp,.@y_tmp,cell_chkpass) ) {
					.@break = 1;
					break;
				}
			}
	}
	if ( .@x_tmp != .@x && .@y_tmp != .@y )
		movenpc strnpcinfo(3), .@x_tmp, .@y_tmp;
	specialeffectmob 10;
	unitkill .@gid;
	end;
OnInit:
	getmapxy .@map$, .x0, .y0, 1;
	// .@npc_name$ = strnpcinfo(3);
	npcspeed 50;

	freeloop 1;
	while( true ) {
		sleep 10000;
		do {
			.@x = .x0 + rand(-10,10);
			.@y = .y0 + rand(-10,10);
		} while( !checkcell(.@map$,.@x,.@y,cell_chkpass) );
		.x0 = .@x;
		.y0 = .@y;
		npcwalkto .x0, .y0;
		// movenpc .@npc_name$, .x0, .y0;
	}
}

src

 src/custom/script.inc     | 19 +++++++++++++++++++
 src/custom/script_def.inc |  3 +++
 src/map/script.c          |  8 ++++++++
 3 files changed, 30 insertions(+)

diff --git a/src/custom/script.inc b/src/custom/script.inc
index 1e01c88..c8e825c 100644
--- a/src/custom/script.inc
+++ b/src/custom/script.inc
@@ -17,3 +17,22 @@
 //	script_pushint(st,1);
 //	return 0;
 //}
+
+BUILDIN_FUNC(monsterattached)
+{
+	struct block_list *bl = map_id2bl(st->rid);
+	if(st->rid == 0 || bl == NULL || bl->type != BL_MOB)
+		script_pushint(st,0);
+	else
+		script_pushint(st,st->rid);
+	return SCRIPT_CMD_SUCCESS;
+}
+
+BUILDIN_FUNC(specialeffectmob)
+{
+	int type = script_getnum(st,2);
+	struct block_list *bl=map_id2bl(st->rid);
+	if(bl != NULL && bl->type == BL_MOB)
+		clif_specialeffect(bl, type, AREA);
+	return SCRIPT_CMD_SUCCESS;
+}
\ No newline at end of file
diff --git a/src/custom/script_def.inc b/src/custom/script_def.inc
index 3319eea..5a75166 100644
--- a/src/custom/script_def.inc
+++ b/src/custom/script_def.inc
@@ -9,3 +9,6 @@
  **/
 
 //BUILDIN_DEF(example,""),
+
+BUILDIN_DEF(monsterattached,""),
+BUILDIN_DEF(specialeffectmob,"i"),
\ No newline at end of file
diff --git a/src/map/script.c b/src/map/script.c
index b6be34d..29d0634 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -13986,6 +13986,14 @@ int recovery_sub(struct map_session_data* sd, int revive)
 				bl = &sd->pd->bl;
 			break;
 		case 3:	//Get Mob Position
+			if( script_hasdata(st,6) ) {
+				struct script_data *data = script_getdata(st,6);
+				get_val(st, data);
+				if( !data_isstring(data) )
+					bl = map_id2bl(script_getnum(st, 6));
+			}
+			else if( st->rid && map_id2bl(st->rid) != NULL )
+				bl = map_id2bl(st->rid);
 			break; //Not supported?
 		case 4:	//Get Homun Position
 			if(script_hasdata(st,6))

I didn't thought about friendly mob

  • Upvote 3
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  803
  • Reputation:   229
  • Joined:  01/30/13
  • Last Seen:  

Why not just make a friendly mob spawn with large view range? Patrolling is harder I guess.

Link to comment
Share on other sites

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.

×
×
  • Create New...