Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. FlyingMounts = {65} -- Mounts in this table are going to force fly when mounting/dismounting.
  2. PvpRestrictions = "high" -- You can set 3 different types of pvp restrictions
  3. -- None:
  4. ---- Nothing will be done, the players can attack each other anytime while flying.
  5.  
  6. -- Medium:
  7. -- The players can attack each other while flying, but they cant start flying if they already have pz and they will have a huge interval (configurable) to go up and down. The interval is only applied to the people with PZ locked.
  8.  
  9. -- High:
  10. ---- Players can't attack each other while flying at all and they cant start flying as in medium. This could be abused to escape from pks as you can't be attacked by them while flying.
  11.  
  12. ChangeFloorInterval = 2 -- seconds
  13. ChangeFloorIntervalPZ = 10 -- seconds, only in medium restriction.
  14.  
  15. function Position:createFlyFloor()
  16.     local toTile = Tile(self)
  17.     if not toTile or not toTile:getItems() or not toTile:getGround() then
  18.         doAreaCombatHealth(0, 0, self, 0, 0, 0, CONST_ME_NONE)
  19.         Game.createItem(460, 1, self)
  20.     end
  21. end
  22.  
  23. function Tile:hasValidGround()
  24.     local ground = self:getGround()
  25.     local nilitem = self:getItemById(460)
  26.     if ground and not nilitem  then
  27.         return true
  28.     end
  29.  
  30.     return false
  31. end
  32.  
  33. function Player:activateFly()
  34.     self:setStorageValue(16400, 1)
  35.     self:registerEvent("FlyEvent")
  36.     return true
  37. end
  38.  
  39. function Player:deactivateFly()
  40.     local can, floor = self:canDeactivateFly()
  41.     local pos = self:getPosition()
  42.     if can then
  43.         local curtile = Tile(pos)
  44.         local itemfloor = curtile:getItemById(460)
  45.         if itemfloor then
  46.             itemfloor:remove()
  47.         end
  48.         self:setStorageValue(16400, -1)
  49.         self:unregisterEvent("FlyEvent")
  50.         if pos.z ~= floor then
  51.             pos.z = floor
  52.             self:teleportTo(pos)
  53.             pos:sendMagicEffect(CONST_ME_TELEPORT)
  54.         end
  55.     end
  56.  
  57.     return can
  58. end
  59.  
  60. function Player:isFlying()
  61.     return self:getStorageValue(16400) == 1
  62. end
  63.  
  64. function Player:canDeactivateFly()
  65.     local pos = self:getPosition()
  66.     for z = pos.z, 15 do
  67.         local tmp = Tile(pos.x, pos.y, z)
  68.         if tmp and tmp:hasValidGround() then
  69.             if self:canFlyDown(z) then
  70.                 return true, z
  71.             else
  72.                 return false
  73.             end
  74.         end
  75.     end
  76.  
  77.     return false
  78. end
  79.  
  80. function Player:canFlyUp()
  81.     local pos = self:getPosition()
  82.     local tmp = Tile(pos.x, pos.y, pos.z-1)
  83.     if tmp and tmp:hasValidGround() then
  84.         return false
  85.     end
  86.  
  87.     return true
  88. end
  89.  
  90. function Player:canFlyDown(floor)
  91.     local pos = self:getPosition()
  92.     local tmp = Tile(pos)
  93.     if floor and floor == pos.z then
  94.         return true
  95.     end
  96.  
  97.     if tmp:hasValidGround() then
  98.         return false
  99.     end
  100.  
  101.     tmp = Tile(pos.x, pos.y, floor or pos.z+1)
  102.     if tmp and (tmp:getHouse() or tmp:hasFlag(TILESTATE_PROTECTIONZONE) or tmp:hasFlag(TILESTATE_FLOORCHANGE) or tmp:hasFlag(TILESTATE_BLOCKSOLID)) then
  103.         return false
  104.     end
  105.  
  106.     return true
  107. end
  108.  
  109. function Player:flyUp()
  110.     if self:isFlying() then
  111.         if self:canFlyUp() then
  112.             local pos = self:getPosition()
  113.             local tile = Tile(pos)
  114.             local itemfloor = tile:getItemById(460)
  115.             if itemfloor then
  116.                 itemfloor:remove()
  117.             end
  118.  
  119.             pos.z = pos.z-1
  120.             pos:createFlyFloor()
  121.             self:teleportTo(pos)
  122.             pos:sendMagicEffect(CONST_ME_TELEPORT)
  123.  
  124.             return true
  125.         end
  126.  
  127.         return false
  128.     else
  129.         self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not flying.")
  130.     end
  131. end
  132.  
  133. function Player:flyDown()
  134.     if self:isFlying() then
  135.         if self:canFlyDown() then
  136.             local pos = self:getPosition()
  137.             local tile = Tile(pos)
  138.             local itemfloor = tile:getItemById(460)
  139.             if itemfloor then
  140.                 itemfloor:remove()
  141.             end
  142.  
  143.             pos.z = pos.z+1
  144.             pos:createFlyFloor()
  145.             self:teleportTo(pos)
  146.             pos:sendMagicEffect(CONST_ME_TELEPORT)
  147.             return true
  148.         end
  149.  
  150.         return false
  151.     else
  152.         self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not flying.")
  153.     end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement