Ah, Shadowfyr offers some efficient code. The second trigger is enabled only when needed, then disabled afterwards. Because you said you sometimes do the casting yourself, I have modified Shadowfyr's code a little, and offer this updated version:
Alias: blind *
Name: BlindAttemptbyMe
Script: BlindTest
Trigger: * utter's the words 'blindness'.
Name: BlindAttemptbyOther
Script: BlindTest
Trigger: * seems to be blinded!
Name: MobBlinded
Script: BlindTest
Script:
dim BlinderName
sub BlindTest (tname, output, wilds)
select tname
case "BlindAttemptbyMe"
world.enabletrigger "MobBlinded", vbTrue
BlinderName = "Me"
world.send "cast 'blindness' " & wilds(1)
case "BlindAttemptbyOther"
world.enabletrigger "MobBlinded", vbTrue
BlinderName = wilds(1)
case "MobBlinded"
world.send "grouptell " & wilds(1) & " blinded by " & BlinderName & "."
world.enabletrigger "MobBlinded", vbFalse
end select
end sub
Both of your triggers, and your alias to cast the spell all call the same scripting subroutine. The subroutine uses a CASE statement (which works sort of like an IF statement) to check where it was called from, then acts accordingly.
In this new example, the "Ok." line you mentioned is ignored. I assume if you fail, "BlinderName" will be overwritten later when another attempt is made by yourself again, or some other player.
You will notice in the code, a lack of GetVariable and SetVariable function calls. Instead, we simply create a variable in Visual Basic, first declaring and ititializing in with the "DIM" statement. Because the "DIM" line is outside any subroutine, it will be executed immediately when your script is first loaded (or reset), and it will also be 'global' to all subroutines. In other words, any of the subroutines in your script file can interact with that variable.
If you had put the "DIM" statement inside a subroutine, then that particular variable would only remain in memory while that subroutine was being executed. Once the "End Sub" line is reached, the variable is discarded from memory.
VBS isn't really that hard. It's quite easy to learn, especially with the help file that Shadowfyr recently linked to in another thread.
Your original idea of just using two triggers, and no script at all, might have worked, but your alias complicated the matter too much, so you are forced to script to accomplish your goal. |