viewing paste Charm System v1.0 | C | Private

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
/*
 Charm System(aka Bonus without equip) Plugin
 -- By Dastgir/Hercules
 -- For Karazu
 -- Please do not remove credits.
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../3rdparty/libconfig/libconfig.h"
 
#include "common/HPMi.h"
#include "common/malloc.h"
#include "common/mmo.h"
#include "common/socket.h"
#include "common/strlib.h"
#include "common/sql.h"
#include "common/utils.h"
#include "common/nullpo.h"
#include "common/conf.h"
#include "common/cbasetypes.h"
 
#include "map/mob.h"
#include "map/map.h"
#include "map/clif.h"
#include "map/pc.h"
#include "map/script.h"
#include "map/elemental.h"
#include "map/npc.h"
#include "map/status.h"
#include "map/storage.h"
#include "map/itemdb.h"
#include "map/guild.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 = {
    "Charm System",// 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)
};
 
struct item_charm_data {
    bool charm;
};
 
int charm_stackable(int *nameid){
    struct item_data *data;
    struct item_charm_data *icdt;
    data = itemdb->search(*nameid);
    if( !(icdt = getFromITEMDATA(data,0)) )
        return 1;
    if (icdt->charm==true){
        hookStop();
        return 0;
    }
    return 1;
}
 
int charm_stackable2(struct item_data *data){
    struct item_charm_data *icdt;
    nullpo_ret(data);
    if( !(icdt = getFromITEMDATA(data,0)) )
        return 1;
    if (icdt->charm==true){
        hookStop();
        return 0;
    }
    return 1;
}
 
int charm_add(int retVal, struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type){
    struct item_data *data;
    struct item_charm_data *icdt;
    if (retVal!=0){
        return retVal;
    }
    
    data = itemdb->search(item_data->nameid);
    if( !(icdt = getFromITEMDATA(data,0)) )
        return retVal;
    if(icdt->charm == true) status->calc_pc_(sd,0);
    return retVal;
}
 
 
int charm_del_pre(struct map_session_data *sd,int *n_,int *amount_,int *type_, short *reason, e_log_pick_type *log_type){
    struct item_charm_data *icdt;
    int n = *n_;
    if (sd->inventory_data[n] == NULL){
        return 0;
    }
    if( !(icdt = getFromITEMDATA(sd->inventory_data[n],0)) )
        return 0;
    if (icdt->charm == true){
        status->calc_pc_(sd,0);
    }
    return 0;
}
 
void charm_bonus(struct map_session_data* sd, enum e_status_calc_opt *opt_) {
    int i;
    struct item_charm_data *icdt;
    for ( i=0; i < MAX_INVENTORY; i++ ) { //dh
        if ( !sd->inventory_data[i])
            continue;
        if( !(icdt = getFromITEMDATA(sd->inventory_data[i],0)) )
            continue;
        if (icdt->charm == false)
            continue;
        if ( sd->inventory_data[i]->script) {
            script->run( sd->inventory_data[i]->script, 0, sd->bl.id, 0 );
        }
    }
    return;
}
 
void charm_readdb(int* itemid, config_setting_t *it, int *n_, const char *source){
    int item_id = *itemid;
    struct item_data *id = itemdb->load(item_id);
    config_setting_t *t = NULL;
    struct item_charm_data *icdt;
    if( !(icdt = getFromITEMDATA(id,0)) ) {
        CREATE(icdt,struct item_charm_data,1);
        addToITEMDATA(id,icdt,0,true);
    }
    if ((t = libconfig->setting_get_member(it, "Charm"))) {
        if (libconfig->setting_get_bool(t)){
            icdt->charm = true;
        }
    }
}
 
HPExport void plugin_init(void) {
    iMalloc = GET_SYMBOL("iMalloc");
    mob = GET_SYMBOL("mob");
    script = GET_SYMBOL("script");
    clif = GET_SYMBOL("clif");
    pc = GET_SYMBOL("pc");
    map = GET_SYMBOL("map");
    npc = GET_SYMBOL("npc");
    status = GET_SYMBOL("status");
    storage = GET_SYMBOL("storage");
    itemdb = GET_SYMBOL("itemdb");
    guild = GET_SYMBOL("guild");
    nullpo = GET_SYMBOL("nullpo");
    libconfig = GET_SYMBOL("libconfig");
 
    addHookPre("itemdb->isstackable", charm_stackable);
    addHookPre("itemdb->isstackable2", charm_stackable2);
    addHookPre("itemdb->readdb_additional_fields",charm_readdb);
    addHookPre("status->calc_pc_additional", charm_bonus);
    addHookPost("pc->additem", charm_add);
    addHookPre("pc->delitem", charm_del_pre);
}
 
HPExport void server_online (void) {
    ShowInfo ("'%s' Plugin by Dastgir/Hercules. Version '%s'\n",pinfo.name,pinfo.version);
}
 
 
Viewed 632 times, submitted by Dastgir.