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;
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;
In 'void CHARACTER::Initialize()' find:
Code:
m_pkMyShop = NULL;
Code:
m_bShopValidPos = true;
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);
}
}
}
};
Code:
if (bItemCount == 0) return;
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
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.







