Peacekeeper NPC


This is a Peacekeeper NPC script, that when the people are in range of the npc, on the certain x, y coordinates, you will be not flagged for pvp. A simple way to make a sanctuary without a patch!



Script:
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[] = { {4519.443359f, 2709.068359f}, {4518.447266f, 2699.789795f}, {4512.137695f, 2689.388184f}, {4512.927734f, 2674.512207f}, {4515.222168f, 2658.663330f}, {4523.524902f, 2641.542480f}, {4536.573730f, 2630.782715f}, {4546.353027f, 2636.786865f}, {4562.053711f, 2651.318359f}, {4570.511719f, 2663.249756f}, {4578.481445f, 2696.588135f}, {4564.876465f, 2707.007324f}, {4542.565918f, 2708.313477f}, {4526.848145f, 2710.782471f}, {4519.443359f, 2709.068359f} }; static const int n = 14; 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++) { [I]if (V.y <= P.y) { if (V[i + 1].y > P.y) [I]if (isLeft(V, V[i+1], P) > 0) ++wn; } else { if (V[i + 1].y <= P.y) [I]if (isLeft(V, V[i+1], P) < 0) --wn; } } return wn != 0; } bool IsOutArea(Point P) { int wn = 0; for (int i=0; i < n; i++) { P.y=+4; [I]if (V.y <= P.y) { if (V[i + 1].y > P.y) [I]if (isLeft(V, V[i+1], P) > 0) ++wn; } else { if (V[i + 1].y <= P.y) [I]if (isLeft(V, 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)){ if(player->pvpInfo.IsInNoPvPArea != true) player->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_SANCTUARY); player->pvpInfo.IsInNoPvPArea = true; player->CombatStopWithPets(); } } } timer = 1000; } else timer -= diff; } uint32 timer; }; }; void AddSC_npc_peacekeeper() { new npc_peacekeeper(); }





› See More: Peacekeeper NPC