Advertisement
Guest User

Warp Gate lib

a guest
Jan 30th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. warp = {
  2.     storage_ini = 60000,
  3.     gates = {}
  4. }
  5.  
  6. function warp:new(name, pos, mana, level, id, storage)
  7.     if self:getWarpById(id) then
  8.         return self:getWarpById(id)
  9.     end
  10.    
  11.     local object = {id = id or #self.gates + 1, name = name, pos = pos, mana = mana, level = level}
  12.     object.storage = storage or self.storage_ini + object.id
  13.    
  14.     setmetatable(object, {__index = self})
  15.  
  16.     self.gates[object.id] = {}
  17.     setmetatable(self.gates[object.id], {__index = object})
  18.    
  19.     return object
  20. end
  21.  
  22. function warp:getWarpById(id)
  23.     return self.gates[id]
  24. end
  25.  
  26. function warp:getGates()
  27.     return self.gates
  28. end
  29.  
  30. local looks = {[0] = 1, [1] = 2, [2] = 3, [3] = 0}
  31.  
  32. local function girar(uid, atual, warp, sx)
  33.     if isCreature(uid) then
  34.         if sx == 1 and atual == 10 then
  35.             doSendMagicEffect(getThingPos(uid), 2)
  36.             doTeleportThing(uid, warp.pos)
  37.             doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You have been warped to ".. warp.name .. ".")
  38.             doSendMagicEffect(warp.pos, 10)
  39.         end
  40.        
  41.         doCreatureSetLookDirection(uid, looks[getCreatureLookDirection(uid)])
  42.        
  43.         if atual ~= 10 then
  44.             if sx == 1 then
  45.                 addEvent(girar, 1200 - atual *  200, uid, atual + 1, warp, sx)
  46.             else               
  47.                 addEvent(girar, atual * 50 , uid, atual + 1, warp, sx)                         
  48.             end
  49.         elseif sx == 1 then
  50.             addEvent(girar, 1200 - atual * 200, uid, 1, warp, 2)
  51.         else
  52.             mayNotMove(uid, false)
  53.         end
  54.     end
  55. end
  56.  
  57. function warp:Warp(uid)
  58.     local p = getThingPos(uid)
  59.     if getPlayerLevel(uid) < self.level then
  60.         return doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to open ".. self.name .. "'s gate at this level.")
  61.     elseif getCreatureMana(uid) < self.mana then
  62.         return doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "Your magic power is not enough to open ".. self.name .. "'s gate.")  
  63.     elseif p.x == self.pos.x and p.y == self.pos.y and p.z == self.pos.z then
  64.         return doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "You already are on ".. self.name .. ".")     
  65.     end
  66.    
  67.     doCreatureAddMana(uid, -self.mana)
  68.     mayNotMove(uid, true)
  69.     doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, "The magic portal is absorbing your body...")
  70.     girar(uid, 1, self, 1) 
  71.     return true
  72. end
  73.  
  74. warp:new("Asgard", {x = 857, y = 964, z = 7}, 1200, 15)
  75. warp:new("Alidria", {x = 881, y = 1030, z = 7}, 20, 150)
  76. warp:new("Badien", {x = 873, y = 977, z = 7}, 70, 170)
  77. warp:new("Kahften", {x = 833, y = 958, z = 7}, 0, 0)
  78. warp:new("Rasgon", {x = 861, y = 980, z = 7}, 50, 15)
  79. warp:new("Tamriel", {x = 866, y = 964, z = 6}, 9500, 6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement