Page 1 of 1

Add LUA functions for spell/ability success

PostPosted: Thursday, 7th January 2021, 07:13
by snow
I'm not talking spell casting success (already exists), I'm talking about the chance of beating enemy MR with hexes, successfully pacifying with Ely, etc.

This would allow custom auto fight scripts that do things like casting Ensorcelled Hibernation while tabbing as a SpEn.

It's desperately needed in the subset of the community that has more fun with trying to write scripts for the game than anything else.

Right now, automation basically limited to melee and conjurations, and this simple change would open up so many possibilities.

Re: Add LUA functions for spell/ability success

PostPosted: Thursday, 7th January 2021, 14:50
by Implojin
It looks like a clua exposure for this was already added to mainline (at least, for spells, and maybe also evoked items that have matching spell names) in a 2019 PR by mgdelmonte:

https://github.com/crawl/crawl/commit/3 ... e1f15b986f

So, you *should* already be able to use `m:defeat_wl("spell_name", evoked)` in a similar way to checking for `m:attitude()` or `m:is_firewood()`. [Disclaimer: I haven't tested this, I'm just running grep on the source.]

Please see l-moninf.cc for details.

However, my brief reading of `moninf_get_defeat_wl` suggests that it might(?) only work with actual spells (and not player abilities?) -- (There's a comparison in `spell_by_name` that checks against NUM_SPELLS, so `moninf_get_defeat_wl` might need some minor changes to work with non-spells? I don't feel like testing this and I'm not going down this rabbit hole right now, good luck~)

tl;dr: If there's something broken with this function in actual use, I'm sure improvements would be welcomed by the devteam as a PR.

Re: Add LUA functions for spell/ability success

PostPosted: Thursday, 7th January 2021, 15:42
by Implojin
Oh, and in response to the inevitable "Wait a minute, monster:defeat_wl() doesn't exist on the dcss.io page":

There was some kind of version incompatibility with LDoc that nobody's fixed yet which prevented updating that dcss.io page, so clua hooks newer than 2018 or so aren't being displayed there. In addition to mgdelmonte's stuff, gammafunk's acquirement hook and my you.noise_perception() bind are also missing from that site. (++who knows what else)

Re: Add LUA functions for spell/ability success

PostPosted: Thursday, 7th January 2021, 21:47
by snow
Implojin, thanks! I didn't know the newer stuff wasn't shown there! That's game changing for me. I can't thank you enough!

Re: Add LUA functions for spell/ability success

PostPosted: Friday, 8th January 2021, 09:58
by ebering
I went and looked into the ldoc issue again and it turns out it was not any kind of versioning incompatibility.

ldoc is just very brittle and will crash with useless error messages when certain things are missing. As of latest trunk (0.27-a0-62-g2af701fde4) and 0.26-b1-60 if you run `make api` it will generate the latest Lua API documentation. I've let advil know so hopefully doc.dcss.io will be updated soon.

PRs to improve the Lua API are always welcome, and also if you feel like sharing code and showing off what you can do with it that's super cool too!

Re: Add LUA functions for spell/ability success

PostPosted: Friday, 8th January 2021, 10:37
by snow
ebering wrote:I went and looked into the ldoc issue again and it turns out it was not any kind of versioning incompatibility.

ldoc is just very brittle and will crash with useless error messages when certain things are missing. As of latest trunk (0.27-a0-62-g2af701fde4) and 0.26-b1-60 if you run `make api` it will generate the latest Lua API documentation. I've let advil know so hopefully doc.dcss.io will be updated soon.

PRs to improve the Lua API are always welcome, and also if you feel like sharing code and showing off what you can do with it that's super cool too!


Ebering, one more small suggestion: can you add a reference to doc.dcss.io in the LUA section of the options guide? Like, "to find what you can do with LUA, look at these docs" or something? It's very minor but I'm guessing this might be an entry point for a few players who are in the process of learning to code (what better way than script a few things in your favorite game?), and they might not know that docs exist for these sorts of things.

Re: Add LUA functions for spell/ability success

PostPosted: Sunday, 10th January 2021, 07:03
by ebering
doc.dcss.io has been updated, enjoy!

And thanks for the suggestion, I'll add something to that effect. Happy hacking.