Advertisement
Foereaper

Peacekeeper test

Aug 18th, 2014
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local Peacekeeper_Entry = x -- Set peacekeeper entry ID here
  2.  
  3. local SafeArea = { -- Change area coordinates here, same as C++ script.
  4.     {4513.935, -4256.359},
  5.     {4510.568, -4236.598},
  6.     {4490.970, -4249.030},
  7.     {4489.567, -4194.844},
  8.     {4513.935, -4256.359}
  9. }
  10.  
  11. local function isLeft(pOne, pTwo, pThree)
  12.     local point = ((pTwo[1] - pOne[1]) * (pThree[2] - pOne[2]) - (pThree[1] - pOne[1]) * (pTwo[2] - pOne[2]))
  13.     return point;
  14. end
  15.  
  16. local function isInArea(point)
  17.     local count = 0;
  18.    
  19.     for i = 1, #SafeArea-1 do
  20.         if (SafeArea[i][2] <= point[2]) then
  21.             if (SafeArea[i+1][2] > point[2]) then
  22.                 if (isLeft(SafeArea[i], SafeArea[i+1], point) > 0) then
  23.                     count = count + 1;
  24.                 end
  25.             end
  26.         else
  27.             if (SafeArea[i+1][2] <= point[2]) then
  28.                 if (isLeft(SafeArea[i], SafeArea[i+1], point) < 0) then
  29.                     count = count - 1;
  30.                 end
  31.             end
  32.         end
  33.     end
  34.    
  35.     return count ~= 0;
  36. end
  37.  
  38. local function Peacekeeper_OnSpawn(event, creature)
  39.     creature:RegisterEvent(Peacekeeper_OnCheckArea, 1000, 0)
  40. end
  41.  
  42. local function Peacekeeper_OnCheckArea(creature)
  43.     for k, player in pairs(GetPlayersInMap(creature:GetMapId())) do
  44.         if(player) then
  45.             if (player:GetAreaId() == creature:GetAreaId())
  46.                 local point = {player:GetX(), player:GetY())
  47.                 if(isInArea(point)) then
  48.                     player:SetPvP(false)
  49.                 else
  50.                     player:SetPvP(true)
  51.                 end
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. RegisterCreatureEvent(Peacekeeper_Entry, 23, Peacekeeper_OnSpawn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement