Jump to content

Check Position for Shops


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

Hello!

I'd like to show you how you can check position for shops (probably offline shops too).
I don't like when the map is full of shops or when shops are too close for each other. So I've made few functions for checking if the shop is in safezone or if it too close to other shops.

Let's start :)

char.h

Find there:

		void			CloseMyShop();

	protected:

		LPSHOP			m_pkShop;
		LPSHOP			m_pkMyShop;
		std::string		m_stShopSign;
		LPCHARACTER		m_pkChrShopOwner;

Add few new lines:

		void			CloseMyShop();
		void			SetShopValidPos(bool value) { m_bShopValidPos = value; }
		bool			GetShopValidPos() { return m_bShopValidPos; }

	protected:

		LPSHOP			m_pkShop;
		LPSHOP			m_pkMyShop;
		std::string		m_stShopSign;
		LPCHARACTER		m_pkChrShopOwner;
		bool			m_bShopValidPos;

char.cpp

In 'void CHARACTER::Initialize()' find:

	m_pkMyShop		= NULL;

Add below:

	m_bShopValidPos = true;

Then search for 'void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)'

Add above new function:

struct CheckShopPos
{
	LPCHARACTER m_ch;
	CheckShopPos(LPCHARACTER ch)
	{
		m_ch = ch;
	}

	void operator()(LPENTITY ent)
	{
		if (ent->IsType(ENTITY_CHARACTER))
		{
			LPCHARACTER ch = (LPCHARACTER) ent;
			if (ch->GetRaceNum()!=30000) //shop mob vnum
				return;

			if (DISTANCE_APPROX(ch->GetX() - m_ch->GetX(), ch->GetY() - m_ch->GetY()) < 200) //distance between shops
			{
				m_ch->SetShopValidPos(false);
			}
		}
	}
};

Then in 'void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)' search for:

	if (bItemCount == 0)
		return;

Add below:

	//shops pos check
	LPSECTREE sectree = GetSectree();
	if (sectree)
	{

		SetShopValidPos(true);

		CheckShopPos f(this);
		sectree->ForEachAround(f);

		if(!GetShopValidPos())
		{
			ChatPacket(CHAT_TYPE_INFO, "You cannot open a shop here (too close to other shop).");
			return;
		}

		if (!sectree->IsAttr(GetX(), GetY(), ATTR_BANPK))
		{
			ChatPacket(CHAT_TYPE_INFO, "You cannot open a shop here (use safezone).");
			return;
		}
	}
	//shops pos check

 

P.s:

Spoiler

1. Make backups before change your source.
2. If you'll repost this solution somewhere, please keep credits.
3. Likes and comments appreciated.

 

That's all, have fun ;)
Regards.

  • Metin2 Dev 2
  • Scream 1
  • Good 4
  • Love 10
Link to comment
Share on other sites

  • Gold

Really nice release, this is what I need on my server. Thank you for that. I will try it when I will be at home. And, can you do that without checking shops is near to each other? So only with safe zone checking? And how can I add new shop number? only with 30000, 30001 etc.?

Thanks for answer. 

Regards ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

29 minutes ago, ReFresh said:

And, can you do that without checking shops is near to each other?

Just comment this part:

		SetShopValidPos(true);

		CheckShopPos f(this);
		sectree->ForEachAround(f);

		if(!GetShopValidPos())
		{
			ChatPacket(CHAT_TYPE_INFO, "You cannot open a shop here (too close to other shop).");
			return;
		}

 

30 minutes ago, ReFresh said:

And how can I add new shop number? only with 30000, 30001 etc.?

You need to add this numbers in 'struct CheckShopPos', something like this:

			if (ch->GetRaceNum()!=30000 || !ch->GetRaceNum()!=30001) //shop mob vnum
				return;

or in case if you have some range of vnums (for example between 30000 and 30010):

			if (ch->GetRaceNum() < 30000 && ch->GetRaceNum() > 30010) //shop mob vnum
				return;

 

  • Love 2
Link to comment
Share on other sites

23 hours ago, wezt said:

Hello!

I'd like to show you how you can check position for shops (probably offline shops too).
I don't like when the map is full of shops or when shops are too close for each other. So I've made few functions for checking if the shop is in safezone or if it too close to other shops.

Let's start :)

char.h

Find there:


		void			CloseMyShop();

	protected:

		LPSHOP			m_pkShop;
		LPSHOP			m_pkMyShop;
		std::string		m_stShopSign;
		LPCHARACTER		m_pkChrShopOwner;

