Jump to content
×
×
  • Create New...

Check Position for Shops


Recommended Posts

M2 Download Center

Hidden Content

    Give reaction to this post to see the hidden content.
( 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.

  • Love 7
  • Good 1
Link to comment
  • Premium

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

Link to comment
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
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

http://prntscr.com/d4k42o

the codes of the market

mob cod (30002)30003)30004)

 

 

These New Markets Are Blocked

 

system thank you 

 

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

Hidden Content

    Give reaction to this post to see the hidden content.

syntax CheckValidPos(ch, type, distance)

  • Metin2 Dev 1
Link to comment
  • Premium
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

 

Link to comment

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

Announcements

  • -15% Discount in Metin2 Dev Store (01/10/2021 => 31/12/2021) => Code => 15_PCT_OCT_TO_DEC_2021


  • Read our Rules
  • Activity

    1. 3

      Quest Craft

    2. 3

      Quest Craft

    3. 414

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

    4. 11

      Metin2 Patcher with Electron

    5. 17

      I Want Find freebsd 11.4 with remove unnecessary codes

    6. 17

      I Want Find freebsd 11.4 with remove unnecessary codes

    7. 3

      Quest Craft

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