Elf programming example #1

strip PROMPT and fully paint it

Task: recognise the presence of the prompt at the beginning of a line. Paint it an a line by itself. Remove the prompt from the line so that following triggers receive a cleaner line of text. 
The prompt is painted showing HP, MANA and MOVEMENT gray, yellow, or red coloured to highlight dangerous values.
View the source code now.

To achieve this task requires several steps:

First of all we need to recognise the presence of the prompt on a line. This requires a trigger.
We can work in two different ways:
  1. we can use the flag CHECK FOR PROMPT
  2. we can fully qualify our prompt test
We'll use the second way: since my prompt looks like
H193 M360 V172 540000 Mob:* Tank:* >
the prompt test (i.e. the trigger) will be
H* M* V* * Mob:* Tank:* >*

We also need to set the CHECK COMPLETE LINES flag, otherwise it might happen that a partial line containing the prompt arrives from the mud and the trigger would be activated on it (partial lines are checked against triggers if there is some lag on the network (i.e., on very fast computers even a lag of a tenth of a second would be enough)).
This trigger has to be one of the first in your trigger list.

The commands related to this trigger are the following:
<prompt %1a %2a %3a %4a %5a %6a
@NewLine @ParmS(7=a)

The first command is a call to a user-defined alias, named prompt, we'll soon be seeing. We pass to that alias all the variable parts of our prompt (i.e. MANA, HP, MOV,...).
The second one replaces the line against which the remaining triggers are checked. Actually it simply sets that line to whatever appears right after the end of the prompt.

Now we must write the alias that actually writes the prompt on a separate line.

The alias will be activated by the pattern
prompt * * * * * *
since we want to pass to it 6 parameters that contain no spaces. If we had to pass parameters containing spaces (and, for instance, no commas), we would have to use the following pattern
prompt *,*,*,*,*,*

The commands related to this alias are the following:
@SLocal p
<colorise %1a 80 135
@p=@FGDarkGray+"H"+@TempS
<colorise %2a 80 150
@p=@p+@FGDarkGray+" M"+@TempS
<colorise %3a 80 120 @p=@p+@FGDarkGray+" V"+@TempS+@FGDarkGray+" %4a Mob:%5a Tank:%6a >"
@OutStr @p

The first meta-command @SLOCAL creates a temporary local string variable named p in which we'll store the restyled prompt.
The second line contains a call to another user-defined alias named colorise that we'll see later. This alias sets the color of a number depending on the passed threshold values. The resulting string (including the ANSI sequence for setting the right color) is stored in the variable @TempS.
The third line stores the first part of our restyled prompt, setting additional colors.
The following lines do almost the same thing for the other values (MANA and MOVEMENT).
The last lines output the resulting prompt to the screen.

Now we must write the alias to colorise a number.

The alias will be activated by the pattern
colorise * * *
where the first parameter is the actual value we want to colorise. The second and third parameters are the threshold values that define which color to use.

the commands related to this alias are the following:
@NLocal n
@n=@ParmN(1a)
@If @n<=@ParmN(2a)
@TempS=@FGRed
@Skip 4
@If @n<=@ParmN(3a)
@TempS=@FGYellow
@Skip 1
@TempS=@FGDarkGray
@TempS=@TempS+@NToS(@n)

These commands check the actual value against the thresholds to decide whether to use yellow, red or dark gray.

The result is stored in the string variable @TempS.

At this point we are almost ready. But that's not all!
We still have to define a trigger to output the rest of the line instructing elf to ignore the line received from the mud (i.e., to avoid outputting it to the screen).
The trigger will be
*

Yes! simply '*', because we want to trap whatever remains after prompt stripping.
We must set the following flags in order for this trigger to work: CHECK COMPLETE LINES, REMOVE ORIGINAL LINE, LAST TRIGGER TO CHECK IF ACTIVATED.
The magic is done by removing the original line!
This trigger has to be the very last trigger in our list of triggers.

The commands related to this trigger are the following:
@OutStr @ParmS(1=a)

This meta-command simply outputs to the screen what remained on the line after prompt stripping.

Here is the necessary programming for this task:
 
trigger STRIP prompt
trigger H* M* V* * Mob:* Tank:* >*
flags check complete lines
commands <prompt %1a %2a %3a %4a %5a %6a 
@NewLine @ParmS(7=a)
 
trigger Show line without prompt
trigger *
flags check complete lines, remove original line, last trigger to check if activated
commands @OutStr @ParmS(1=a)
 
alias Show prompt
pattern prompt * * * * * *
flags none
commands @SLocal p 
<colorise %1a 80 135 
@p=@FGDarkGray+"H"+@TempS 
<colorise %2a 80 150 
@p=@p+@FGDarkGray+" M"+@TempS 
<colorise %3a 80 120 @p=@p+@FGDarkGray+" V"+@TempS+@FGDarkGray+" %4a Mob:%5a Tank:%6a >" 
@OutStr @p
 
alias Colorise
pattern colorise * * *
flags none
commands @NLocal n 
@n=@ParmN(1a) 
@If @n<=@ParmN(2a) 
@TempS=@FGRed 
@Skip 4 
@If @n<=@ParmN(3a) 
@TempS=@FGYellow 
@Skip 1 
@TempS=@FGDarkGray 
@TempS=@TempS+@NToS(@n)
 

These pages were developed with Netscape Composer 4.03 by Alfredo Milani-Comparetti  
Last modified on 8 nov 1997