Jehu's guide to Tf-triggers for newbies


Short and weird Trigger guide
If you didn't know, a trigger means a part of a script that detects a certain line of text from the mud and perform certain actions.
Since this is a newbie guide, i will not explain all details, but rather help you get started.

To trigger on the line:

You are hungry.

The trigger can look like this:

/def -mregexp -t'^You are thirsty.' needwater = drink barrel


(the word "needwater" is just an unique name for the triggerline it don't mean anything to the trigger. Each of your triggerlines must have a unique name)

Note, the ^ means start of line.
If you are going to make a trigger, the start of the line "/def -mregexp -t'" is good. There are however variations of that. For example "/def -mglob -t'" is also very common. I will stick with -mregexp for the examples since i think its good and flexible.

Ok fine, the style of the trigger for drinking from the barrel is good for many normal things, however, sometimes other factors are important in the situation. Then you can set variables. Variables in scripts work like a word that you connect to a value.
Ex. /set assist=1
What you do is you have a variable, leader, and you connect the name number 1 to it. In this example it might be used for some triggers to know if you have auto assist on.

A little note about "\"
Some signs like ', ( or ) for example, means things in commands in tf. So if you want to have them in the trigger pattern you need to put a \ before them for the trigger to interpret them correctly like this: \' or \(.

Now, in some triggers there will be a word in the textline that you don't know in advance. For example if you follow a person and they group you, and you want to set that persons name as leader. If it is one word containing letters, like a character's name your trigger can look like this: (here you can also see an example of how to use \ before the ') The line on the mud looks like this

You are now a member of Jehu's group.

And the trigger line will look like this:

/def -mregexp -t'^You are now a member of ([A-Za-z]+)\'s group.' grouped 


Ok so now we want something to happen, we want the leader variable to be set.

/def -mregexp -t'^You are now a member of ([A-Za-z]+)\'s group.' grouped = /set leader=%{P1} 


What was that? Well P1 means the first paranthesis in the trigger line, and that will in this case be the name of the one grouping you - the leader.
When you use the P1 variable in a normal command you add the %{ and } around it.
If you want to execute several commands in a row, you separate them with %;
Like this:
/def -mregexp -t'^You are now a member of ([A-Za-z]+)\'s group.'
grouped = /set leader=%{P1}%;/set assist=1 
Ok now we will make a trigger with a factor to check, with an "if" line. If is used to compare variables, numbers etc to see if everything is right so you should execute a command.
If you have a really long trigger, you might wanna put the command on the next line, then add a \ at the end of the line. AND NO SPACES AFTER THE \ or you'll get an error message.
/def -mregexp -t'^([A-Za-z]+) places' leaderplacesassist = \
/if ({P1}=~{leader}) assist%;/endif


Note that just after the paranthesis in the if statement, there should be no %;, but there is one before the endif. Endif simply means that it is the end of the if comparison.
Ok now lets improve it a bit more.

/def -mregexp -t'^([A-Za-z]+) places' leaderplacesassist = \
/if ({P1}=~{leader} & assist=1) assist%;/endif


Ok the & means both these comparisons have to be true to make you assist.
1. It must be the leader doing the places thing.
2. The assist variable must be 1 which should bean that you want to assist the group.


Ok, now a little about aliases and commands.
Let me give you an example:

/alias food 7sw%;buy 20 bread%;put all.bread bag%;e7n 


Here we have a simple alias that could just as well with some modification be a mudalias. You begin with the /alias command and then the name of the alias.. and then you stack a bunch of commands on the line.
If you want to use parameters you can do like this:

/alias pp cast 'powerword pain' {1} 


and to make that work you can either just type pp while fighting or for example pp hobbit to cast powerword pain on a poor hobbit.
There are also commands in tf that are not aliases but commands, then they are preceeded by a / They are made like this:

/def pp=cast 'powerword pain' {1} 


to use it you type /pp or /pp balrog for example.

Sometimes you want to use a word for a command but dont want it to be a normal alias. Say for example you want the command /use for /use fire or /use unlife If you made an alias it would make it so you could not type in the normal mudcommand use which is used for wands etc. Maybe thats a crappy reason... I usually use the commands for the stuff i will not type in manually but are parts of a big trigger and aliases for the things i'm supposed to type manually. Ok fine, now i want to show you how a couple of triggers can work together in a script.

/def -mregexp -t'^An Underground Lake' wellroomwater = /set no_rest=1


This sets the variable no_rest to 1

/def -mregexp -t'^You feel a slight movement in the air'
wellwindcoming = /if (no_rest=0) rest%;/endif


The wind is blowing, ok lets rest, IF its not a water room, because then no_rest is set to 1

/def -mregexp -t'^You follow ([A-Za-z]+)\'s group.$' groupmoving =
/set no_rest=0 


Ok now we are moving along to other rooms, now set no_rest to 0 again.

Well thats it, maybe I'll add more things later.

/Jehu