Jump to content
×
×
  • Create New...
  • 0

Give Random Item by item Type


Kafa

Question

5 answers to this question

Recommended Posts

  • 0
  • 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);
  • Love 1
  • Good 1
  • Not Good 1
Link to comment
Share on other sites

  • 0
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

  • 0
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Activity

    1. 0

      Looking for Someone to create the queries etc for armors and weapons

    2. 13

      Official Private Shop Search

    3. 944

      [40250] Reference Serverfile + Client + Src [15 Available Languages]

    4. 79

      GUI Teleport System

    5. 0

      inventory slot marking system cant compile

    6. 8

      Inventory Bug

    7. 63

      Metin2 Dev - Changelogs

  • Recently Browsing

    • No registered users viewing this page.

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.