Creating one-shot *triggers* in scripts

Posted by Krenath on Tue 29 Jan 2002 10:00 PM — 3 posts, 18,126 views.

USA #0
If you want a simple way of programmatically creating a one-shot trigger, here are two VBscript subroutines you can use which will generate a trigger with a random name that will delete itself upon firing.


Sub OneShotTrigger(sPattern,sResponseText)
	Dim iFlags,iRand
	Randomize timer
	iRand=int(32767*rnd(1)+1)
	iFlags = eEnabled+eKeepEvaluating+eIgnoreCase+eTriggerRegularExpression+eExpandVariables+eReplace
	World.AddTrigger "OneShot_"&iRand,sPattern,sResponseText,iFlags,-1,0,"","OnDeleteTrigger"
End Sub

Sub OnDeleteTrigger(sName,sOutput,aParams)
	world.deletetrigger sName
End Sub


You can then call OneShotTrigger with your pattern and the text you want to send as a response and not have to worry about the trigger waiting around to fire at inappropriate times.


OneShotTrigger "Bob has connected.","say Hi, Bob!"

THe above will greet bob the next time he connects, but not repeat if he disconnects and reconnects.

Australia Forum Administrator #1
Nice idea.

You can save a small amount of effort, and make the trigger names stay unique for longer, by using World.GetUniqueNumber.

This returns a unique number for the session, that is a "long" so it has a larger range of values than the 32,767 you used in conjunction with the rnd function.

Australia Forum Administrator #2
However, I must admit that your way is better if you are likely to be adding triggers over multiple sessions, as the GetUniqueNumber function only supplies a unique number for a particular execution of MUSHclient.