
door_pressed = 0

function appliance_init(e)
end
	 
function appliance_main(e)
 PlayerDist = GetPlayerDistance(e)
 if (PlayerDist < 100 ) and g_PlayerHealth > 0 then
  GetEntityPlayerVisibility(e)
  if 1 then
   if g_Entity[e]['activated'] == 0 then
    if g_Entity[e]['haskey'] == -1 then
     SetActivated(e,1)
    
    end
   else
    if g_Entity[e]['activated'] == 1 then
     
     if g_Entity[e]['plrvisible'] == 1 then 
      Prompt("Press E to use")
      if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then  
	   SetAnimation(0)
	   PlayAnimation(e)
	   g_Entity[e]['animating'] = 1
       SetActivated(e,2)
	   ActivateIfUsed(e)
       PlaySound(e,0)
	   StartTimer(e)
	   g_Entity[e]['timer'] = g_Time
	   door_pressed = 1
	  end
	 end
    else
     if g_Entity[e]['activated'] == 2 then
	  --  is open
	  if g_Entity[e]['plrvisible'] == 1 then 
 	   if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then
 	    SetAnimation(1)
	    PlayAnimation(e)
 	    g_Entity[e]['animating'] = 1
        SetActivated(e,1)
        PlaySound(e,1)
        CollisionOn(e)
	    door_pressed = 1
	   end
	  end
	 end
    end
   end
  end
 end
 if g_Entity[e]['activated'] == 2 then
  -- collision off after 1 second
  if GetTimer(e)>1000 then
   CollisionOff(e)
  end
 end
 if g_KeyPressE == 0 then 
  door_pressed = 0
 end
 --PromptLocal ( e, "activated=" .. g_Entity[e]['activated'] .. "PlayerDist=" .. PlayerDist .. " plrvisible=" .. g_Entity[e]['plrvisible'] ..  " haskey=" .. g_Entity[e]['haskey']  )
end
