GTA AFK Money (Survival job runner, using AutoHotKey)

Update 10/29/2023:

Today's checkin is a version that is finally using FindText() for all images.

It's also one of my first checkins with "PinkyMenu" support (semicolon starts a menu), but there are several issues. I probably won't remove all the title-bar key bindings yet. I also prefer many key bindings to the menu equivalents, eg. control-o to get my oppressor2 from mechanic (with dialer), versus ;get>oppressor2 (;go)
(I was somewhat hoping I could get the vim-like (stateful) menu to "feel" better than complex keybindings.)

Part of the problem can be the goofy feedback issues due to titlebar updates with the keystate every 500ms, which I need to disable during menu activities...

Part of the problem may be that GTA5 "eats" some keystrokes? I can't seem to disable GTA5's keyboard processing; it may be using DirectInput or maybe it's periodically polling physical keyboard state (GetKeyboardState() WinAPI), so my menu keyboard keys should generally/ideally be different than game default bindings.

The menus feel non-responsive and I don't know yet if it's due to slowness of InputHook.Start() or failure of .Stop() to deallocate the previous hook; maybe I'll try building a menu that uses a single inputhook.

TODO:

  1. Call WinSetTitle from a single Status class, update method, maintaining various kinds of state in the object
  2. fix-up the AFK mission logic to reduce screen scanning; there really should only be these states in a simple state-machine, at most:
    1) Not in AFK mission; cancelled
    2) Awaiting SETTINGS
    3) Awaiting INVITE
    4) Awaiting Play button
    5) Awaiting mission text in upper-left (AFKMoney&RP v2)
    6) Awaiting WAVE 20 -- can scan about twice per minute for this, and be specific about the screen area to minimize CPU. Consider wait1, but only if the scanning is infrequent.
    7) Awaiting Replay -- scan often, or use wait1
  3. Fix PinkyMenu timing issues / glitchiness ... not quite sure how, yet. Time InputHook creation and start(), and if it's slow just create one inputhook and use OnChar, then maintain menu state in the onchar callback function.
  4. Integrate FeiYue's v9.2 FindText_v2. Maybe suggest some changes (eg. my change from RButton to NumPadAdd, because I can't get GTA5 to ignore RButton)
  5. Better screen capture functionality, and/or AFK mission setup
  6. Misc cleanup; this seems to be always lowest priority, unfortunately, but the code is a mess in many ways. I'm reminded of how clean "GTA V Online AHK-Macros v1.3.0 by 2called-chaos" looked, and may review that code for some hints-to-self (Mine has been hacked-together out of habit and game addiction, not planned.) Cleanup can include:
    1) Delete most commented code, or archive. Especially failed experiments (eg.trying to hide RButton messages from GTA5)
    2) Move AFKMoney into an optional include file?
    3) Assign all hotkeys with HotKey, instead of inline. Create a separate config file for hotkeys.
    4) Better user documentation (probably delete most of this page...), although the menus are supposed to avoid the need, when I get it working right.
  7. Consider FindText Pic library, and maybe make it shared among all users, for collecting multiple resolution screen captures.

Update 8/16/2023:

Please use the AHK v2 script at https://github.com/tallpeak/AHK/tree/main/GTA/AFKMoney ; I no longer use the v1 script, so I am not updating it to fix timing glitches, etc.

You will need to clip images corresponding to your screen resolution and name them appropriately; I hope to make this setup task easier soon.

Also feel free to check out some recent streams at twitch.tv/sqlexpert to learn about GetKeyState.







Update 1/30/2023:

ImageSearch now looks for 1600x900 images (so set to that resolution for this macro to work)

You will need to screen-shot the images at your preferred resolution, if you want to run in a resoultion other than 1600x900 auto, and fix the macro if you use different filenames.

Update [8/05/2021]:

There have been a few small fixes to undocumented macros in my script. The "fly up,forward,down" macro was sending {Control down}, and leaving it down for 60 seconds. This is "dangerous", because Escape could cause a maximized game window to be minimized. Now I send Numpad5, instead.

Note: I believe this script should work for most users with a 16:9 aspect ratio monitor, or with aspect ratio set to 16:9. And I seem to have one confirmed successful user. If you have problems, feel free to email me at aaron@qomph.com. I'm still reluctant to re-post this script anywhere more public than this, until I've fixed some unfortunate key bindings, and rewrote the idle kick prevention logic.

