Lua botting is a big topic.
I'd like to give an overview.
How hard it's going to be to make a bot depends on how complicated the things are you want to do. So my first piece of advice would be to imagine exactly
what you want from this bot.
Since you didn't really specify that, I'm just going to start from the easiest one.
So what is the easiest Lua bot? A bot that displays a value on the screen? Probably not. We usually associate a Lua bot with something that changes or creates
input.
So to start off, you'd probably want to create a script that just holds a button (the Hello World! kind of program, if you will), and the best way to do that is, as you suggested, to
study some of the other bot scripts.
Of course this is too easy and not really useful in emulators that have an autohold feature.
But now that you know the syntax on how to press buttons programmatically in Lua, you can easily write simple scripts that press a button every second or third frame (maybe while dealing with lag and also save the position with savestates), other input macros, or more complicated bots.
Now, these are currently all bots that work in
realtime by which I mean they don't use savestates to get additional information about future frames (and indeed, you can go
quite far with those), but of course there are bots that create
whole movies! Working input files! This is where we enter the more complicated bots.
Before we go to the bots that create whole movies, we just look at savestate usage. Maybe you just want to brute force some RNG value.
You just load a savestate, try the next set of input combinations,
advance a bunch of frames, check if the value fits, if it does then you stop, if it doesn't start from the beginning.
The reason I want to emphasize the frame advances is because that is exactly the point where it differs from the previous bots. It became
nonlinear. You
stopped calling the script each frame to display something or calculate the current inputs and you
started advancing multiple frames
just to check what happened.
This is where the bots make movies on their own, where they think by themselves, where complicated bots become complicated.
If you want to make a Lua bot that simulates your TASing (trying to find the fastest movie), you need to have a lot of ideas on how to solve the problems of
- where the bot makes the savestates
- how to give the inputs a score (for example a simple platformer would have a higher score if you are closer to the goal)
- how to make the bot remember the best inputs
- how to make the bot stop testing additional input (you don't want to test the same inputs, and you also don't want to brute force
everything)
Basically it's not too easy.
tl;dr: