viewing paste topic/7161- item_mob_data.c | 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../map/atcommand.h"
#include "../map/itemdb.h"
#include "../map/clif.h"
#include "../map/pc.h"
#include "../map/mob.h"
#include "../map/map.h"
 
#include "../common/HPMi.h"
#include "../common/HPMDataCheck.h" // should always be the last file included! (if you don't make it last, it'll intentionally break compile time)
 
HPExport struct hplugin_info pinfo = {
    "item_mob_data",// Plugin name
    SERVER_TYPE_MAP,// Which server types this plugin works with?
    "0.1",          // Plugin version
    HPM_VERSION,    // HPM Version (don't change, macro is automatically updated)
};
 
struct item_data2 {
    bool deny;
};
 
struct mob_db2 {
    bool deny;
};
 
struct mob_data2 {
    bool invincible;
};
 
ACMD(denyitem) {
    struct item_data *idata;
    struct item_data2 *idata2;
    char atcmd_output[CHAT_SIZE_MAX];
    unsigned short item_id = atoi(message);
    if ( !message || !*message ) {
        clif->message( fd, "Syntax : @denyitem <itemID>" );
        return false;
    }
    if ( ( idata = itemdb->exists(item_id) ) == NULL ) {
        clif->message( fd, "Invalid item ID." );
        return false;
    }
    if ( !( idata2 = getFromITEMDATA(idata,0) ) ) {
        CREATE( idata2, struct item_data2, 1 );
        idata2->deny = 1;;
        addToITEMDATA( idata, idata2, 0, true );
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "The item %s is now denied.", idata->jname );
        clif->message( fd, atcmd_output );
    }
    else {
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "The item %s has already denied.", idata->jname );
        clif->message( fd, atcmd_output );
    }
    return true;
}
 
ACMD(testitem) {
    struct item_data *idata;
    struct item_data2 *idata2;
    char atcmd_output[CHAT_SIZE_MAX];
    if ( !message || !*message ) {
        clif->message( fd, "Syntax : @testitem <itemID>" );
        return false;
    }
    if ( ( idata = itemdb->exists( atoi(message) ) ) == NULL ) {
        clif->message( fd, "Invalid item ID." );
        return false;
    }
    if ( idata2 = getFromITEMDATA(idata,0) ) {
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "You can't create %s.", idata->jname );
        clif->message( fd, atcmd_output );
    }
    else {
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "You can create %s.", idata->jname );
        clif->message( fd, atcmd_output );
    }
    return true;
}
 
ACMD(denymob) {
    struct mob_db *mdb;
    struct mob_db2 *mdb2;
    char atcmd_output[CHAT_SIZE_MAX];
    unsigned short mob_id = atoi( message );
    if ( !message || !*message ) {
        clif->message( fd, "Syntax : @testmob <MobID>" );
        return false;
    }
    if ( !mob->db_checkid(mob_id) ) {
        clif->message( fd, "Invalid mob ID." );
        return false;
    }
    mdb = mob->db(mob_id);
    if ( !( mdb2 = getFromMOBDB(mdb,0) ) ) {
        CREATE( mdb2, struct mob_db2, 1 );
        mdb2->deny = 1;;
        addToMOBDB( mdb, mdb2, 0, true );
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "The monster %s is now denied.", mdb->name );
        clif->message( fd, atcmd_output );
    }
    else {
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "The monster %s has already denied.", mdb->name );
        clif->message( fd, atcmd_output );
    }
    return true;
}
 
ACMD(testmob) {
    struct mob_db *mdb;
    struct mob_db2 *mdb2;
    char atcmd_output[CHAT_SIZE_MAX];
    unsigned short mob_id = atoi( message );
    if ( !message || !*message ) {
        clif->message( fd, "Syntax : @testmob <MobID>" );
        return false;
    }
    if ( !mob->db_checkid(mob_id) ) {
        clif->message( fd, "Invalid mob ID." );
        return false;
    }
    mdb = mob->db(mob_id);
    if ( mdb2 = getFromMOBDB(mdb,0) ) {
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "You can't create %s.", mdb->name );
        clif->message( fd, atcmd_output );
        return true;
    }
    else {
        int id = mob->once_spawn( sd, sd->bl.m, sd->bl.x, sd->bl.y, mdb->name, mob_id, 1, "", SZ_SMALL, AI_NONE );
        struct mob_data *mdata = (TBL_MOB*)map->id2bl(id);
        struct mob_data2 *mdata2;
        mdata2 = getFromMOBDATA(mdata,0);
        CREATE( mdata2, struct mob_data2, 1 );
        mdata2->invincible = 1;
        addToMOBDATA( mdata, mdata2, 0, true );
        safesnprintf( atcmd_output, CHAT_SIZE_MAX, "You just create %s.", mdb->name );
        clif->message( fd, atcmd_output );
    }
    return true;
}
 
int battle_check_target_post( int retVal, struct block_list *src, struct block_list *target,int *flag ) {
    if ( retVal == 1 && target->type == BL_MOB ) {
        struct mob_data *mdata = (TBL_MOB*)target;
        struct mob_data2 *mdata2;
        if ( mdata2 = getFromMOBDATA(mdata,0) )
            return -1;
    }
    return retVal;
}
 
HPExport void plugin_init (void) {
    clif = GET_SYMBOL("clif");
    itemdb = GET_SYMBOL("itemdb");
    strlib = GET_SYMBOL("strlib");
    iMalloc = GET_SYMBOL("iMalloc");
    mob = GET_SYMBOL("mob");
    map = GET_SYMBOL("map");
 
    addAtcommand("denyitem",denyitem);
    addAtcommand("testitem",testitem);
    addAtcommand("denymob",denymob);
    addAtcommand("testmob",testmob);
    addHookPost("battle->check_target", battle_check_target_post);
}
Viewed 1419 times, submitted by AnnieRuru.