Motivation: GTA5 online can be fun, or it can get to be a grind. It's a grind if you're primarily trying to make money in the game, for whatever reason, and trying to maximize your income. If you're just starting out and "broke", or you're tired of the grind, you can run AFK (away from keyboard) jobs for truly passive income, using a script. There are ways to do it without a script, such as running a multiplayer "Peter Griffin" survival job with a controller "rubber-banded" in a position that causes your character to walk in circles, but my ports aren't open (ISP modem+router is blocking me; ISP did not provide the password to configure it), and this makes joining (hosting) multiplayer jobs difficult, so I had to use a script that reruns the job automatically by searching for images. I found this on reddit gtaglitches but the original had a few issues, so I tweaked it for weeks until it was about 99% reliable AFK, or about 80% reliable in light use (it misses the Replay when user activity prevents window switching, because I wanted the script to run unobtrusively in the event I'm trying to work on the same PC.

Instructions:

  1. Go to http://www.autohotkey.com and download the latest 1.1.x version of AHK and install on your Windows computer. (Mine says Version 1.1.33.02 in the Help)
  2. Download and unzip this archive. (I put mine inside an AHK folder on the desktop)
    AFKMoney.zip
  3. Run AFKmoney.ahk to start the script
  4. Open GTA5.exe as normal (I use the Steam launcher)
  5. Bookmark this job: AFK Money & RP V2, on Social Club.
  6. Make sure GTA is running in 800x600 Windowed (not borderless). There are instructions in the window title (which is why it's important not to be in borderless mode.)
  7. Press F8 when your character is in GTA Online in freemode (not in a mission) to start the script.
  8. For some additional instructions, and the original script from which mine is derived, see this reddit post. Note that I have removed the pause function, and added F9 to resume (for when the AFK job is still running but you've restarted the autohotkey script, for whatever reason.
    Some glitches in my script: When not truly AFK, this AHK script may seem to get "stuck" at a particular place in the code where it's waiting to start the mission; this code is intended to correct for the occasional player who slips in before the session is closed (since I don't bother to run the game in solo sessions), and is working quite well, though the behavior is sub-optimal when not truly AFK. There's also the fact that F8 doesn't respond when you've already pressed it and it's still running, in an infinite loop; that's normal behavior for a hotkey, though something I would change if I rewrote this to use a SetTimer approach where all hotkeys are asynchronous with the execution of long-running game automation functions.) F9 also works to put the script into a loop that prevents idle kick when in freemode, or to resume mission-looping after manually starting an AFK survival mission. For example, I sometimes would start a bookmarked "Sky Fall Fast AFK test" survival, because that one was close to my Meth, so I could deliver meth when I'm done with the survival job (exiting by pressing escape and enter or selecting Freemode before the script selects Replay.)
  9. There are various macros using obscure key combinations that I'm probably not going to bother to document. Some more useful ones would be ctrl+shift+8 to switch from max resolution to min resolution (presumably 800x600), then start the AFK job as usual. I also provided ctrl+shift+0 to switch back to max resolution. Then there's ctrl+alt+N to go to new session (eg. when making a bunker or MC delivery and you're given vehicles you don't want to bother with.) There can be timing issues, but I *think* I've resolved them all, on my end, but your CPU could be slower and might need an even greater MenuDelay than 1600 milliseconds (which seems ridiculously slow.) I may want to fiddle with SetKeyDelay again, but hate to mess with it now that the script is running so reliably.

    One of the reasons (or excuses) I was slow to document this script is because I believe anyone who runs a script like this should at least *try* to read it first. Be careful with any script in which you see DllCall, for example; dangerous things can be done with such commands (the references to DllCall in my script are in some untested code, for forcing the current session to be a solo public session, by pausing the process for 10 seconds). Also be careful with obscured or binary code, such as C code that has been converted to hexadecimal or base64 strings (common in AHK scripts.) There is no malicious code in the script that I uploaded, but it is up to you to verify that.

    Also, I do not provide a compiled script (.EXE), because I believe it would be foolish for anyone to run an unsigned binary from a stranger posting on a forum or advertising within a game (which I suppose my SPAM function fits the definition of).

    There definitely are issues with trying to perform other activities on the same computer. It's behaving about as well as it can, under the conditions, (WinActivate when the user is idle for at least 10 seconds to perform its activities.), but the most common consequence of trying to work on that same computer is that the end-of-job transition goes to a "real" Survival instead of the AFK one. Resolving this may be possible, but not easy, given that GTA only responds to keystrokes sent to its window when the window is active.

    Sorry if I had users who tried this script and were confused, because the only instructions were in the title bar (this page was nearly blank, other than the link.) Originally, I used a ToolTip for instructions, but placement of the ToolTip was problematic, as it sometimes interfered with mouse operations, like moving a window. And it would jump around as the GTA window was moved.

    Here's an email if you want to make any comments or suggestions, or ask questions. I am still a bit reluctant to post publicly about this script, because I'm on unemployment and not sure how public I want to be about playing this silly game!! Email: aaron@qomph.com . Note that I don't check that email daily, to it might take me a few days to get back to you.


    Update: fixed VolumeUp and down (Ctrl+Alt+NumpadPlus and minus). But they are too slow; may tweak later. I have timing issues to work on... I will probably put this script on GitHub so that users (if any) can provide feedback, and so I can track changes, but again I really need a rewrite to fix the awkwardness of hotkeys and make hotkeys asynchronous with menu(s), either building a Gui menu or creating a "title bar menu".

    Update 2: WinActivate fails if you move GTA5 to another virtual desktop. I might want to fix... ( ref: AHK board topic 70136)


    PS: QOMPH.COM was intended to be a personal healthcare analytics site, but I haven't started building it yet (after two years...) Hopefully soon...

    PPS: I would move the code to my github, but again I'm hesitant to be "too" public about this AutoHotKey scripting activity... maybe it would be relevant to a game-automation SDET (testing) job?



    Some comments on the appeal of open-world gaming, and specifically GTA:O. What's the draw? What leads a player in, and what keeps him in? There are many aspects to the appeal of GTA:O. A visually-impressive, somewhat realistic, immersive world in which the player can run free, explore randomly, experiment with objects, NPCs and players, learn what works and what doesn't, infer rules of the game world and perhaps build a few of their own rules (with Creator), although that aspect is limited in GTA. An environment in which success at a mission or job is easy, but also fraught with mild challenges. Challenges that relate to everyone, regardless of language or ability. Virtually anyone can press keys on a keyboard or controller, and can follow simple visual clues such as colors on a map (except perhaps the color-blind!) Language skills are not needed in this game, nor math skills. There are many challenges that are time-limited, so walking/running/driving/shooting may have to be done with some degree of accuracy to complete the challenge in the limited time, but most jobs permit two or three retries before the mission is considered a failure. Missions and jobs have simple objectives; drive somewhere, kill someone, steal some loot, bring it back. But there are many variants on these themes that have added complexity to the challenges over the years, to where GTA V:Online is a very rich environment with much to learn, much to explore.

    There is also a social element. I find sometimes I'm more interested in chatting or collaborating with other players than in killing or fighting them (ha... I have my destructive moments, and even carelessly killed a friend yesterday...(sorry again Adam!)) Perhaps there's also a negative social element, because people do sometimes randomly "grief" others, some more intentionally and persistently than others. But I certainly see potential for the positive social element, based on my and others' players to want to form friendships, alliances (informally) and help on a job within the game. The environment is too limited, and lacking in truly useful (or intellectual) learning activities, but there are types of learning that occur anyway (though mostly confined to the somewhat arcane game rules and behaviors.)

    Criticisms: The environment is "cartoonish" (my word for it); physics are not real (though there seems to be a significant degree of accuracy to much of the physics). Surely a Phantom Wedge or Ramp Buggy couldn't *really* knock ambulances, trucks and cars 50 feet in the air or more, if these vehicles existed in "real life"! But these cartoonish elements are both amusing and interesting, and I can't claim that a RealPhysics environment would have better appeal, because much of the fun of explorarion in such a game is learning these strange and silly elements of behavior of the environment.

    Many items are mostly unlocks, and otherwise next-to-useless. MOC and TerrorByte are examples; MOC is only useful as an unlock for weapons (or for "Criminal Damage" freemode events; probably very effective if you can find 3 friends to man all 3 turret stations while you drive around!), and TerrorByte is only useful for Oppressor MK2 weapons unlock. Same with Arcade; the absolute worst investment I've ever seen, in the game, other than the unlock for the associated heist, especially if you buy the individual game machines (a few milllion to buy them all, and I make that back at what, $30k a day or less? Will have to play the game non-stop for almost a year to make back that investment!). (But I *do* like the Master Control Terminal; who wouldn't like 9 monitors on a giant desk? Too bad I can't stick it in my MOC or other vehicle I can call at any time!) I think the game should separate unlocks to reduce confusion, like saying "weapons unlock costs $2 million", but I can see that having a game object associated with the unlock might make it feel more real. (Just wait until a game comes out where each unlock requires buying an NFT!!!)

    I have much more to say, but limited time to say it now. Perhaps the only excuse I have for playing this game so much, these last three months, is my fantasizing about creating a better game. I want to model real physics, to some level. For example, I would love to give tools to players to create their own customized race cars and engines, based on 100% real physics! This would be incredible, if modelled down to the molecular and even subatomic and crystallographic levels! Someone will do it someday...

    I'm partly impressed that R* has made $6 billion on a game that is so glitchy and buggy, but also fairly impressed by the creativity and visual appeal of the game, and can see the mass appeal, having played it so much for the last 3 months (too much, though I'm mostly AFK lately.) Having made $190 million or so, it's about time I quit it... There is not much dramatically new to discover in the game, although Cayo would be a learning experience. It's just a bit too long and challenging (in mostly non-intellectual ways, although I suppose there are some mild puzzles to solve), for my taste.