Auto exit on low hp.


Ask fellow adventurers how to stay alive in the deep, dark, dangerous dungeon below, or share your own accumulated wisdom.

User avatar

Slime Squisher

Posts: 342

Joined: Friday, 2nd May 2014, 15:02

Post Friday, 2nd May 2014, 15:02

Auto exit on low hp.

Does anyone know how make a macro that would auto exit dcss on low hp?
[09:23] <Sequell> kroki is a greatplayer!
[09:23] <Sequell> kroki is a greaterplayer!
[03:57] <Sequell> kroki is a polytheist!
[21:53] <Sequell> kroki is a greatberserker!

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Friday, 2nd May 2014, 15:29

Re: Auto exit on low hp.

  Code:
<
  function ready()
    DmgTrack()
  end
>

: local dmg_old_hp = 0
 
: function DmgTrack()
:   local bot_hp, bot_mhp = you.hp()
:   local dmg_inturn = 0
:   local huge_int = 0
:   local percent_hp = 0
:   local percent_old_hp = 0
:   local percent_hp_txt = "--%"
:   if dmg_old_hp > 0 then
:     if bot_hp < dmg_old_hp then
:       dmg_inturn = dmg_old_hp - bot_hp
:       percent_old_hp = math.ceil((dmg_old_hp*100)/bot_mhp)
:       percent_hp = math.ceil((bot_hp*100)/bot_mhp)
:       percent_hp_txt = percent_hp .. "%"
:       if percent_hp < 30 then
:       percent_hp_txt = "<red>" .. percent_hp_txt .. "</red>"
:       elseif percent_hp < 55 then
:         percent_hp_txt = "<lightred>" .. percent_hp_txt .. "</lightred>"
:       elseif percent_hp < 75 then
:         percent_hp_txt = "<yellow>" .. percent_hp_txt .. "</yellow>"
:       end   
:       percent_hp_txt = percent_hp_txt .. "<darkgray>(" .. bot_hp .. "hp)</darkgray>"
:       if dmg_inturn > (bot_hp*0.25) then
:         if dmg_inturn > (bot_hp*0.45) and dmg_inturn > 2 then
:         crawl.mpr("<green>Mandatory exit. Think how to survive! </green>")
:           crawl.mpr("<white>Huge Dmg:</white> <red>-" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "</red> hp: " .. percent_hp_txt)
:           crawl.flush_prev_message()
:           crawl.more()
:   autoexit_note(dmg_inturn, bot_hp)
:           crawl.sendkeys("S")
:           crawl.sendkeys("y")
:         else
:           crawl.mpr("<white>Huge Dmg:</white> <red>-" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "</red> hp: " .. percent_hp_txt)
:           dmg_old_hp = bot_hp
:           crawl.flush_prev_message()
:           crawl.more()
:           crawl.more_autoclear()         
:         end
:       else
:         if dmg_inturn > (bot_hp*0.15) then
:           crawl.mpr("<white>Damage</white>: <yellow>-" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "</yellow>   hp: " .. percent_hp_txt)
:         else
:           crawl.mpr("<white>Damage</white>: -" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "   hp: " .. percent_hp_txt)
:         end
:       end
:       crawl.flush_prev_message()
:     end
:   end
:   dmg_old_hp = bot_hp
: end

: function autoexit_note(l, r)
:   crawl.take_note("=================== Autoexit: lost:" .. l .. " current:" .. r)
: end

For this message the author Sandman25 has received thanks:
kroki

Snake Sneak

Posts: 95

Joined: Sunday, 24th July 2011, 19:17

Post Friday, 2nd May 2014, 15:34

Re: Auto exit on low hp.

It even tells you "Think how to survive!" Awesome.
10 Wins: NaGl* (15) MuCj (15) DsFE* (4) DsWn*+ (5,8) HaBe (3) DECj (15) SpAK (5) GrBe+ (4) HoCK+ (15)
* on CAO; + on CZO
User avatar

Slime Squisher

Posts: 342

Joined: Friday, 2nd May 2014, 15:02

Post Friday, 2nd May 2014, 15:40

Re: Auto exit on low hp.

Thank you Sandman, now where do I put all this code to make it work in-game?
[09:23] <Sequell> kroki is a greatplayer!
[09:23] <Sequell> kroki is a greaterplayer!
[03:57] <Sequell> kroki is a polytheist!
[21:53] <Sequell> kroki is a greatberserker!

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Friday, 2nd May 2014, 15:50

Re: Auto exit on low hp.

If you play locally, put it into settings/init.txt.
If online, put it into your RC file (it's specific for every server).

Also note you can change
"dmg_inturn > (bot_hp*0.45) and dmg_inturn > 2" to whaever you like. Currently it autosaves if received damage is more than 45% of HP after the hit AND the received damage is greater than 2. The latter helps to avoid annoying autosaves from poison on low HP.

For this message the author Sandman25 has received thanks:
kroki

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Friday, 2nd May 2014, 15:53

Re: Auto exit on low hp.

Midpoint wrote:It even tells you "Think how to survive!" Awesome.


I added it after multiple spectators got kicked out of my online game without realizing what happened :)
User avatar

Slime Squisher

Posts: 342

Joined: Friday, 2nd May 2014, 15:02

Post Friday, 2nd May 2014, 16:08

Re: Auto exit on low hp.

