TF prompt capture

by Alger

Back to Mechanic's Corner.

Alger2004-12-03 05:46:57
I can capture prompt by using a hook on a terminated - with something like
/def -h"PROMPT *-" prompt = /test prompt %; (other prompt commands) (that could be wrong but im not at home and brains fried). I've never been able to figure out how to capture the exact prompt effectively though so that i could save the individual values in respective variables.

I've tried a regular expression approach going /def -p0 -mregexp -h'(%d)h, (%d)m, etc etc (.*)-' but that doesnt work either... well it does but i end up catching the ansi codes (i think its the ansi code) as well and my captured strings end up with something like ]38]]34]3333h,]38]]34] ...

maybe someone here could enlighten me?
Thorgal2004-12-03 07:59:56
You mean something like:

string:
(*)h, (*)m, (*)p (*)

value:
currenthealth=%1
currentmana=%2
promptscan=%4
checkprompt

alias:
checkprompt

value:
#if %pos( x, @promptscan) {bal=yes} {bal=no}
#if %pos( e, @promptscan) {eq=yes} {eq=no}
#if %pos( p, @promptscan) {hindered=yes} {hindered=no}
#if %pos( k, @promptscan) {kafe=1} {kafe=0}
#if %pos( b, @promptscan) {blindness=1} {blindness=0}
#if %pos( d, @promptscan) {deafness=1} {deafness=0}
Alger2004-12-03 12:21:29
erm... you talking about tinyfugue thorgal?

you cant have (*) by itself has to be something like (.*) with the way tf handles regexp (of course depending on how you want it to treat the string)... so that line wouldnt work...

if i used that it would come up with a regexp error pertaining to the * not following anything and values picked up would be something like

% health=
Ralshan2004-12-03 13:19:57
I worked out a prompt hook for Imperian in Tinyfugue, it ended up really complex and I haven't yet adapted it to Lusternia, though it'd be fairly easy to do so. If it helps, here's my hook line:

CODE
/def -mregexp -h"PROMPT ^*H:*m(+)*M:*m(*)*<*()*()(*)>" catch_prompt = /set hp={P1}%;/set mana={P2}%;/if ({P3} =~ "e") /set eq=1%; /else /set eq=0%; /endif%;/if ({P4} =~ "b") /set bal=1%; /else /set bal=0%; /endif%;/set rest_prompt={P5}%;/if (strstr(rest_prompt, "p") > -1) /set prone=1%; /else /set prone=0%; /endif%; /test prompt(strcat({*}, " "))%;


Basically I just had to work around the color codes. For reference, the prompt in Imperian looks something like:

H:328 M:264
Alger2004-12-03 14:33:56
thanks ralshan
Neale2004-12-03 14:46:12
Hmm, I'm using a different client, but what I do for situations like that is make a copy of the string, remove all the ANSI from it, and then use that to get whatever values I need, while I send the normal, colourful string out to the display.

CODE
var ansiColourRegExp = /\\;)?(3)?(4)?m/g;
var incomingStripped = incoming.replace(ansiColourRegExp, "");
Alger2004-12-03 23:13:21
well i got something to work but it could be better...

CODE
/def -p0 -mregexp -h"PROMPT ^*m(*)*h,*m*m (*)*m,*m*m (*)*e,*m*m (*)*p,*m*m (*)*en,*m*m (*)*w*m *()" promptcheck = \\
  /set hp=%P1 %;\\
  /set mp=%P2 %;\\
  /set ego=%P3 %;\\
  /set power=%P4 %;\\
  /set endurance=%P5 %;\\
  /set willpower=%P6 %;\\
  /test prompt(strcat({*}, " ")) %;\\
  /illusioncheckset %;\\
  /breakprompt %;\\
  /herbchecking %;\\
  /salvechecking %;\\
  /smokechecking %;\\
  /focuschecking %;\\
  /sippingid %;\\
  /stuncheck %;\\
  /illusioncheckreset %;\\
  /standing %;\\
  /breath %;\\
  /mliner %;\\
  /attack

/def -p1 -mregexp -h"PROMPT ^*m*m(*)*h,*m*m (*)*m,*m*m (*)*e,*m*m (*)*p,*m*m (*)*en,*m*m (*)*w*m *()" promptcheck2 =\\
  /set hp=%P1 %;\\
  /set mp=%P2 %;\\
  /set ego=%P3 %;\\
  /set power=%P4 %;\\
  /set endurance=%P5 %;\\
  /set willpower=%P6 %;\\
  /test prompt(strcat({*}, " ")) %;\\
  /illusioncheckset %;\\
  /breakprompt %;\\
  /herbchecking %;\\
  /salvechecking %;\\
  /smokechecking %;\\
  /focuschecking %;\\
  /sippingid %;\\
  /stuncheck %;\\
  /illusioncheckreset %;\\
  /standing %;\\
  /breath %;\\
  /mliner %;\\
  /attack


need to seperate the *() and how to make it just 1 capture line... not sure how yet though
Thorgal2004-12-04 11:10:16
Ew, you people should start using zmud tongue.gif. I'm getting a headache even looking at this stuff.
Ioryk2004-12-06 22:43:17
Announce post 82 says you can add a linebreak to the prompt. The help scroll for this doesn't say how. Anyone know anything about this? I have a lot of balance stuff relying on balance and equi prompts.
Neale2004-12-07 14:30:31
QUOTE (Ioryk @ Dec 6 2004, 06:43 PM)
Announce post 82 says you can add a linebreak to the prompt.  The help scroll for this doesn't say how.  Anyone know anything about this?  I have a lot of balance stuff relying on balance and equi prompts.

CONFIG PROMPT ADD LINEBREAK
Ioryk2004-12-07 16:05:25
QUOTE(Neale @ Dec 7 2004, 02:30 PM)
CONFIG PROMPT ADD LINEBREAK
14542



Top stuff, thanks.
Unknown2004-12-24 00:30:31
QUOTE(Thorgal @ Dec 4 2004, 06:10 AM)
Ew, you people should start using zmud tongue.gif. I'm getting a headache even looking at this stuff.
13706



I wish I had my vials system handy, mr zmud... TF is a *NIX client. Zmud is not.
Unknown2005-01-04 18:16:39
Here's a somewhat nicer looking regex for stripping ansi codes. This is python, so adapt to your language of choice.
CODE
re.compile(chr(27) + '\\*')
Unknown2007-09-11 04:18:24
Adding a number to the string strips color codes.

This reply is a bit late, but maybe it will help someone else. I found a post by bwbettin that gave a prompt hook example. The prompt catch regexp is very clean and easy to understand. The work of stripping the color codes is simply done by adding zero to the captured number in an expression evaluation ($):

/eval /set health $

For a complete example of capturing the prompt see:
http://forums.lusternia.com/index.php?s=&a...ost&p=80620