Register for your free account! | Forgot your password?

You last visited: Today at 03:38

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++] Check position for shops

Discussion on [C++] Check position for shops within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old   #1
 
wezt's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 8
Received Thanks: 13
[C++] Check position for shops

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:
Code:
		void			CloseMyShop();

	protected:

		LPSHOP			m_pkShop;
		LPSHOP			m_pkMyShop;
		std::string		m_stShopSign;
		LPCHARACTER		m_pkChrShopOwner;
Add few new lines:
Code:
		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:
Code:
	m_pkMyShop		= NULL;
Add below:
Code:
	m_bShopValidPos = true;
Then search for 'void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)'

Add above new function:
Code:
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:
Code:
	if (bItemCount == 0)
		return;
Add below:
Code:
	//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.:
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.
wezt is offline  
Thanks
2 Users
Old 11/08/2016, 20:24   #2
 
_xmr's Avatar
 
elite*gold: 0
Join Date: Nov 2016
Posts: 1
Received Thanks: 1
Stop using nested conditionals
Use that instead:

Code:
if (!sectree)
    return;
Also, why do you declare sectree as NULL?

Code:
LPSECTREE sectree = GetSectree();
And you don't need to define bShopValidPos in the Initialize method
Just define it in the declaration
_xmr is offline  
Thanks
1 User
Old 11/09/2016, 12:04   #3
 
wezt's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 8
Received Thanks: 13
Hey, thanks for your reply.

Quote:
Originally Posted by _xmr View Post
Stop using nested conditionals
Use that instead:

Code:
if (!sectree)
    return;
I don't see any problems with it, there a lot of such conditionals in whole source (don't sure if it's right or not, but it works), examples:


Already applied this:
Code:
LPSECTREE sectree = GetSectree();
And I've added m_bShopValidPos in the Initialize method because as far I know each variable should be initialized.

Regards.
wezt is offline  
Old 11/12/2016, 03:34   #4
 
elite*gold: 0
The Black Market: 105/0/0
Join Date: May 2016
Posts: 8,679
Received Thanks: 1,638
I really like this function, thx for the rls.
悪地城 is offline  
Old 11/19/2016, 12:54   #5
 
elite*gold: 0
Join Date: Nov 2016
Posts: 23
Received Thanks: 7
Thank you for posting
AcronicDesign is offline  
Reply

Tags
c++, shop


Similar Threads Similar Threads
Bewertungsportal für MMORPG-Shops | MMO-Shop-Check.de
08/11/2012 - World of Warcraft Trading - 3 Replies
Ob World of Warcraft, Star Wars, RIFT, Star Trek Online, Star Wars: TOR, Diablo 3 oder ein anderes MMORPG - immer mehr Jugendliche und junggebliebene spielen in ihrer Freizeit Spiele über und im Internet. Problem: Den meisten Spielern fehlt es an der nötigen Zeit stundenlang Gold für World of Warcraft oder Diablo 3,Platin für RIFT, Credits für Star Trek Online sowie Star Wars The Old Republic zu sammeln. Abhilfe: Schon gegen den kleinen Euro bekommt man in den MMORPG-Shops jede...
MMO-Shop-Check.de - Bewertungsportal für MMORPG-Shops
08/10/2012 - Rift Trading - 0 Replies
Ob World of Warcraft, Star Wars, RIFT, Star Trek Online, Star Wars: TOR, Diablo 3 oder ein anderes MMORPG - immer mehr Jugendliche und junggebliebene spielen in ihrer Freizeit Spiele über und im Internet. Problem: Den meisten Spielern fehlt es an der nötigen Zeit stundenlang Gold für World of Warcraft oder Diablo 3,Platin für RIFT, Credits für Star Trek Online sowie Star Wars The Old Republic zu sammeln. Abhilfe: Schon gegen den kleinen Euro bekommt man in den MMORPG-Shops jede...



All times are GMT +1. The time now is 03:39.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.