Jump to content
  • 0

Give Random Item by item Type


Kafa

Question

Hey boys,

 

can someone tell me how i can give a random item from a chest (char_item.cpp)

by item type? Example ITEM_SKILLBOOK. I want to give a random ITEM_SKILLBOOK type item to player.

Link to post

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

I'll be offline for a few months🌛

Link to post
  • 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 post
  • 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 post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  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.



  • Activity

    1. 0

      Compile Server

    2. 0

      QC error message for special characters next to apostrophes

    3. 135

      Render Target Remastered

    4. 0

      Mount not attacking

    5. 2

      Rodnia2 | PVM | International | 3k+ players | Multiple-Languages | 2nd server opening: 13.02.2021

    6. 218

      WorldEditor ReMIX

    7. 54

      Quiver System

    8. 72

      Party Flag

  • Recently Browsing

    No registered users viewing this page.

Shoutbox

Shoutbox

Chatroom Rules

 

Join our Discord

A request for help = Shoutbox Ban

Be respectful & Respect the rules

 

×
×
  • 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.