#include #include #include #include "../map/atcommand.h" #include "../map/itemdb.h" #include "../map/clif.h" #include "../map/pc.h" #include "../map/pet.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 = { "at_item", // 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) }; int item_deny_id[999]; // deny up to 999 items, int item_deny_lv[999]; // which means allow up to 999 entries in `item_deny` table int item_deny_total = 0; void load_item_deny(void) { if ( SQL->Query( map->mysql_handle, "select * from item_deny" ) == SQL_ERROR ) Sql_ShowDebug( map->mysql_handle ); else { int i = 0; char *data; while ( SQL->NextRow( map->mysql_handle ) == SQL_SUCCESS ) { if ( SQL->GetData( map->mysql_handle, 0, &data, NULL ) == SQL_SUCCESS ) item_deny_id[i] = atoi(data); if ( SQL->GetData( map->mysql_handle, 1, &data, NULL ) == SQL_SUCCESS ) item_deny_lv[i] = atoi(data); i++; } item_deny_total = i; SQL->FreeResult( map->mysql_handle ); } return; } HPExport void server_online (void) { load_item_deny(); } ACMD(reloaditemdeny) { int i; char aaa[255]; load_item_deny(); clif->message( fd, "Item Deny has been reloaded." ); safesnprintf( aaa, 255, "Total -> %d", item_deny_total ); clif->message( fd, aaa ); for ( i = 0; i < item_deny_total; i++ ) { safesnprintf( aaa, 255, "Item ID %d : Deny lv %d", item_deny_id[i], item_deny_lv[i] ); clif->message( fd, aaa ); } return true; } ACMD(item) { char item_name[100]; int number = 0, item_id, flag = 0, bound = 0; struct item item_tmp; struct item_data *item_data; int get_count, i; memset(item_name, '\0', sizeof(item_name)); if (!strcmp(info->command,"itembound") && (!message || !*message || ( sscanf(message, "\"%99[^\"]\" %d %d", item_name, &number, &bound) < 2 && sscanf(message, "%99s %d %d", item_name, &number, &bound) < 2 ))) { clif->message(fd, msg_txt(295)); // Please enter an item name or ID (usage: @itembound ). return false; } else if (!message || !*message || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 && sscanf(message, "%99s %d", item_name, &number) < 1 )) { clif->message(fd, msg_txt(983)); // Please enter an item name or ID (usage: @item ). return false; } if (number <= 0) number = 1; if ((item_data = itemdb->search_name(item_name)) == NULL && (item_data = itemdb->exists(atoi(item_name))) == NULL ) { clif->message(fd, msg_txt(19)); // Invalid item ID or name. return false; } if (!strcmp(info->command,"itembound") ) { if( !(bound >= IBT_MIN && bound <= IBT_MAX) ) { clif->message(fd, msg_txt(298)); // Invalid bound type return false; } switch( (enum e_item_bound_type)bound ) { case IBT_CHARACTER: case IBT_ACCOUNT: break; /* no restrictions */ case IBT_PARTY: if( !sd->status.party_id ) { clif->message(fd, msg_txt(1498)); //You can't add a party bound item to a character without party! return false; } break; case IBT_GUILD: if( !sd->status.guild_id ) { clif->message(fd, msg_txt(1499)); //You can't add a guild bound item to a character without guild! return false; } break; } } item_id = item_data->nameid; for ( i = 0; i < item_deny_total; i++ ) { if ( item_deny_id[i] == item_id ) { if ( pc_get_group_level(sd) < item_deny_lv[i] ) { clif->message( fd, "You are restricted from creating this item." ); return false; } } } get_count = number; //Check if it's stackable. if (!itemdb->isstackable2(item_data)) { if( bound && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) { clif->message(fd, msg_txt(498)); // Cannot create bounded pet eggs or pet armors. return false; } get_count = 1; } for (i = 0; i < number; i += get_count) { // if not pet egg if (!pet->create_egg(sd, item_id)) { memset(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = 1; item_tmp.bound = (unsigned char)bound; if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } } if (flag == 0) clif->message(fd, msg_txt(18)); // Item created. return true; } ACMD(item2) { struct item item_tmp; struct item_data *item_data; char item_name[100]; int item_id, number = 0, bound = 0; int identify = 0, refine = 0, attr = 0; int c1 = 0, c2 = 0, c3 = 0, c4 = 0; memset(item_name, '\0', sizeof(item_name)); if (!strcmp(info->command,"itembound2") && (!message || !*message || ( sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 && sscanf(message, "%99s %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) { clif->message(fd, msg_txt(296)); // Please enter all parameters (usage: @itembound2 clif->message(fd, msg_txt(297)); // ). return false; } else if ( !message || !*message || ( sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 && sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 )) { clif->message(fd, msg_txt(984)); // Please enter all parameters (usage: @item2 clif->message(fd, msg_txt(985)); // ). return false; } if (number <= 0) number = 1; if( !strcmp(info->command,"itembound2") && !(bound >= IBT_MIN && bound <= IBT_MAX) ) { clif->message(fd, msg_txt(298)); // Invalid bound type return false; } item_id = 0; if ((item_data = itemdb->search_name(item_name)) != NULL || (item_data = itemdb->exists(atoi(item_name))) != NULL) item_id = item_data->nameid; if (item_id > 500) { int flag = 0; int loop, get_count, i; loop = 1; get_count = number; if( !strcmp(info->command,"itembound2") ) bound = 1; if( !itemdb->isstackable2(item_data) ) { if( bound && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) { clif->message(fd, msg_txt(498)); // Cannot create bounded pet eggs or pet armors. return false; } loop = number; get_count = 1; if (item_data->type == IT_PETEGG) { identify = 1; refine = 0; } if (item_data->type == IT_PETARMOR) refine = 0; if (refine > MAX_REFINE) refine = MAX_REFINE; } else { identify = 1; refine = attr = 0; } for ( i = 0; i < item_deny_total; i++ ) { if ( item_deny_id[i] == item_id ) { if ( pc_get_group_level(sd) < item_deny_lv[i] ) { clif->message( fd, "You are restricted from creating this item." ); return false; } } } for (i = 0; i < loop; i++) { memset(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = identify; item_tmp.refine = refine; item_tmp.attribute = attr; item_tmp.bound = (unsigned char)bound; item_tmp.card[0] = c1; item_tmp.card[1] = c2; item_tmp.card[2] = c3; item_tmp.card[3] = c4; if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } if (flag == 0) clif->message(fd, msg_txt(18)); // Item created. } else { clif->message(fd, msg_txt(19)); // Invalid item ID or name. return false; } return true; } ACMD(produce) { char item_name[100], atcmd_output[255]; int item_id, attribute = 0, star = 0, i = 0; struct item_data *item_data; struct item tmp_item; memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(item_name, '\0', sizeof(item_name)); if (!message || !*message || ( sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 && sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1 )) { clif->message(fd, msg_txt(1007)); // Please enter at least one item name/ID (usage: @produce <# of very's>). return false; } if ( (item_data = itemdb->search_name(item_name)) == NULL && (item_data = itemdb->exists(atoi(item_name))) == NULL ) { clif->message(fd, msg_txt(170)); //This item is not an equipment. return false; } item_id = item_data->nameid; for ( i = 0; i < item_deny_total; i++ ) { if ( item_deny_id[i] == item_id ) { if ( pc_get_group_level(sd) < item_deny_lv[i] ) { clif->message( fd, "You are restricted from creating this item." ); return false; } } } if (itemdb->isequip2(item_data)) { int flag = 0; if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE) attribute = ATTRIBUTE_NORMAL; if (star < MIN_STAR || star > MAX_STAR) star = 0; memset(&tmp_item, 0, sizeof tmp_item); tmp_item.nameid = item_id; tmp_item.amount = 1; tmp_item.identify = 1; tmp_item.card[0] = CARD0_FORGE; tmp_item.card[1] = item_data->type==IT_WEAPON? ((star*5) << 8) + attribute:0; tmp_item.card[2] = sd->status.char_id & 0xFFFF; tmp_item.card[3] = sd->status.char_id >> 16; clif->produce_effect(sd, 0, item_id); clif->misceffect(&sd->bl, 3); if ((flag = pc->additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } else { safesnprintf(atcmd_output, 255, msg_txt(169), item_id, item_data->name); // The item (%d: '%s') is not equipable. clif->message(fd, atcmd_output); return false; } return true; } HPExport void plugin_init (void) { atcommand = GET_SYMBOL("atcommand"); clif = GET_SYMBOL("clif"); map = GET_SYMBOL("map"); itemdb = GET_SYMBOL("itemdb"); strlib = GET_SYMBOL("strlib"); pet = GET_SYMBOL("pet"); pc = GET_SYMBOL("pc"); SQL = GET_SYMBOL("SQL"); addAtcommand("item",item); addAtcommand("item2",item2); addAtcommand("produce",produce); addAtcommand("reloaditemdeny",reloaditemdeny); }