pressE = 0 local direction = {} local fps = 60 --try match your game's intended frame rate local timer = 0 local animSpeed = {} local startAY = {} --set how fast the door opens and closes using the animation speed property in the editor function door_with_collision_init(e) SetActivated(e,1) direction[e] = -1 --set to 1 to swing 1 way or -1 to swing the other animSpeed[e] = GetAnimationSpeed(e) startAY[e] = GetEntityAngleY(e) SetActivated(e,5) end function door_with_collision_main(e) --Prompt(animSpeed[e]) local Pdist = GetPlayerDistance(e) if g_Entity[e]['activated'] == 5 then if g_Entity[e]['haskey'] == -1 then SetActivated(e,1) return end if Pdist < 100 then if g_Entity[e]['haskey'] == 1 then PromptLocal(e," The door is locked, unlock the door? (e)") if g_KeyPressE == 1 then if pressE == 0 then PlaySound(e,2) SetActivated(e,1) end pressE = 1 end elseif g_Entity[e]['haskey'] == 0 then PromptLocal(e," The door is locked, find the key to unlock it") end end elseif g_Entity[e]['activated'] == 1 then if Pdist < 100 then PromptLocal(e," Open the door? (e)") if g_KeyPressE == 1 then if pressE == 0 then SetActivated(e,2) PlaySound(e,0) timer = 0 end pressE = 1 end end elseif g_Entity[e]['activated'] == 2 then CollisionOff(e) RotateY(e,((90*fps*GetTimeElapsed())/animSpeed[e])*direction[e]) timer = timer + GetTimeElapsed() CollisionOn(e) if timer >= animSpeed[e] then SetActivated(e,3) end elseif g_Entity[e]['activated'] == 3 then if Pdist < 100 then PromptLocal(e," Close the door? (e)") if g_KeyPressE == 1 then if pressE == 0 then SetActivated(e,4) timer = 0 end pressE = 1 end end elseif g_Entity[e]['activated'] == 4 then CollisionOff(e) RotateY(e,((90*fps*GetTimeElapsed())/animSpeed[e])*direction[e]*-1) timer = timer + GetTimeElapsed() CollisionOn(e) if timer >= animSpeed[e] then PlaySound(e,1) SetActivated(e,1) CollisionOff(e) SetRotation(e,GetEntityAngleX(e),startAY[e],GetEntityAngleZ(e)) ResetRotation(e,GetEntityAngleX(e),startAY[e],GetEntityAngleZ(e)) CollisionOn(e) end end if g_KeyPressE == 0 then pressE = 0 end end