martijnsx Posted January 14, 2022 Share Posted January 14, 2022 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! Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 15, 2022 Share Posted January 15, 2022 "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. 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). Quote Link to comment Share on other sites More sharing options...
martijnsx Posted January 16, 2022 Author Share Posted January 16, 2022 (edited) Hi Joe, Thank you very much! Works like a charm! Edited January 16, 2022 by martijnsx Quote Link to comment Share on other sites More sharing options...
martijnsx Posted January 16, 2022 Author Share Posted January 16, 2022 (edited) I think i understand the script. I was not familiar with the operators like ++ but i looked it up on the AHK website. PS, why do we need the sleep 750? Edited January 16, 2022 by martijnsx Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 16, 2022 Share Posted January 16, 2022 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) Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 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. 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? Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 6 Share Posted January 6 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. Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 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. Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 On PC the joystick Select button is recognized as 8. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 6 Share Posted January 6 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 } Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 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. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 6 Share Posted January 6 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 } Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 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... 😩 Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 6 Share Posted January 6 6 minutes ago, lfan said: There is no error, but the script does not limit to 5 coins... 😩 Can you show your script as you have it. Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 1Joy8:: { if (coin1 = 5) ; Max 5 coins Return coin1++ 1Joy8::5 Sleep 750 } Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 The script for keybord works. Quote Link to comment Share on other sites More sharing options...
skizzosjt Posted January 6 Share Posted January 6 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 } Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 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. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted January 6 Share Posted January 6 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 } Quote Link to comment Share on other sites More sharing options...
lfan Posted January 6 Share Posted January 6 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.