Jump to content

Give Random Item by item Type


Recommended Posts

42 minutes ago, Mali61 said:

char.cpp/ void CHARACTER::GiveRandomSkillBook()

Thanks but ITEM_SKILLBOOK was just an example. I want to use that function for something else bro.. 

 

By looking at ::GiveRandomSkillBook Function i cannot think about how i can change it like i want. :( 

Edited by Kafa
Link to comment
Share on other sites

  • Honorable Member
1 minute ago, Kafa said:

Thanks but ITEM_SKILLBOOK was just an example. I want to use that function for something else bro..

like this?

void CHARACTER::GiveRandomItemByType(BYTE bType)
{
	if (!(bType > ITEM_NONE && bType <= ITEM_BELT)) // my last item type is belt
		return;

	if (bType == ITEM_SKILLBOOK) {
		GiveRandomSkillBook();
		return;
	}
	
	const std::vector<TItemTable>& vItemTable = ITEM_MANAGER::instance().GetTable();
	if (vItemTable.empty())
		return;

	while (true) {
		const int iRandIdx = number(0, vItemTable.size() - 1);
		const TItemTable& table = vItemTable.at(iRandIdx);
		if (table.bType == bType) {
			AutoGiveItem(table.dwVnum);
			break;
		}
	}
}

char.h

void				GiveRandomItemByType(BYTE bType);

USAGE:

character->GiveRandomItemByType(ITEM_ARMOR);
character->GiveRandomItemByType(ITEM_BELT);
  • Not Good 1
  • Good 1
  • Love 1

 

Link to comment
Share on other sites

1 minute ago, Mali61 said:

like this?


void CHARACTER::GiveRandomItemByType(BYTE bType)
{
	if (!(bType > ITEM_NONE && bType <= ITEM_BELT)) // my last item type is belt
		return;

	if (bType == ITEM_SKILLBOOK) {
		GiveRandomSkillBook();
		return;
	}
	
	const std::vector<TItemTable>& vItemTable = ITEM_MANAGER::instance().GetTable();
	if (vItemTable.empty())
		return;

	while (true) {
		const int iRandIdx = number(0, vItemTable.size() - 1);
		const TItemTable& table = vItemTable.at(iRandIdx);
		if (table.bType == bType) {
			AutoGiveItem(table.dwVnum);
			break;
		}
	}
}

char.h


void				GiveRandomItemByType(BYTE bType);

USAGE:


character->GiveRandomItemByType(ITEM_ARMOR);
character->GiveRandomItemByType(ITEM_BELT);

 

Exactly!  

For those who wonder, why ? 

 

I want to create a chest because my upgrade items have type ITEM_UPGRADE. 

 

There are so many hundreds of upgrade items, i cant add all of them in special_drop, thats why i needed this function. 

 

Thank you Mali!!!!!

  • Metin2 Dev 2
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.