Jump to content
  • 0

"Convert Headgear to Costume" compiling errors


friomixx

Question


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  18
  • Reputation:   0
  • Joined:  03/02/12
  • Last Seen:  

Hi All,

I'm trying to implement below diff for src/map/atcommand.cpp. This is to convert any headgear to costumes and vice versa.

diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index 43d6ad4d7d..e2897a48b5 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -1218,7 +1218,7 @@ ACMD_FUNC(heal)
 ACMD_FUNC(item)
 {
 	char item_name[100];
-	int number = 0, bound = BOUND_NONE;
+	int number = 0, bound = BOUND_NONE, costume = 0;
 	char flag = 0;
 	struct item item_tmp;
 	struct item_data *item_data[10];
@@ -1267,6 +1267,27 @@ ACMD_FUNC(item)
 
 	for(j--; j>=0; j--){ //produce items in list
 		unsigned short item_id = item_data[j]->nameid;
+		if (!strcmpi(command + 1, "costumeitem"))
+		{
+			if (!battle_config.reserved_costume_id)
+			{
+				clif_displaymessage(fd, "Costume convertion is disable. Set a value for reserved_cosutme_id on your battle.conf file.");
+				return -1;
+			}
+			if (!(item_data[j]->equip&EQP_HEAD_LOW) &&
+				!(item_data[j]->equip&EQP_HEAD_MID) &&
+				!(item_data[j]->equip&EQP_HEAD_TOP) &&
+				!(item_data[j]->equip&EQP_COSTUME_HEAD_LOW) &&
+				!(item_data[j]->equip&EQP_COSTUME_HEAD_MID) &&
+				!(item_data[j]->equip&EQP_COSTUME_HEAD_TOP) &&
+				!(item_data[j]->equip&EQP_GARMENT) &&
+				!(item_data[j]->equip&EQP_COSTUME_GARMENT))
+			{
+				clif_displaymessage(fd, "You cannot costume this item. Costume only work for headgears.");
+				return -1;
+			}
+			costume = 1;
+		}
 		//Check if it's stackable.
 		if (!itemdb_isstackable2(item_data[j]))
 			get_count = 1;
@@ -1277,6 +1298,11 @@ ACMD_FUNC(item)
 				memset(&item_tmp, 0, sizeof(item_tmp));
 				item_tmp.nameid = item_id;
 				item_tmp.identify = 1;
+				if (costume == 1) { // Costume item
+					item_tmp.card[0] = CARD0_CREATE;
+					item_tmp.card[2] = GetWord(battle_config.reserved_costume_id, 0);
+					item_tmp.card[3] = GetWord(battle_config.reserved_costume_id, 1);
+				}
 				item_tmp.bound = bound;
 				if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
 					clif_additem(sd, 0, 0, flag);

however, after compiling, i received below errors. can you help me identify the fix for this errors?
image.thumb.jpeg.db8525b6bcdaa22eeeb356424886c348.jpeg

Below is the complete block code where I implemented the diffs.

/*==========================================
 * @item command (usage: @item <itemdid1:itemid2:itemname:..> <quantity>) (modified by [Yor] for pet_egg)
 * @itembound command (usage: @itembound <name/id_of_item> <quantity> <bound_type>)
 *------------------------------------------*/
ACMD_FUNC(item)
{
	char item_name[100];
	//int number = 0, bound = BOUND_NONE;
	/*[GSF] begin convert headgear to costume*/
	int number = 0, bound = BOUND_NONE, costume = 0;
	/*[GSF] end convert headgear to costume*/
	char flag = 0;
	char *itemlist;

	nullpo_retr(-1, sd);
	memset(item_name, '\0', sizeof(item_name));

	parent_cmd = atcommand_alias_db.checkAlias(command+1);

	if (!strcmpi(parent_cmd,"itembound")) {
		if (!message || !*message || (
			sscanf(message, "\"%99[^\"]\" %11d %11d", item_name, &number, &bound) < 3 &&
			sscanf(message, "%99s %11d %11d", item_name, &number, &bound) < 3))
		{
			clif_displaymessage(fd, msg_txt(sd,295)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity> <bound_type>).
			clif_displaymessage(fd, msg_txt(sd,298)); // Invalid bound type
			return -1;
		}
		if( bound <= BOUND_NONE || bound >= BOUND_MAX ) {
			clif_displaymessage(fd, msg_txt(sd,298)); // Invalid bound type
			return -1;
		}
	} else if (!message || !*message || (
		sscanf(message, "\"%99[^\"]\" %11d", item_name, &number) < 1 &&
		sscanf(message, "%99s %11d", item_name, &number) < 1
	)) {
		clif_displaymessage(fd, msg_txt(sd,983)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity>).
		return -1;
	}

	std::vector<std::shared_ptr<item_data>> items;
	itemlist = strtok(item_name, ":");

	while( itemlist != nullptr ){
		std::shared_ptr<item_data> item = item_db.searchname( itemlist );

		if( item == nullptr ){
			item = item_db.find( strtoul( itemlist, nullptr, 10 ) );
		}

		if( item == nullptr ){
			clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
			return -1;
		}

		items.push_back( item );
		itemlist = strtok(NULL, ":"); //next itemline
	}

	if (number <= 0)
		number = 1;
	int get_count = number;

	// Produce items in list
	for( const auto& item : items ){
		t_itemid item_id = item->nameid;

		/*[GSF] begin convert headgear to costume*/
		if (!strcmpi(command + 1, "costumeitem"))
		{
			if (!battle_config.reserved_costume_id)
			{
				clif_displaymessage(fd, "Costume convertion is disable. Set a value for reserved_cosutme_id on your battle.conf file.");
				return -1;
			}
			if (!(item_data[j]->equip&EQP_HEAD_LOW) &&
				!(item_data[j]->equip&EQP_HEAD_MID) &&
				!(item_data[j]->equip&EQP_HEAD_TOP) &&
				!(item_data[j]->equip&EQP_COSTUME_HEAD_LOW) &&
				!(item_data[j]->equip&EQP_COSTUME_HEAD_MID) &&
				!(item_data[j]->equip&EQP_COSTUME_HEAD_TOP) &&
				!(item_data[j]->equip&EQP_GARMENT) &&
				!(item_data[j]->equip&EQP_COSTUME_GARMENT))
			{
				clif_displaymessage(fd, "You cannot costume this item. Costume only work for headgears.");
				return -1;
			}
			costume = 1;
		}
		/*[GSF] end convert headgear to costume*/

		//Check if it's stackable.
		if( !itemdb_isstackable2( item.get() ) ){
			get_count = 1;
		}

		for( int i = 0; i < number; i += get_count ){
			// if not pet egg
			if (!pet_create_egg(sd, item_id)) {
				struct item item_tmp = {};

				item_tmp.nameid = item_id;
				item_tmp.identify = 1;
				/*[GSF] begin convert headgear to costume*/
				if (costume == 1) { // Costume item
					item_tmp.card[0] = CARD0_CREATE;
					item_tmp.card[2] = GetWord(battle_config.reserved_costume_id, 0);
					item_tmp.card[3] = GetWord(battle_config.reserved_costume_id, 1);
				}
				/*[GSF] end convert headgear to costume*/
				item_tmp.bound = bound;
				if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
					clif_additem(sd, 0, 0, flag);
			}
		}
	}

	if (flag == 0)
		clif_displaymessage(fd, msg_txt(sd,18)); // Item created.
	return 0;
}

 

next is for src/map/script.cpp with below error message, can i also ask for help to fix the error?
Error    C3861    'itemdb_searchname': identifier not found

Below is the block code for above error message.

/*===============================
 * getcostumeitem <item id>;
 * getcostumeitem <"item name">;
 *===============================*/
BUILDIN_FUNC(getcostumeitem)
{
	unsigned short nameid;
	struct item item_tmp;
	TBL_PC *sd;
	struct script_data *data;

	if (!script_rid2sd(sd))
	{	// No player attached.
		script_pushint(st, 0);
		return SCRIPT_CMD_SUCCESS;
	}

	data = script_getdata(st, 2);
	get_val(st, data);
	if (data_isstring(data)) {
		int ep;
		const char *name = conv_str(st, data);
		struct item_data *item_data = itemdb_searchname(name);
		if (item_data == NULL)
		{	//Failed
			script_pushint(st, 0);
			return SCRIPT_CMD_SUCCESS;
		}
		ep = item_data->equip;
		if (!(ep&EQP_HEAD_LOW) && !(ep&EQP_HEAD_MID) && !(ep&EQP_HEAD_TOP) && !(ep&EQP_GARMENT)){
			ShowError("buildin_getcostumeitem: Attempted to convert non-cosmetic item to costume.");
			return SCRIPT_CMD_FAILURE;
		}
		nameid = item_data->nameid;
	}
	else
		nameid = conv_num(st, data);

	if (!itemdb_exists(nameid))
	{	// Item does not exist.
		script_pushint(st, 0);
		return SCRIPT_CMD_SUCCESS;
	}

	memset(&item_tmp, 0, sizeof(item_tmp));
	item_tmp.nameid = nameid;
	item_tmp.amount = 1;
	item_tmp.identify = 1;
	item_tmp.card[0] = CARD0_CREATE;
	item_tmp.card[2] = GetWord(battle_config.reserved_costume_id, 0);
	item_tmp.card[3] = GetWord(battle_config.reserved_costume_id, 1);
	if (pc_additem(sd, &item_tmp, 1, LOG_TYPE_SCRIPT)) {
		script_pushint(st, 0);
		return SCRIPT_CMD_SUCCESS;	//Failed to add item, we will not drop if they don't fit
	}

	script_pushint(st, 1);
	return SCRIPT_CMD_SUCCESS;
}

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  162
  • Topics Per Day:  0.04
  • Content Count:  745
  • Reputation:   47
  • Joined:  03/12/14
  • Last Seen:  

17 hours ago, friomixx said:

next is for src/map/script.cpp with below error message, can i also ask for help to fix the error?
Error    C3861    'itemdb_searchname': identifier not found

item_data = item_db.searchname(item_name)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...