Advertisement
dalvorsn

Untitled

Apr 4th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. --#lib init#
  2. Fly = {}
  3.  
  4. flystorage  = 123456
  5. function Fly:new(cid)
  6.     local bool = getPlayerStorageValue(cid, flystorage)
  7.     if(bool == -1)then bool = false end
  8.     return setmetatable({cid = cid, active = bool}, {__index = self})
  9. end
  10.  
  11. function Fly:isFlying()
  12.     return self.active
  13. end
  14.  
  15. function Fly:activeFly()
  16.     self.active = true
  17.     setPlayerStorageValue(cid, flystorage, true)
  18. end
  19.  
  20. function Fly:flyUp()
  21.     if(isCreature(self.cid))then
  22.         local newpos = getThingPos(self.cid)
  23.         newpos.z = newpos.z + 1
  24.         if not(getTileInfo(newpos))then
  25.             doCreateItem(101,1, newpos)
  26.         end
  27.         doTeleportThing(self.cid, newpos)
  28.     else
  29.         self.active = false
  30.     end
  31. end
  32.  
  33. function Fly:flyDown()
  34.     if(isCreature(self.cid))then
  35.         local newpos = getThingPos(self.cid)
  36.         newpos.z = newpos.z - 1
  37.         if not(getTileInfo(newpos))then
  38.             doCreateItem(101,1, newpos)
  39.         end    
  40.         doTeleportThing(self.cid, newpos)
  41.     else
  42.         self.active = false
  43.     end
  44. end
  45.  
  46. function Fly:deactiveFly()
  47.     self.active = false
  48.     setPlayerStorageValue(cid, flystorage, false)
  49. end
  50. -- #endlib#
  51.  
  52. -- #creature init#
  53. function onDirection(cid, old, current)
  54.     local fly = Fly:new(cid)
  55.     local posold = getPositionByDirection(getThingPos(cid), old, 1)
  56.     local itemold = getTileItemById(posold, 101)
  57.     if(itemold)then
  58.         doRemoveItem(itemold, 1)
  59.     end
  60.     if(fly:isFlying())then
  61.         doCreateItem(101, 1, getPositionByDirection(getThingPos(cid), current, 1))
  62.     end
  63.     return true
  64. end
  65.  
  66. function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
  67.     local itemold = getTileItemById(lastPosition, 101)
  68.     if(itemold)then
  69.         doRemoveItem(itemold, 1)
  70.     end
  71.     if(fly:isFlying())then
  72.         doCreateItem(101, 1, getCreatureLookPosition(cid))
  73.     end
  74.     return true
  75. end
  76. -- #end creature
  77.  
  78. -- #talk example
  79. function onSay(cid, words, param, channel)
  80.     local fly = Fly:new(cid)
  81.     if(param == "ativar")then
  82.         fly:activeFly()
  83.     elseif(param == "desativa")then
  84.         fly:deactiveFly()
  85.     elseif(param == "desce")then
  86.         fly:flyDown()
  87.     elseif(param == "sobe")then
  88.         fly:flyUp()
  89.     else
  90.         doPlayerSendCancel(cid, "Invalid parameteres")
  91.     end
  92.     return true
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement