Artificial intelligence (AI) technology can have a dramatic impact on the quality of video games. AI planning techniques are useful in a wide range of game components, including modules that control the behavior of fully autonomous units. However, planning is computationally expensive, and the CPU and memory resources available to game AI modules at runtime are scarce. Offline planning can be a good strategy to avoid runtime performance bottlenecks. In this work, we apply hierarchical task network (HTN) planning to video games. We describe a system that computes plans offline and then represents them as game scripts. This can be seen as a form of generating game scripts automatically, replacing the traditional approach of composing them by hand. We apply our ideas to the commercial game THE ELDER SCROLLS IV: OBLIVION, with encouraging results. Our system generates scripts automatically at a level of complexity that would require a great human effort to achieve.