viewing paste makeitem2.c | C

Posted on the | Last edited on
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
// fixed from http://herc.ws/board/topic/6040-script-cmd-makeitem2/ <-- Credit to Angelmelody
 
#include "common/hercules.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "map/pc.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
    "makeitem2", // 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(makeitem2) {
    int nameid,amount,m,x,y;
    const char *mapname;
    struct item_data* id ;
 
    if( script_isstringtype(st, 2) ) {
        const char *name = script_getstr(st, 2);
        if( (id = itemdb->search_name(name)) )
            nameid = id->nameid;
        else {
            ShowError("makeitem2: Nonexistant item %s requested.\n", name);
            return false;
        }       
    } else {
        nameid = script_getnum(st, 2);
        if( nameid <= 0 || !(id = itemdb->exists(nameid)) ) {
            ShowError("makeitem2: Nonexistant item %d requested.\n", nameid);
            return false;
        }
    }
 
    amount  = script_getnum(st,3);
    mapname = script_getstr(st,4);
    x       = script_getnum(st,5);
    y       = script_getnum(st,6);
 
    if(strcmp(mapname,"this")==0) {
        TBL_PC *sd;
        sd = script->rid2sd(st);
        if (!sd) return false; //Failed...
        m=sd->bl.m;
    } else
        m = map->mapname2mapid(mapname);
 
    if( m == -1 ) {
        ShowError("makeitem2: creating map on unexistent map '%s'!\n", mapname);
        return false;
    }
    if(nameid > 0) {
        struct item item_tmp;
        int get_count,i;
        memset(&item_tmp,0,sizeof(item_tmp));
        item_tmp.nameid = nameid;
        item_tmp.identify = script_getnum(st,7);
        item_tmp.refine = script_getnum(st,8);
        item_tmp.attribute = script_getnum(st,9);
        item_tmp.card[0] = script_getnum(st,10);
        item_tmp.card[1] = script_getnum(st,11);
        item_tmp.card[2] = script_getnum(st,12);
        item_tmp.card[3] = script_getnum(st,13);
 
        if(id->type==IT_WEAPON || id->type==IT_ARMOR) {
            if( item_tmp.refine > MAX_REFINE) item_tmp.refine = MAX_REFINE;
        } else if (id->type==IT_PETEGG) {
            item_tmp.identify = 1;
            item_tmp.refine = 0;
        } else {
            item_tmp.identify = 1;
            item_tmp.refine = item_tmp.attribute = 0;
        }
 
        //Check if it's stackable.
        if (!itemdb->isstackable(nameid))
            get_count = 1;
        else
            get_count = amount;
 
        for (i = 0; i < amount; i += get_count)
            map->addflooritem(NULL,&item_tmp,get_count,m,x,y,0,0,0,0);
 
    }
 
    return true;
 
}
 
 
HPExport void plugin_init (void) {
    addScriptCommand( "makeitem2", "visiiiiiiiii", makeitem2);
}
 
Viewed 1329 times, submitted by AnnieRuru.