Lesson Four: IF and IF TRIGGERSSL files consist (to first approximation) of three sorts of blocks. The first are ACTION DEFINITIONS of the sort I talked about above. These are processed when they occur in the file and are kept in memory for the rest of the run (so if you call two SSL files in one compilation run, any ACTION DEFINITIONs in the first are available in the second).
The second are plain BCS blocks, of the sort you'd find in any BAF file. It's convenient to call them IF blocks, since they always start with an IF. Any BCS block is valid in SSL (though SSL sometimes requires entries to be on separate lines, so it's best to avoid multiline scripting on principle); as we'll see later, SSL also admits a few commands for IF blocks that BAF doesn't.
The most important blocks are SSL blocks, also called IF TRIGGER blocks. A simple example would be
IF TRIGGER
Target(NearestEnemyOf(Myself))
THEN DO
Action(Spell,WIZARD_FLAME_ARROW)
END
If the Spell action hasn't been defined already, SSL will fail on this block. But if Spell is defined as above, the block will be compiled as
IF
!GlobalTimerNotExpired("cast","LOCALS")
HaveSpell(WIZARD_FLAME_ARROW)
See(NearestEnemyOf(Myself))
THEN
RESPONSE #100
SetGlobalTimer("cast","LOCALS",6)
Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END
So far, not much of a saving. But multiple targets can be defined.
IF TRIGGER
Target([PC.0.0.MAGE])
Target(NearestEnemyOf(Myself))
THEN DO
Action(Spell,WIZARD_FLAME_ARROW)
END
compiles as
IF
!GlobalTimerNotExpired("cast","LOCALS")
HaveSpell(WIZARD_FLAME_ARROW)
See([PC.0.0.MAGE])
THEN
RESPONSE #100
SetGlobalTimer("cast","LOCALS",6)
Spell([PC.0.0.MAGE],WIZARD_FLAME_ARROW)
END
IF
!GlobalTimerNotExpired("cast","LOCALS")
HaveSpell(WIZARD_FLAME_ARROW)
See(NearestEnemyOf(Myself))
THEN
RESPONSE #100
SetGlobalTimer("cast","LOCALS",6)
Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END
And multiple actions can be applied.
IF TRIGGER
Target(NearestEnemyOf(Myself))
THEN DO
Action(Spell,WIZARD_FLAME_ARROW)
Action(Spell,WIZARD_MAGIC_MISSILE)
END
compiles to
IF
!GlobalTimerNotExpired("cast","LOCALS")
HaveSpell(WIZARD_FLAME_ARROW)
See(NearestEnemyOf(Myself))
THEN
RESPONSE #100
SetGlobalTimer("cast","LOCALS",6)
Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END
IF
!GlobalTimerNotExpired("cast","LOCALS")
HaveSpell(WIZARD_MAGIC_MISSILE)
See(NearestEnemyOf(Myself))
THEN
RESPONSE #100
SetGlobalTimer("cast","LOCALS",6)
Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)
END
And this can be combined: hopefully it's obvious what
IF TRIGGER
Target([PC.0.0.MAGE])
Target(NearestEnemyOf(Myself))
THEN DO
Action(Spell,WIZARD_FLAME_ARROW)
Action(Spell,WIZARD_MAGIC_MISSILE)
END
does, though it's perhaps worth noting that each Target has the first Action applied to it before moving on to the next Action. So this block first tries to cast Flame Arrow at a mage, then at anyone; then it tries to cast Magic Missile at a mage, then at anyone.