Add LUA functions for spell/ability success


Although the central place for design discussion is ##crawl-dev on freenode, some may find it helpful to discuss requests and suggestions here first.

User avatar

Tomb Titivator

Posts: 857

Joined: Monday, 31st January 2011, 23:19

Post Thursday, 7th January 2021, 07:13

Add LUA functions for spell/ability success

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.

Slime Squisher

Posts: 368

Joined: Thursday, 11th April 2013, 21:07

Post Thursday, 7th January 2021, 14:50

Re: Add LUA functions for spell/ability success

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.

Slime Squisher

Posts: 368

Joined: Thursday, 11th April 2013, 21:07

Post Thursday, 7th January 2021, 15:42

Re: Add LUA functions for spell/ability success

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)

For this message the author Implojin has received thanks:
snow
User avatar

Tomb Titivator

Posts: 857

Joined: Monday, 31st January 2011, 23:19

Post Thursday, 7th January 2021, 21:47

Re: Add LUA functions for spell/ability success

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!

Dungeon Master

Posts: 250

Joined: Thursday, 27th November 2014, 19:12

Post Friday, 8th January 2021, 09:58

Re: Add LUA functions for spell/ability success

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!

For this message the author ebering has received thanks:
Implojin
User avatar

Tomb Titivator

Posts: 857

Joined: Monday, 31st January 2011, 23:19

Post Friday, 8th January 2021, 10:37

Re: Add LUA functions for spell/ability success

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.

Dungeon Master

Posts: 250

Joined: Thursday, 27th November 2014, 19:12

Post Sunday, 10th January 2021, 07:03

Re: Add LUA functions for spell/ability success

doc.dcss.io has been updated, enjoy!

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

Return to Game Design Discussion

Who is online

Users browsing this forum: No registered users and 36 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.