
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
  
  
  
-- Created by: Terry Ingalls aka: Tingalls 7/26/2014
  
  
  
-- Opens door automatically and closes it when player is away from door
  
 local open = {}
  
function doorauto_init(e)
 open[e] = 0
end
  
       
  
function doorauto_main(e)
 if GetPlayerDistance(e) < 150 then
  
  if open[e] == 0 then
  
   -- door is closed
   StartTimer(e);
  
   if g_Entity[e]['animating'] == 0 then
  
    SetAnimation(0);
	SetAnimationSpeed(e,150);
  
    PlayAnimation(e);
  
    open[e] = 1
  
    g_Entity[e]['animating'] = 1;
  
    PlaySound(e,0);
  
   end
  
  else
  
   if open[e] == 1 then
  
    -- door collision off after 1 second
  
    if GetTimer(e)>20 then
  
      CollisionOff(e);
  
    end
  
   end
  
  end
  
 
elseif GetPlayerDistance(e) > 150 then
  
 --door is open
     if open[e] == 1 then
  
      if g_Entity[e]['animating'] == 0 then
  
        SetAnimation(1);
  
        PlayAnimation(e);
  
        PlaySound(e,1);
  
          g_Entity[e]['animating'] = 1;
  
         open[e] = 0;
  
        CollisionOn(e);
  
     end
  
     end
  
    end
  
end
 

