I have an idea that might be easyer.
Put:
this addeventhandler ["fired",{_this exec "yourscript.sqs"}]
In the units init. field.
and put:
_whatever = _this select 2
?(_whatever == "detonate") : goto "loop1"
goto "exit"
#loop1
blah blah blah
#exit
exit
in your script somewhere
That should make the script work only when you detonate a pipebomb.
Note: Check out Igor Drukov's event handler tutorial, it is really good and I learned a lot from it.