Advertisement
Guest User

Untitled

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