You stop a script from within the script by use of the line
exit
If you wanted to make a script stop when something happened in the game, then you would use a trigger to set a variable to true when the thing happened.
Activation box/Condition: whatever you like
On activation: endscript=true
In the script you would probably have a loop:
#loop
? (not endscript): exit
whatever the script does
~1
goto "loop"