Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. -- CONFIGURAÇÕES --
  2. local doors= {14155, 14154, 14153, 14152}
  3. local door_table = {
  4.     [action_id] = {x=1386, y=736, z=7},
  5.     --etc
  6. }
  7.  
  8. -- FIM CONFIGURAÇÕES --
  9.  
  10. local function areThereCreaturesInArea(top_left, bottom_right)
  11.     for x = top_left.x, bottom_right.x do    
  12.         for y = top_left.y, bottom_right.y do        
  13.             if isCreature(getTopCreature({x=x, y=y, z=top_left.z}).uid) then              
  14.                 return true        
  15.             end    
  16.         end
  17.     end  
  18.    
  19.     return false
  20. end
  21.  
  22. local function open(pos, i)
  23.     if i < #doors then
  24.         current = doors[i]  
  25.         next_ = doors[i+1]
  26.         local door = getTileItemById(pos, current)
  27.        
  28.         if door.uid > 0 then      
  29.             doTransformItem(door.uid, next_)      
  30.             addEvent(open, 200, pos, i+1)  
  31.         end
  32.     end
  33. end
  34.  
  35. local function close_(pos, i)
  36.     local top_left= {x = pos.x - 3, y = pos.y - 2, z = pos.z}
  37.     local bottom_right= {x = pos.x, y = pos.y + 2, z = pos.z}  
  38.  
  39.     if areThereCreaturesInArea(top_left, bottom_right) then  
  40.         return true
  41.     end
  42.    
  43.     if i <= #doors and i > 1 then  
  44.         current = doors[i]  
  45.         next_ = doors[i-1]    
  46.         local door = getTileItemById(pos, current)
  47.        
  48.         if door.uid > 0 then      
  49.             doTransformItem(door.uid, next_)      
  50.             addEvent(close_, 200, pos, i-1)
  51.         end
  52.     end
  53. end
  54.  
  55. function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
  56.     local door_pos = door_table[item.actionid]
  57.    
  58.     if not door_pos then
  59.         print("Error: door not configured. Action id: "..item.actionid)
  60.        
  61.         return true
  62.     end
  63.    
  64.     for i = 1, #doors do      
  65.         local door = getTileItemById(door_pos, doors[i])      
  66.        
  67.         if door.uid > 0 then          
  68.             open(door_pos, i)          
  69.             break      
  70.         end
  71.     end
  72.     return true
  73. end
  74.  
  75. function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
  76.     local door_pos = door_table[item.actionid]
  77.    
  78.     if not door_pos then
  79.         print("Error: door not configured. Action id: "..item.actionid)
  80.        
  81.         return true
  82.     end
  83.  
  84.     close_(door_pos, #doors)  
  85.     return true
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement