Jump to content
  • We need you!

    You must register to discover all the features of our community!

Fix Pickup distances bug


Recommended Posts

Well, first I had a BUG on a client, if there were a lot of items on the floor, I kept pressing Z to pick up the items, until suddenly he stopped picking up. Then, I found that the function that maps the items that were nearby simply sent the package to pick up an item that was too far away and ignored those that were really close.

 

I searched a lot on google for a solution, I saw two or three post with this same bug, but without solution.

 

I know almost nothing about C ++, but I managed and managed to solve it. If anyone has an idea, or any better way to resolve it, please leave your idea.

 

 

So what did I do?

 

Spoiler

locale_inc.h

Add:
 

#define ENABLE_FIX_PICKITEM



PythonItem.cpp
 

Search and replace the entire function:

 



bool CPythonItem::GetCloseItem(const TPixelPosition & c_rPixelPosition, DWORD * pdwItemID, DWORD dwDistance)
{
    DWORD dwCloseItemID = 0;
    DWORD dwCloseItemDistance = 1000 * 1000;

    TGroundItemInstanceMap::iterator i;
    for (i = m_GroundItemInstanceMap.begin(); i != m_GroundItemInstanceMap.end(); ++i)
    {
        TGroundItemInstance * pInstance = i->second;

        DWORD dwxDistance = DWORD(c_rPixelPosition.x-pInstance->v3EndPosition.x);
        DWORD dwyDistance = DWORD(c_rPixelPosition.y-(-pInstance->v3EndPosition.y));
        DWORD dwDistance = DWORD(dwxDistance*dwxDistance + dwyDistance*dwyDistance);

        if (dwxDistance*dwxDistance + dwyDistance*dwyDistance < dwCloseItemDistance)
        {
            dwCloseItemID = i->first;
            dwCloseItemDistance = dwDistance;
        }
    }

    if (dwCloseItemDistance>float(dwDistance)*float(dwDistance))
        return false;

    *pdwItemID=dwCloseItemID;

    return true;
}


for this:
 

#ifdef ENABLE_FIX_PICKITEM
int DISTANCE_APPROX(int dx, int dy)
{
	int min, max;

	if (dx < 0)
		dx = -dx;

	if (dy < 0)
		dy = -dy;

	if (dx < dy)
	{
		min = dx;
		max = dy;
	}
	else
	{
		min = dy;
		max = dx;
	}

	// coefficients equivalent to ( 123/128 * max ) and ( 51/128 * min )
	return (((max << 8) + (max << 3) - (max << 4) - (max << 1) +
		(min << 7) - (min << 5) + (min << 3) - (min << 1)) >> 8);
}

bool CPythonItem::GetCloseItem(const TPixelPosition& c_rPixelPosition, DWORD* pdwItemID, DWORD dwDistance)
{
	DWORD dwCloseItemID = 0;
	DWORD dwCloseItemDistance = 0;
	int aproMin = 0;

	TGroundItemInstanceMap::iterator i;
	for (i = m_GroundItemInstanceMap.begin(); i != m_GroundItemInstanceMap.end(); ++i)
	{
		TGroundItemInstance* pInstance = i->second;

		int iDist = DISTANCE_APPROX((int)c_rPixelPosition.x - (int)pInstance->v3EndPosition.x, (int)c_rPixelPosition.y - (-(int)pInstance->v3EndPosition.y));
		if (aproMin == 0)
			aproMin = iDist;
		if (aproMin >= iDist) {
			aproMin = iDist;
			dwCloseItemID = i->first;
			dwCloseItemDistance = iDist;
		}
	}

	if (dwCloseItemDistance > 300)
		return false;

	*pdwItemID = dwCloseItemID;

	return true;
}
#else
bool CPythonItem::GetCloseItem(const TPixelPosition& c_rPixelPosition, DWORD* pdwItemID, DWORD dwDistance)
{
	DWORD dwCloseItemID = 0;
	DWORD dwCloseItemDistance = 1000 * 1000;

	TGroundItemInstanceMap::iterator i;
	for (i = m_GroundItemInstanceMap.begin(); i != m_GroundItemInstanceMap.end(); ++i)
	{
		TGroundItemInstance* pInstance = i->second;

		DWORD dwxDistance = DWORD(c_rPixelPosition.x - pInstance->v3EndPosition.x);
		DWORD dwyDistance = DWORD(c_rPixelPosition.y - (-pInstance->v3EndPosition.y));
		DWORD dwDistance = DWORD(dwxDistance * dwxDistance + dwyDistance * dwyDistance);

		if (dwxDistance * dwxDistance + dwyDistance * dwyDistance < dwCloseItemDistance)
		{
			dwCloseItemID = i->first;
			dwCloseItemDistance = dwDistance;
		}
	}

	if (dwCloseItemDistance > float(dwDistance) * float(dwDistance))
		return false;

	*pdwItemID = dwCloseItemID;

	return true;
}
#endif

 

 

With that he will always pick the item that is at a closer average distance, different from the other function that I did not understand well how it worked...
As I said, I am very lay with C ++, but there is a solution to a bug that I solved.

Edited by valdirk2
Fixing tutorial (see edit history)
  • Love 3
  • Poop 1
Link to post
2 hours ago, valdirk2 said:

Where is this fix? I spent two hours searching on google and didn't find any correction, if someone did a fix better than mine, I definitely want to use it.

It is not your fix wtf

Link to post

 

2 hours ago, valdirk2 said:

Where is this fix? I spent two hours searching on google and didn't find any correction, if someone did a fix better than mine, I definitely want to use it.

Whats wrong with you ?

Lead @ another famous Metin2 Forum did create this code.

Pay him respect with a mention or i report your "fix" for being stolen

Link to post

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


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