Lua: [More] when buffs are running out


Questions, Explanations, Howtos

Slime Squisher

Posts: 387

Joined: Monday, 15th August 2011, 16:31

Location: Frankfurt

Post Monday, 29th April 2013, 08:04

Lua: [More] when buffs are running out

I'd like to add something to my rc that forces a [more] prompt (or something functionally equivalent), whenever certain combat buffs such as Ozocubu's, Stoneskin, Shroud etc. are about to run out. But here's the catch: I want this only when I'm in combat. I suppose that could be done in Lua, could it? Would anybody give me some pointers?

I suppose, I can learn from autofight.lua how to check whether there is a monster in LoS. (It would be nice if this would trigger only if the situation provides some amount of challenge -- may be with the 'tension' system? -- but this is of secondary importance.)

Otherwise, I suppose I need a way to trigger the function. Is there a hook variable or something into which to put functions that run whenever there is a message?

I'd then have to find a way to force the player to hit <space> before any other action. But maybe I can figure that out based on the answer to that last question.
"... while we / Unburden'd crawl toward death." -- King Lear I,1

Mines Malingerer

Posts: 51

Joined: Monday, 1st April 2013, 04:54

Post Tuesday, 10th June 2014, 17:21

Re: Lua: [More] when buffs are running out

This is a good idea, I use plenty of more prompts and would love to limit the combat ones.

I used some hacked together monster detection in HDAtravel and SpoilerAlerts but these use a function which checks every square, and returns a table.

In source/l_you.cc appears to be defined the function you.feel_safe() which by the name of it may also work.

I still haven't gotten the hang of redefining options every turn, but it looks like qw uses crawl.setopt() for it's options, but doesn't use any more prompts.

Something similar to this code might work, but you may also need to have an else clause which clears all your force_more_messages.
  Code:
<
if not you.feel_safe() then
  crawl.setopt("force_more_message = Your icy (shield|armour) evaporates")
end
>


Utis wrote:Is there a hook variable or something into which to put functions that run whenever there is a message?

You can use the function crawl.messages() to check the messages you have received, and then you could use that to trigger a more prompt. You could probably check your current hp to to approximate threat.
  Code:
<
local hp, max_hp = you.hp()
if string.find(crawl.messages(number_of_messages_to_check), string_to_check) and not you.feel_safe() and (hp < (max_hp *0.50)) then
  crawl.more()
end
>

Return to Coding

Who is online

Users browsing this forum: No registered users and 4 guests

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