Jump to content
  • 0

@mapmoblist - help


Johnson

Question


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   1
  • Joined:  08/22/18
  • Last Seen:  

May I ask help on getting monster to display on mapmoblist command. Somehow, it is not showing any monster data when use on @mapmoblist

image.png.073347d321703b7a4234ea6b418448ee.png

atcommand.cpp
 

static int count_mob(struct block_list *bl, va_list ap) // [FE]
{
   struct mob_data *md = (struct mob_data*)bl;
   short id = va_arg(ap, short);
   if (md->mob_id == id)
       return 1;
   return 0;
}

ACMD_FUNC(mapmoblist) // [FE]
{
   char temp[100];
   bool mob_searched[MAX_MOB_DB];
   bool mob_mvp[MAX_MOB_DB]; // Store mvp data..
   struct s_mapiterator* it;
   unsigned short count = 0, i, mapindex = 0;
   int m = 0;


   memset(mob_searched, 0, MAX_MOB_DB);
   memset(mob_mvp, 0, MAX_MOB_DB);

   if (message && *message) {
       // Player input map name, search mob list for that map
       mapindex = mapindex_name2id(message);
       if (!mapindex) {
           clif_displaymessage(fd, "Map not found");
           return -1;
       }
       m = map_mapindex2mapid(mapindex);
   } else {
       // Player doesn't input map name, search mob list in player current map
       mapindex = sd->mapindex;
       m = sd->bl.m;
   }

   clif_displaymessage(fd, "--------Monster List--------");

   sprintf(temp, "Mapname: %s", mapindex_id2name(mapindex));
   clif_displaymessage(fd, temp);

   clif_displaymessage(fd, "Monsters: ");

   //Looping and search for mobs
   it = mapit_geteachmob();
   while (true) {
       TBL_MOB* md = (TBL_MOB*)mapit_next(it);
       uint16 mob_id;
       std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);

       if (md == NULL)
           break;

       if (md->bl.m != m || md->status.hp <= 0)
           continue;
       if (mob_searched[md->mob_id] == true)
           continue; // Already found, skip it
       if (md->db->mexp) {
           mob_searched[md->mob_id] = true;
           mob_mvp[md->mob_id] = true; // Save id for later
           continue; // It's MVP!
       }

       mob_searched[md->mob_id] = true;
       count = map_foreachinmap(count_mob, m, BL_MOB, md->mob_id);

       sprintf(temp, " %s[%d] : %d", mob->jname, md->mob_id, count);

       clif_displaymessage(fd, temp);
   }
   mapit_free(it);

   clif_displaymessage(fd, "MVP: ");

   // Looping again and search for mvp, not sure if this is the best way..
   for (i = 1000; i < MAX_MOB_DB; i++) { //First monster start at 1001 (Scorpion)
       if (mob_mvp[i] == true) {
           TBL_MOB* md = (TBL_MOB*)mapit_next(it);
           count = map_foreachinmap(count_mob, m, BL_MOB, i);
           sprintf(temp, " %s[%d] : %d", md->db->jname, i, count);
           clif_displaymessage(fd, temp);
       }
   }

   return 0;



}

ACMD_DEF(mapmoblist),

Reference & Credits to FatalError:

 

Edited by khouuming21
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

also can try using npc script if you want.