It auto-exits after berserk rage expires (you lose 50% max hp at the time - makes sense). any way to fix that?

Other than setting the variable to 51% :P
[09:23] <Sequell> kroki is a greatplayer!
[09:23] <Sequell> kroki is a greaterplayer!
[03:57] <Sequell> kroki is a polytheist!
[21:53] <Sequell> kroki is a greatberserker!

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Friday, 2nd May 2014, 16:16

Re: Auto exit on low hp.

kroki wrote:It auto-exits after berserk rage expires (you lose 50% max hp at the time - makes sense). any way to fix that?

Other than setting the variable to 51% :P


Sorry, I don't know. I just took the script and added autosave to it. Maybe there is a way to check status (exhausted and slowed) in lua, I will investigate during weekend.

Tomb Titivator

Posts: 832

Joined: Wednesday, 17th April 2013, 13:28

Post Friday, 2nd May 2014, 17:56

Re: Auto exit on low hp.

As a fellow user of the auto exit function, I'd suggest against checking for Exh and Slow. I thought about that too, then realized there are corner cases that could bite you. Example: berserk wears off, you're hurt and there are still enemies on the screen. IMO that still warrants auto exit. So I think I'd rather the function be too conservative, rather than have it miss a potential life threatening situation.

Though I still think being tormented is more annoying :D

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Friday, 2nd May 2014, 19:06

Re: Auto exit on low hp.

DracheReborn wrote:As a fellow user of the auto exit function, I'd suggest against checking for Exh and Slow. I thought about that too, then realized there are corner cases that could bite you. Example: berserk wears off, you're hurt and there are still enemies on the screen. IMO that still warrants auto exit. So I think I'd rather the function be too conservative, rather than have it miss a potential life threatening situation.

Though I still think being tormented is more annoying :D


Right, I am not going to use the berserk fix in my games, just for OP, I understand how annoying it can be for Be early game.

You can avoid autosave on torment from full life by something like

dmg_inturn > (bot_hp*0.45) and dmg_inturn > 2 and dmg_inturn < 100

I will use it as is, I like autosave after torment from full life, that reminds me that I should get out of LoS ASAP even at full HP :)

Ziggurat Zagger

Posts: 11111

Joined: Friday, 8th February 2013, 12:00

Post Saturday, 3rd May 2014, 02:33

Re: Auto exit on low hp.

New version does not autosave on turn when berserk ends or starts. But be careful, it can kill you

  Code:
: local dmg_old_hp = 0
: local old_berserk = you.berserk()
 
: function DmgTrack()
:   local bot_hp, bot_mhp = you.hp()
:   local berserk = you.berserk();
:   local dmg_inturn = 0
:   local huge_int = 0
:   local percent_hp = 0
:   local percent_old_hp = 0
:   local percent_hp_txt = "--%"
:   if dmg_old_hp > 0 then
:     if bot_hp < dmg_old_hp then
:       dmg_inturn = dmg_old_hp - bot_hp
:       percent_old_hp = math.ceil((dmg_old_hp*100)/bot_mhp)
:       percent_hp = math.ceil((bot_hp*100)/bot_mhp)
:       percent_hp_txt = percent_hp .. "%"
:       if percent_hp < 30 then
:       percent_hp_txt = "<red>" .. percent_hp_txt .. "</red>"
:       elseif percent_hp < 55 then
:         percent_hp_txt = "<lightred>" .. percent_hp_txt .. "</lightred>"
:       elseif percent_hp < 75 then
:         percent_hp_txt = "<yellow>" .. percent_hp_txt .. "</yellow>"
:       end   
:       percent_hp_txt = percent_hp_txt .. "<darkgray>(" .. bot_hp .. "hp)</darkgray>"
:       if dmg_inturn > (bot_hp*0.25) then
:         if dmg_inturn > (bot_hp*0.45) and dmg_inturn > 2 and berserk == old_berserk then
:         crawl.mpr("<green>Mandatory exit. Think how to survive! </green>")
:           crawl.mpr("<white>Huge Dmg:</white> <red>-" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "</red> hp: " .. percent_hp_txt)
:           crawl.flush_prev_message()
:           crawl.more()
:           autoexit_note(dmg_inturn, bot_hp)
:           crawl.sendkeys("S")
:           crawl.sendkeys("y")
:         else
:           crawl.mpr("<white>Huge Dmg:</white> <red>-" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "</red> hp: " .. percent_hp_txt)
:           dmg_old_hp = bot_hp
:           crawl.flush_prev_message()
:           crawl.more()
:           crawl.more_autoclear()         
:         end
:       else
:         if dmg_inturn > (bot_hp*0.15) then
:           crawl.mpr("<white>Damage</white>: <yellow>-" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "</yellow>   hp: " .. percent_hp_txt)
:         else
:           crawl.mpr("<white>Damage</white>: -" .. (percent_old_hp-percent_hp) .. "%<darkgray>(-" .. dmg_inturn .. "hp)</darkgray>" .. "   hp: " .. percent_hp_txt)
:         end
:       end
:       crawl.flush_prev_message()
:     end
:   end
:   dmg_old_hp = bot_hp
:   old_berserk = berserk
: end

: function autoexit_note(l, r)
:   crawl.take_note("=================== Autoexit: lost:" .. l .. " current:" .. r)
: end

Return to Dungeon Crawling Advice

Who is online

Users browsing this forum: No registered users and 69 guests

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