MAME Coin Control

Post gaming related scripts
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

MAME Coin Control

31 Dec 2016, 00:36

This program will limit the number of coins available in MAME. By default, it uses the right-thumbstick click of an X-Box controller (Joy10) on up to four controllers. It will insert a specified number of coins and then progressively add a new coin after an interval (five minutes by default) has passed.

MAME must be compiled to force Direct Input and the coin keys are set to the program defaults (5-8).

Just run the program with MAME to start it and run it again with the parameter q in order to close. The generated INI file can be used to set the number of starting coins and the interval between the addition of new coins.

The compiled program and source can be downloaded here: http://www.chinagreenelvis.com/gaming/tools/coincontrol

Code: Select all

; MAME Coin Control
; by chinagreenelvis
; Version 0.01
 
#NoEnv
#SingleInstance force
#Persistent
SetWorkingDir %A_ScriptDir%
 
AppName=MAMECC

IfNotExist, %AppName%.ini
{
	IniWrite, 0, %AppName%.ini, Settings, HideIcon
	IniWrite, 300000, %AppName%.ini, Settings, CoinTime
	IniWrite, 4, %AppName%.ini, Settings, StartingCoins
	IniWrite, 0, %AppName%.ini, Program, Running
}

IniRead, HideIcon, %AppName%.ini, Settings, HideIcon
IniRead, CoinTime, %AppName%.ini, Settings, CoinTime
IniRead, StartingCoins, %AppName%.ini, Settings, StartingCoins
IniRead, Running, %AppName%.ini, Program, Running

If (HideIcon)
{
	Menu, Tray, NoIcon
}
Else
{
	Menu, Tray, Icon
}

If (Running)
{
	IniWrite, 0, %AppName%.ini, Program, Running
	ExitApp
}
Else
{
	IniWrite, 1, %AppName%.ini, Program, Running
}

P1 = %1%
IfEqual, P1, q
{
	ExitApp
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODE

SetKeyDelay 50

Joy1Pressed := 0
Joy2Pressed := 0
Joy3Pressed := 0
Joy4Pressed := 0

#IfWinActive ahk_class MAME

~1joy10::
If (!Joy1Pressed)
{
	Joy1Pressed:= 1
	KeyWait 1joy10
	Loop, %StartingCoins%
	{
		Send {5 down}
		Send {5 up}
		Sleep, 50
	}
	SetTimer, Timer1, %CoinTime%
	Return
}
Else
{
	Return
}
Return

Timer1:
	IfWinActive ahk_class MAME
	{
		Send {5 down}
		Send {5 up}
	}
Return

~2joy10::
If (!Joy2Pressed)
{
	Joy2Pressed:= 1
	KeyWait 1joy10
	Loop, %StartingCoins%
	{
		Send {6 down}
		Send {6 up}
		Sleep, 50
	}
	SetTimer, Timer2, %CoinTime%
	Return
}
Else
{
	Return
}
Return

Timer2:
	IfWinActive ahk_class MAME
	{
		Send {6 down}
		Send {6 up}
	}
Return

~3joy10::
If (!Joy3Pressed)
{
	Joy3Pressed:= 1
	KeyWait 1joy10
	Loop, %StartingCoins%
	{
		Send {7 down}
		Send {7 up}
		Sleep, 50
	}
	SetTimer, Timer3, %CoinTime%
	Return
}
Else
{
	Return
}
Return

Timer3:
	IfWinActive ahk_class MAME
	{
		Send {7 down}
		Send {7 up}
	}
Return

~4joy10::
If (!Joy4Pressed)
{
	Joy4Pressed:= 1
	KeyWait 1joy10
	Loop, %StartingCoins%
	{
		Send {8 down}
		Send {8 up}
		Sleep, 50
	}
	SetTimer, Timer4, %CoinTime%
	Return
}
Else
{
	Return
}
Return

Timer4:
	IfWinActive ahk_class MAME
	{
		Send {8 down}
		Send {8 up}
	}
Return

#IfWinActive
Last edited by chinagreenelvis on 05 Sep 2021, 14:09, edited 3 times in total.
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Re: MAME Coin Control

10 Jan 2017, 15:09

Updated to allow toggle via F1 hotkey while MAME is active, simplified code using a function.

Code: Select all

; MAME Coin Control
; by chinagreenelvis
; Version 0.03
 
#NoEnv
#SingleInstance force
#Persistent
SetWorkingDir %A_ScriptDir%
 
AppName=MAMECC

IfNotExist, %AppName%.ini
{
	IniWrite, 0, %AppName%.ini, Settings, HideIcon
	IniWrite, 1, %AppName%.ini, Coins, Enabled
	IniWrite, 300000, %AppName%.ini, Coins, CoinTime
	IniWrite, 4, %AppName%.ini, Coins, StartingCoins
}

IniRead, HideIcon, %AppName%.ini, Settings, HideIcon

Global Enabled
Global CoinTime
Global StartingCoins

IniRead, Enabled, %AppName%.ini, Coins, Enabled
IniRead, CoinTime, %AppName%.ini, Coins, CoinTime
IniRead, StartingCoins, %AppName%.ini, Coins, StartingCoins

If (HideIcon)
{
	Menu, Tray, NoIcon
}
Else
{
	Menu, Tray, Icon
}

P1 = %1%
IfEqual, P1, q
{
	ExitApp
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODE

SetKeyDelay 50

Global Joy1Pressed
Global Joy2Pressed
Global Joy3Pressed
Global Joy4Pressed

JoyPress(Num := 0, Num2 := 0)
{
	IfWinActive, ahk_class MAME
	{
		If (Enabled)
		{
			;MsgBox, WORKING
			If (!Joy%Num%Pressed)
			{
				Joy%Num%Pressed:= 1
				KeyWait %Num%joy10
				Loop, %StartingCoins%
				{
					Send {%Num2% down}
					Send {%Num2% up}
					Sleep, 50
				}
				SetTimer, Timer%Num%, %CoinTime%
				Return
			}
			Else
			{
				Return
			}
		}
		Else
		{
			Send {%Num2% down}
			Send {%Num2% up}
		}
	}
}

~F1::

	If (Enabled)
	{
		Enabled := 0
		IniWrite, 0, %AppName%.ini, Coins, Enabled
		SetTimer, Timer1, Delete
		SetTimer, Timer2, Delete
		SetTimer, Timer3, Delete
		SetTimer, Timer4, Delete
	}
	Else
	{
		Enabled := 1
		IniWrite, 1, %AppName%.ini, Coins, Enabled
		Joy1Pressed := 0
		Joy2Pressed := 0
		Joy3Pressed := 0
		Joy4Pressed := 0
	}

Return

~1joy10::
	JoyPress(1, 5)
Return

~2joy10::
	JoyPress(2, 6)
Return

~3joy10::
	JoyPress(3, 7)
Return

~4joy10::
	JoyPress(4, 8)
Return


Timer1:
	IfWinActive, ahk_class MAME
	{
		Send {5 down}
		Send {5 up}
	}
Return

Timer2:
	IfWinActive, ahk_class MAME
	{
		Send {6 down}
		Send {6 up}
	}
Return

Timer3:
	IfWinActive, ahk_class MAME
	{
		Send {7 down}
		Send {7 up}
	}
Return

Timer4:
	IfWinActive, ahk_class MAME
	{
		Send {8 down}
		Send {8 up}
	}
Return

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 31 guests