This code may require editing to work on your game, it's a work in progress.