Jump to content
LaunchBox Community Forums

Coin limiter for Arcade games


martijnsx

Recommended Posts

Hi to all Retro Gamers,

Since a couple of years i have been looking for some script/program in which you can limit the amount of coins you can spend in MAME. Games are no challenge if you have unlimited coins.

I have not found a solution so i began trying to write my own AHK script. And that is not as easy as i thought it would be. 

I hope we can all contribute to making a script that can do this (or hint to a program that does this already).

What i want is very simple. Suppose your coin key is the Q key. If Q is pressed for example 5 times AHK must disable that key.

The script must be active only when MAME is running. For this last requirement we have 2 options. 1. start the script when MAME is started / kill the script when MAME is closed. 2. write a script that checks if MAME is running or not. Starting and killing a script may be possible from within Launchbox (with launching/closing emulator). Killing a script might be also possible if we define the exit emulator key in the script. 

There is one more requirement. There may be more coin keys. If you have a 2 or 4 player system then there are 2 or 4 coin keys. I am not sure but i think arcade games have coins adressed differently. You have cabinets that add coins to a global counter and cabinets that have coins dedicated for player 1, 2, 3, and 4. In the first version it does not matter where you input a coin, in the last it does. I think most cabinets have a global counter (all coins add up and you can start all players). TMNT however does have dedicated coin inputs for 4 players (example).  

So who will join me in making this AHK script work? 

Step 1. Find AHK code that will block the input of a key if it is pressed more than X times

Step 2. Make it work only when MAME is active

Step 3. Make it work with multiple coin keys. 

Who has the solution or part of the solution and wants to share the first line of code? Let's do this together!

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

"Q" seems like an odd key assigned to inserting a coin. But who am I to knock it?

MAME's default coin inputs for players one thru four are keys 5, 6, 7 and 8, respectively.

image.png.9d11eaaca6b573a385df5b617d458616.png

Here's coin 1 and 2 (per MAME keyboard assignments) to get you started.  Study it carefully and YOU can add coin 3 & 4 (or change it back to "Q" and whatever ;)).

global coin1 := 0
global coin2 := 0

; Player one coin input = "5"
5::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   5::5
   Sleep 750
}

; Player 2 coin input = "6"
6::
{
   if (coin2 = 5)
      Return

   coin2++
   6::6
   Sleep 750
}

Copy this into the Running [AutoHotkey] Script section of your MAME emulator and limit those little hoodlum's allowance (at least until they learn they can exit, then restart the game with 5 more quarters. lol).

Link to comment
Share on other sites

31 minutes ago, martijnsx said:

why do we need the sleep 750?

Because I was too lazy to try to remember how to set the delay repeat-click thingy. (still am. lol) 

This way if you press and hold "coin", you have to wait 750ms before it detects another press/click. Which is usually long enough if you press and release the button.  But if you presssssss and then release, the script may detect it as more than one press. At this point, MAME probably only gives you the one coin while the script counted 2 or 3.

It's not the "proper" way to do it. But it does work. As cheesy as it may be. ;) 

 

And ya, Coin1++  looks a lot cooler than  Coin1 = Coin1 + 1

 

Glad it's working!!! (because I didn't really test it. lol)

Link to comment
Share on other sites

  • 1 year later...
On 1/15/2022 at 3:01 PM, JoeViking245 said:

"Q" seems like an odd key assigned to inserting a coin. But who am I to knock it?

MAME's default coin inputs for players one thru four are keys 5, 6, 7 and 8, respectively.

image.png.9d11eaaca6b573a385df5b617d458616.png

Here's coin 1 and 2 (per MAME keyboard assignments) to get you started.  Study it carefully and YOU can add coin 3 & 4 (or change it back to "Q" and whatever ;)).

global coin1 := 0
global coin2 := 0

; Player one coin input = "5"
5::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   5::5
   Sleep 750
}

; Player 2 coin input = "6"
6::
{
   if (coin2 = 5)
      Return

   coin2++
   6::6
   Sleep 750
}

Copy this into the Running [AutoHotkey] Script section of your MAME emulator and limit those little hoodlum's allowance (at least until they learn they can exit, then restart the game with 5 more quarters. lol).

