viewing paste topic/7027- equip2.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
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// Sample Hercules Plugin
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../common/HPMi.h"
#include "../map/script.h"
#include "../map/pc.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 = {
    "equip2",       // 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)
};
 
BUILDIN(equip2) {
    int i,nameid,ref,attr,c0,c1,c2,c3;
    struct item_data *item_data;
    TBL_PC *sd;
 
    if( script_hasdata(st,9) )
        sd = map->id2sd(script_getnum(st,9));
    else
        sd = script->rid2sd(st);
 
    if( sd == NULL )
    {
        script_pushint(st,0);
        return 0;
    }
        
    nameid = script_getnum(st,2);
    if( (item_data = itemdb->exists(nameid)) == NULL )
    {
        ShowError("Wrong item ID : equipitem2(%i)\n",nameid);
        script_pushint(st,0);
        return 1;
    }
 
    ref    = script_getnum(st,3);
    attr   = script_getnum(st,4);
    c0     = (short)script_getnum(st,5);
    c1     = (short)script_getnum(st,6);
    c2     = (short)script_getnum(st,7);
    c3     = (short)script_getnum(st,8);
 
    ARR_FIND( 0, MAX_INVENTORY, i,( sd->status.inventory[i].nameid == nameid &&
                                    sd->status.inventory[i].refine == ref &&
                                    sd->status.inventory[i].attribute == attr &&
                                    sd->status.inventory[i].card[0] == c0 &&
                                    sd->status.inventory[i].card[1] == c1 &&
                                    sd->status.inventory[i].card[2] == c2 &&
                                    sd->status.inventory[i].card[3] == c3 ) );
 
    if( i < MAX_INVENTORY ) {
        script_pushint(st,1);
        pc->equipitem(sd,i,item_data->equip);
    }
    else
        script_pushint(st,0);
 
    return true;
}
 
HPExport void plugin_init (void) {
    script = GET_SYMBOL("script");
    pc = GET_SYMBOL("pc");
    map = GET_SYMBOL("map");
    itemdb = GET_SYMBOL("itemdb");
    addScriptCommand( "equip2", "viiiiii?", equip2);
}
Viewed 1222 times, submitted by AnnieRuru.