Add few new lines:


		void			CloseMyShop();
		void			SetShopValidPos(bool value) { m_bShopValidPos = value; }
		bool			GetShopValidPos() { return m_bShopValidPos; }

	protected:

		LPSHOP			m_pkShop;
		LPSHOP			m_pkMyShop;
		std::string		m_stShopSign;
		LPCHARACTER		m_pkChrShopOwner;
		bool			m_bShopValidPos;

char.cpp

In 'void CHARACTER::Initialize()' find:


	m_pkMyShop		= NULL;

Add below:


	m_bShopValidPos = true;

Then search for 'void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)'

Add above new function:


struct CheckShopPos
{
	LPCHARACTER m_ch;
	CheckShopPos(LPCHARACTER ch)
	{
		m_ch = ch;
	}

	void operator()(LPENTITY ent)
	{
		if (ent->IsType(ENTITY_CHARACTER))
		{
			LPCHARACTER ch = (LPCHARACTER) ent;
			if (ch->GetRaceNum()!=30000) //shop mob vnum
				return;

			if (DISTANCE_APPROX(ch->GetX() - m_ch->GetX(), ch->GetY() - m_ch->GetY()) < 200) //distance between shops
			{
				m_ch->SetShopValidPos(false);
			}
		}
	}
};

Then in 'void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)' search for:


	if (bItemCount == 0)
		return;

Add below:


	//shops pos check
	LPSECTREE sectree = NULL;
	sectree = GetSectree();
	if (sectree)
	{

		SetShopValidPos(true);

		CheckShopPos f(this);
		sectree->ForEachAround(f);

		if(!GetShopValidPos())
		{
			ChatPacket(CHAT_TYPE_INFO, "You cannot open a shop here (too close to other shop).");
			return;
		}

		if (!sectree->IsAttr(GetX(), GetY(), ATTR_BANPK))
		{
			ChatPacket(CHAT_TYPE_INFO, "You cannot open a shop here (use safezone).");
			return;
		}
	}
	//shops pos check

 

P.s:

  Reveal hidden contents

1. Make backups before change your source.
2. If you'll repost this solution somewhere, please keep credits.
3. Likes and comments appreciated.

 

That's all, have fun ;)
Regards.

hello 

how we do new markets

https://metin2.download/picture/ge83X21H0XvckjfT9uk0h3qTfr3S6hI1/.png

the codes of the market

mob cod (30002)30003)30004)

 

 

These New Markets Are Blocked

 

system thank you 

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • 1 year later...
  • 9 months later...
  • 2 weeks later...
  • Honorable Member
On 11/30/2018 at 11:14 AM, ReFresh said:

@wezt How can I call this function in char_item.cpp? I want to get an error message when I click on shop bag. And how to make it for when NPC is near too?

Thanks for answer!

Sincerely,

ReFresh

This is the hidden content, please

syntax CheckValidPos(ch, type, distance)

  • Metin2 Dev 4
  • Good 2

 

Link to comment
Share on other sites

  • Gold
3 hours ago, Mali61 said:

this not tested

syntax CheckValidPos(ch, type, distance)

First thing:

I'm not sure if you did what I though. I meant extend already existing function with when some NPC not depend on which npc is it, is too close to you you will get an error message with return value. (You can't make a private shop when some NPC is near to you.)  

Second thing:

Now you will get an error message if you're too close to another private shop after click on OK button (to create shop). I want to get all these error messages when player click on the shop bag (just before private shop window is opened).

Thanks for your answer but I got this error with your code:

Spoiler

char.h: In member function 'void CHARACTER::CheckValidPos::operator()(CEntity*)':
char.h:1371: error: 'type' was not declared in this scope
char.h:1372: error: ISO C++ forbids declaration of 'i' with no type
char.h:1378: error: a function-definition is not allowed here before '{' token
char.h:1379: error: a function-definition is not allowed here before ':' token
char.h:1383: error: expected primary-expression before '}' token
char.h:1383: error: expected `;' before '}' token
char.h:1383: error: expected primary-expression before '}' token
char.h:1383: error: expected `)' before '}' token
char.h:1383: error: expected primary-expression before '}' token
char.h:1383: error: expected `;' before '}' token
char.h:1390: error: 'DISTANCE_APPROX' was not declared in this scope
Makefile:130: recipe for target 'OBJDIR/BattleArena.o' failed

 

I'll be always helpful! 👊 

Link to comment
Share on other sites

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.