I've been messing with it recently, so I'll try to give the important stuff that I actually know about. I'm going to include stuff that you obviously already know, just for the sake of completeness. I would like to get enough basic info so we can at least create a tiny 'quick start guide' or some such; even if it only has a few things, like ready() and choose_stat_gain() it'll still have been extremely helpful for me when I was trying to figure this stuff out.
Firstly, bind something to CMD_LUA_CONSOLE.. You'll probably want to debug and mess with stuff in the console while the game is running to figure it out faster at times.
A lot of the code you're looking for is in the source folder,
https://github.com/crawl/crawl/tree/mas ... ref/source , and most of the functions are in the files in the format: l_(blah).cc
You'll see at the bottom of a lot of these pages something like 'luaL_openlib' with some functions being pushed through. Some of it is clua, and some is dlua. For example, on
https://github.com/crawl/crawl/blob/mas ... e/l_you.cc find "you_clib", there should be a table definition full of good stuff, and then the table pushed through that function
- Code:
luaL_openlib(ls, "you", you_clib, 0)
And in our rc we can access that you_clib table of functions using 'you.(table key)'. So you.turns() (or maybe you.turns) will give you turn number.
Another method I used to figure out exactly what I had access to was using the console:
- Code:
for x, c in pairs(_G) do
crawl.mpr(x)
end
_G is a table with all your globals, so it'll list lua functions, crawl functions, everything. And use crawl.mpr(type(blah)) to figure out if it's a function or whatever. Luckily, most of the clua functions are in neat little tables (inventory, you, crawl, etc), which you can loop through just like above.
General lua warnings.. Lua arrays are actually tables, I think? And they tend to start at 1, unless you manually started it at 0. So the keys can be anything, just like a table/dict. I guess that's the only thing I can think of atm. I like Lua. :)
-------------------------------------------------------
Some of those functions I feel are worth mentioning:
crawl.mpr() prints to the screen. I suggest aliasing it for quicker access.
crawl.messages([num of messages]) is, as far as I know, the only way to get the chat log info to trigger events on messages from the chat log. For pattern matching, watch that crawl.mpr automatically capitalizes the first letter even if it's actually lowercase, made a bug from that.
crawl.sendkeys(), crawl.process_command(), crawl.process_keys(), crawl.do_commands(), crawl.runmacro() send commands to the game. They are all slightly different, so look through them.
-------------------------------------------------------
Some special functions you can define(Edit: found a couple more):
ready() is actually called by the game, so for actual lua automation I believe this is all you can use. It is called after every action completes. The autoattack code errors (pressing tab with nobody in view) do not trigger a ready(). Luckily you can just copy the whole tab code into your rc and add them there :p.
choose_stat_gain() is called when you level up. You can define it to sendkeys 's', 'i', or 'd', or even just have the function return the letter you want, and it'll pick that stat for you.
c_answer_prompt(prompt) is called when a prompt comes up, return true or false
c_trap_is_safe(trap) Qw has an example
auto_experience() "Calling a user lua function here to let players automatically accept the given skill distribution for a potion of experience.", not sure of the syntax
ch_force_autopickup() looks like it's a way to force an item onto your auto-pickup
-------------------------------------------------------
My 'bot'. It's much smaller and simpler than a real bot like qw, but it has examples of everything above. Most of it is just the copied over autoattack code, slightly modified. (The real autoattack code is here:
https://github.com/crawl/crawl/blob/fca ... ofight.lua )
http://crawl.akrasiac.org/rcfiles/crawl-git/Dracbot.rcAs you can see, all the hard work is done by the auto explore and auto fight code that other people wrote. This really wasn't meant for public consumption, so if you want examples of good (or at least better) code, look at the other bots. :D
-------------------------------------------------------
Edit: I forgot to mention this, which wasn't initially obvious to me, although it might be in the docs.
But you can use functions and conditionals to directly set rc settings:
- Code:
: if you.race() == "Troll" then
autopickup = $%
: end
Another random thing, stolen from qw: string.char(27) is the 'escape' character, I think? It's the only way I could find to use sendkeys to exit out of a shop, probably good for some other menus as well.