// 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);
}