-	script	getmapmob_main	-1,{
  OnInit:
	  bindatcmd "getmapmob", strnpcinfo(3) + "::OnAtcommand";
	  end;

	OnAtcommand:
		.@map$ = strcharinfo(3);
		if (.@atcmd_numparameters) {
			if (getmapusers(.@atcmd_parameters$) == -1) {
				dispbottom "Invalid map " + .@atcmd_parameters$+".";
				end;
			}
			.@map$ = .@atcmd_parameters$;
		}
		.@size = getmapunits(BL_MOB, .@map$);
		for (.@i = 0; .@i < .@size; .@i++) {
			getunitdata .@array[.@i], .@array;
			if (!.@mobcount[.@array[UMOB_CLASS]]) {
				.@mob_id[.@mob_id_size] = .@array[UMOB_CLASS];
				.@mob_id_size++;
			}
			.@mob[.@array[UMOB_CLASS]]++;
		}
		dispbottom "Found "+ .@mob_id_size + " monsters at " + strcharinfo(3);
		for (.@i = .@mob_id_size - 1; .@i >= 0; .@i--) {
			if (getmonsterinfo(.@mob_id[.@i], MOB_MVPEXP) > 0)
				continue;
			dispbottom sprintf(" %s[%d] : %d", getmonsterinfo(.@mob_id[.@i], MOB_NAME), .@mob_id[.@i], .@mob[.@mob_id[.@i]]);
			deletearray .@mob_id[.@i], 1;
			.@mob_id_size--;
		}
		dispbottom "Found "+ .@mob_id_size + " normal monsters at " + strcharinfo(3);
		for (.@i = 0; .@i < .@mob_id_size; .@i++) {
			dispbottom sprintf(" %s[%d] : %d", getmonsterinfo(.@mob_id[.@i], MOB_NAME), .@mob_id[.@i], .@mob[.@mob_id[.@i]]);
		}
		end;
}

but this may cause performance issue, use at your own risk.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   1
  • Joined:  08/22/18
  • Last Seen:  

On 1/23/2024 at 10:56 PM, Emistry said:

also can try using npc script if you want.

-	script	getmapmob_main	-1,{
  OnInit:
	  bindatcmd "getmapmob", strnpcinfo(3) + "::OnAtcommand";
	  end;

	OnAtcommand:
		.@map$ = strcharinfo(3);
		if (.@atcmd_numparameters) {
			if (getmapusers(.@atcmd_parameters$) == -1) {
				dispbottom "Invalid map " + .@atcmd_parameters$+".";
				end;
			}
			.@map$ = .@atcmd_parameters$;
		}
		.@size = getmapunits(BL_MOB, .@map$);
		for (.@i = 0; .@i < .@size; .@i++) {
			getunitdata .@array[.@i], .@array;
			if (!.@mobcount[.@array[UMOB_CLASS]]) {
				.@mob_id[.@mob_id_size] = .@array[UMOB_CLASS];
				.@mob_id_size++;
			}
			.@mob[.@array[UMOB_CLASS]]++;
		}
		dispbottom "Found "+ .@mob_id_size + " monsters at " + strcharinfo(3);
		for (.@i = .@mob_id_size - 1; .@i >= 0; .@i--) {
			if (getmonsterinfo(.@mob_id[.@i], MOB_MVPEXP) > 0)
				continue;
			dispbottom sprintf(" %s[%d] : %d", getmonsterinfo(.@mob_id[.@i], MOB_NAME), .@mob_id[.@i], .@mob[.@mob_id[.@i]]);
			deletearray .@mob_id[.@i], 1;
			.@mob_id_size--;
		}
		dispbottom "Found "+ .@mob_id_size + " normal monsters at " + strcharinfo(3);
		for (.@i = 0; .@i < .@mob_id_size; .@i++) {
			dispbottom sprintf(" %s[%d] : %d", getmonsterinfo(.@mob_id[.@i], MOB_NAME), .@mob_id[.@i], .@mob[.@mob_id[.@i]]);
		}
		end;
}

but this may cause performance issue, use at your own risk.

Hi Emistry, Thanks for this i have managed to do it in src. Will still test this out tho thanks!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  48
  • Topics Per Day:  0.02
  • Content Count:  180
  • Reputation:   6
  • Joined:  10/22/18
  • Last Seen:  

On 1/26/2024 at 11:36 PM, khouuming21 said:

Hi Emistry, Thanks for this i have managed to do it in src. Will still test this out tho thanks!

hi, kindly share the solution to the community.

thanks

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...