Guys... you've all ignored Parranoia's way of doing something like this which he used in http://emudevs.com/showthread.php/40...tuary-PvP-Zone

Code:

#include "ScriptPCH.h"
typedef struct {float x, y;} Point;
// This is a list of X, Y coordinates that you want to make your "safe area"
// The first and last points MUST be the same for this to work
static const Point V[] = { {4513.935f, -4256.359f}, {4510.568f, -4236.598f}, {4490.970f, -4249.030f}, {4489.567f, -4194.844f}, {4513.935f, -4256.359f} };
// Set n to the number of elements in V - 1
// Since there are a total of 5 points, n is 4
static const int n = 4;
class npc_peacekeeper : public CreatureScript
{
public:
npc_peacekeeper() : CreatureScript("npc_peacekeeper") {}
CreatureAI* GetAI(Creature* c) const
{
return new npc_peacekeeperAI(c);
}
struct npc_peacekeeperAI : public ScriptedAI
{
npc_peacekeeperAI(Creature* c) : ScriptedAI(c) {}
int isLeft(Point P0, Point P1, Point P2)
{
return ( (P1.x - P0.x) * (P2.y - P0.y)
- (P2.x - P0.x) * (P1.y - P0.y) );
}
// Checks if a Point is inside the predefined area
bool IsInArea(Point P)
{
int wn = 0;
for (int i=0; i < n; i++)
{
if (V[i].y <= P.y)
{
if (V[i + 1].y > P.y)
if (isLeft(V[i], V[i+1], P) > 0)
++wn;
}
else
{
if (V[i + 1].y <= P.y)
if (isLeft(V[i], V[i+1], P) < 0)
--wn;
}
}
return wn != 0;
}
void Reset()
{
// Only run the check every 1 second rather than every update
// Not sure how intensive this algorithm is, but it's better to be safe
timer = 1000;
}
void UpdateAI(uint32 diff)
{
if (timer <= diff)
{
Map::PlayerList const& Players = me->GetMap()->GetPlayers();
for (Map::PlayerList::const_iterator itr = Players.begin(); itr != Players.end(); ++itr)
{
if (Player* player = itr->GetSource())
{
if (player->GetAreaId() != me->GetAreaId())
continue;
Point p = { player->GetPositionX(), player->GetPositionY() };
if (IsInArea(p))
player->SetPvP(false);//do this to players inside the area
else
player->SetPvP(true);//do this to players outside the area
}
}
timer = 1000;
} else timer -= diff;
}
uint32 timer;
};
};
void AddSC_npc_peacekeeper()
{
new npc_peacekeeper();
}