The NEW Build Your Own Arcade Controls

Main => Software Forum => Topic started by: Stormrider on October 03, 2009, 04:51:30 pm

Title: Coin drop effect for MAME: AutohotKey script with random sounds and delay
Post by: Stormrider on October 03, 2009, 04:51:30 pm
All the files are included in my MaLa layout (folder called coindrop). You can downloaded from here:

http://www.alvarezeninternet.com/malalayout/ (http://www.alvarezeninternet.com/malalayout/)

You can delete the rest of the files if you are only interested in the coin drop effect.

Before we start, let me tell you that you will have to compile MAME for this to work. If you are not willing to do so, forget this chapter.

This feature is an idea by jdpb81, so credits to him. This fellow has developed an AutohotKey script (http://www.autohotkey.com/ (http://www.autohotkey.com/)) to simulate the insertion of a coin when you push the coin/select button in your control panel. When you press this button or the key you have set, the sound of a coin drop is played and then, when the sound has finished or is about to finish, the credit is registered. This delay makes the effect really authentic and attractive. I have completed the script with the ability to play random sounds from several coin drops, just to add some variety and realism.

You can find a folder in my MaLa layout called coindrop. This folder has a set of 8 sound samples I have downloaded and edited. Copy or move this coindrop folder to C:\Windows\. Run coindrop.exe (MaLa root folder) before launching MAME. If necessary, edit the source code according to your settings. It is included in the scripts source folder. Compile it with the tool provided with AutohotKey (convert .ahk to .exe). I'll explain the code:

#NoTrayIcon
SetKeyDelay 50
#IfWinActive ahk_class MAME

~1joy10::  ; this is the button in my control panel for insert coin (go to control panel, gaming devices, to find yours)
Random, n, 1, 8 ; indicates the minimum and maximum number of random sound files
SoundPlay %A_WinDir%\coindrop\coin%n%.wav ; this is where the sound samples are stored
Sleep 750 ; the delay after the sound starts and the credit is registered (all sound samples should be approximately the same length)
KeyWait 1joy10
Send {5 down}
Send {5 up}
return

~2joy10:: ; for the second player
Random, n, 1, 8
SoundPlay %A_WinDir%\coindrop\coin%n%.wav
Sleep 750
KeyWait 2joy10
Send {6 down}
Send {6 up}
return

As you can see in the code, the real key for insert coin is '5' (first player) and '6' (second player), so you have to configure MAME to use that key, not the button in your control panel.

As I said before, this feature needs recompiling MAME with a little change to osd\windows\input.c Find the line #define FORCE_DIRECTINPUT 0 and change it to #define FORCE_DIRECTINPUT 1. That changes raw input to direct input, which is necessary for the script to work in MAME.

Another final issue. If you have your MaLa or any other frontend instead of userinit.exe, as described before, so that it loads before or instead the Windows environment, you will have to make a little change to load the script before the frontend. Open Regedit: hkey_local_machine\software\microsoft\windows nt\currentversion\winlogon -> Userinit There you should have d:\mala\mala.exe (for instance) instead of userinit.exe. Now, you have to change it to: d:\mala\coindrop.exe,d:\mala\mala.exe that is, the path to the script exe and then the frontend exe (separated by a comma). Don't forget to make a Ghost image before doing this kind of modifications.