JoeViking245, how configure the joystick's "select" button for coin?

Link to comment
Share on other sites

7 hours ago, lfan said:

JoeViking245, how configure the joystick's "select" button for coin?

When assigning the inputs in MAME, you should be able to just highlight Coin 1, press enter (it'll wait for your 'input') then press the button on the controller to select it.

Link to comment
Share on other sites

38 minutes ago, JoeViking245 said:

When assigning the inputs in MAME, you should be able to just highlight Coin 1, press enter (it'll wait for your 'input') then press the button on the controller to select it.

Joy 1 SELECT on MAME screen. JOYCODE_1_SELECT in MAME file.

In the code, I tried to replace the number 5 to JOYCODE_1_SELECT but it didn't work. It seems that the code only accepts numbers.

Link to comment
Share on other sites

9 minutes ago, lfan said:

Joy 1 SELECT on MAME screen. JOYCODE_1_SELECT in MAME file.

In the code, I tried to replace the number 5 to JOYCODE_1_SELECT but it didn't work. It seems that the code only accepts numbers.

On PC the joystick Select button is recognized as 8.

I thought you were just wanting to configure it MAME.  JOYCODE_1_SELECT is MAME lingo. 

Did it work to replace the number with 8?  Though I doubt it's a literal "8".  May try 1Joy8   Which is player-1 joystick, button 8.

1Joy8::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   1Joy8::1Joy8
   Sleep 750
}

 

Link to comment
Share on other sites

5 minutes ago, JoeViking245 said:

I thought you were just wanting to configure it MAME.  JOYCODE_1_SELECT is MAME lingo. 

Did it work to replace the number with 8?  Though I doubt it's a literal "8".  May try 1Joy8   Which is player-1 joystick, button 8.

1Joy8::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   1Joy8::1Joy8
   Sleep 750
}

 

Error at line 10.

Line Text: 1Joy8
Error: This line does not contain a recognized action.

The program will exit.

Link to comment
Share on other sites

34 minutes ago, lfan said:

Error at line 10.

Line Text: 1Joy8
Error: This line does not contain a recognized action.

The program will exit.

Ah ya. You can't assign a joy output.  You can only read its input.

In MAME, revert your Coin 1 to Kbd 5.  Then this might work.

1Joy8::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   1Joy8::5
   Sleep 750
}

 

Link to comment
Share on other sites

13 minutes ago, JoeViking245 said:

Ah ya. You can't assign a joy output.  You can only read its input.

In MAME, revert your Coin 1 to Kbd 5.  Then this might work.

1Joy8::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   1Joy8::5
   Sleep 750
}

 

There is no error, but the script does not limit to 5 coins... 😩

Link to comment
Share on other sites

This works for me, which is exact same syntax. I just don't have dinput controllers to test with. I don't see why it wouldn't work with a controller button?

5::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   5::5
   Sleep 750
}

 

Link to comment
Share on other sites

8 minutes ago, skizzosjt said:

This works for me, which is exact same syntax. I just don't have dinput controllers to test with. I don't see why it wouldn't work with a controller button?

5::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   5::5
   Sleep 750
}

 

For keybord it works perfectly. The mystery is with joystick.

Link to comment
Share on other sites

27 minutes ago, lfan said:

For keybord it works perfectly. The mystery is with joystick.

I [actually just now] tested the script as you have it.  It's pressing 5 twice.  Then when coin1 = 5, is still presses five, but only once.  

Instead of messing with the joy buttons, just have it do what it is we want it to do.

SetKeyDelay, 125, 50 
1joy8::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   Send, 5
   Sleep 750
}

 

Link to comment
Share on other sites

33 minutes ago, JoeViking245 said:

I [actually just now] tested the script as you have it.  It's pressing 5 twice.  Then when coin1 = 5, is still presses five, but only once.  

Instead of messing with the joy buttons, just have it do what it is we want it to do.

SetKeyDelay, 125, 50 
1joy8::
{
   if (coin1 = 5)        ; Max 5 coins
      Return

   coin1++
   Send, 5
   Sleep 750
}

 

Unfortunately, it still doesn't work. Have you tested with any joystick?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...