viewing paste mapmoblist | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
#include <stdio.h>
#include <string.h>
#include "../common/HPMi.h"
#include "../common/mapindex.h"
#include "../map/script.h"
#include "../map/mob.h"
#include "../map/pc.h"
#include "../map/map.h"
 
#include "../common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
    "mapmoblist",       // Plugin name
    SERVER_TYPE_MAP,// Which server types this plugin works with?
    "1.0",          // Plugin version
    HPM_VERSION,    // HPM Version (don't change, macro is automatically updated)
};
 
static int count_mob(struct block_list *bl, va_list ap) // [FE]
{
    struct mob_data *md = (struct mob_data*)bl;
    int id = va_arg(ap, int);
    if (md->class_ == id)
        return 1;
    return 0;
}
 
ACMD(mapmoblist)
{
    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, mi = 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
        mi = mapindex->name2id(message);
        if (!mi) {
            clif->message(fd, "Map not found");
            return -1;
        }
        m = map->mapindex2mapid(mi);
    } else {
        // Player doesn't input map name, search mob list in player current map
        mi = sd->mapindex;
        m = sd->bl.m;
    }
 
    clif->message(fd, "--------Monster List--------");
 
    sprintf(temp, "Mapname: %s", mapindex_id2name(mi));
    clif->message(fd, temp);
 
    clif->message(fd, "Monsters: ");
 
    //Looping and search for mobs
    it = mapit_geteachmob();
    while (true) {
        TBL_MOB* md = (TBL_MOB*)mapit->next(it);
        if (md == NULL)
            break;
 
        if (md->bl.m != m || md->status.hp <= 0)
            continue;
        if (mob_searched[md->class_] == true)
            continue; // Already found, skip it
        if (mob->db(md->class_)->mexp) {
            mob_searched[md->class_] = true;
            mob_mvp[md->class_] = true; // Save id for later
            continue; // It's MVP!
        }
 
        mob_searched[md->class_] = true;
        count = map->foreachinmap(count_mob, m, BL_MOB, md->class_);
 
        sprintf(temp, " %s[%d] : %d", mob->db(md->class_)->jname, md->class_, count);
 
        clif->message(fd, temp);
    }
    mapit->free(it);
 
    clif->message(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) {
            count = map->foreachinmap(count_mob, m, BL_MOB, i);
            sprintf(temp, " %s[%d] : %d", mob->db(i)->jname, i, count);
            clif->message(fd, temp);
        }
    }
 
    return true;
}
 
/* Server Startup */
HPExport void plugin_init (void)
{
    mapindex = GET_SYMBOL("mapindex");
    script = GET_SYMBOL("script");
    battle = GET_SYMBOL("battle");
    mapit = GET_SYMBOL("mapit");
    clif = GET_SYMBOL("clif");
    map = GET_SYMBOL("map");
    mob = GET_SYMBOL("mob");
 
    addAtcommand("mapmoblist",mapmoblist);
}
Viewed 908 times, submitted by Guest.