I didn't have a look at zyblade's cap, but generally you just have to map the distance to the opacity by making it a relative value.
1) First you decide, which values correspond to 0% and 100%.
2) Now with those min and max values you convert the distance to a relative value.
Example:
minDistance (corresponds to 100%) 60 pixel
maxDistance (corresponds to 0%) 500 pixel
now you see that you need to map a range of 440 with an offset of 60
t-value (the relative value you want to know)
1 - (distance - minDistance) / (maxDistance - minDistance)
Let's assume distance is 280 at the moment:
1 - (280 - 60) / (500 - 60) = 1 - 220 / 440 = 1 - 0.5 = 0.5
Or distance is 170 at the moment:
1 - (170 - 60) / (500 - 60) = 1 - 110 / 440 = 1 - 0.25 = 0.75
The term "(distance - minDistance) / (maxDistance - minDistance)
" will always calculate a relative value from lowest to highest, so that in this example 60 corresponds to 0.0 and 500 to 1.0, but you need it the other way round. That's why "1 - " is added in the beginning. It reverses the result.
You now have to multiply the result by 100 to get an opacity value in the range [0, 100].
If you would use the above formula like that, you would also get values, if distance is outside your limits 60 and 500. For example, if distance is 610 at the moment:
1 - (610 - 60) / (500 - 60) = 1 - 550 / 440 = 1 - 1.25 = -0.25
But opacity only knows values between 0.0 and 1.0 (or 0% and 100%). That's why you can use clamp (it isn't really needed in this particular scenario, because opacity automatically clamps any value to the range [0, 100], but it doesn't hurt either and is good practice)
clamp(t-value * 100, 0, 100)
sets "t-value * 100" to 100 for any value that is higher than 100, and to 0 for any value that is lower than 0
If you don't feel like calculating the t-value for yourself, there's the math plugin by lucid, which, if I remember correctly, has a function to retrieve a t-value.