ID:141781
 
                var/icon/I = new(M.icon)
I.Blend(rgb(0,0,0,100),ICON_SUBTRACT)
M.icon = I


This takes away some opacity, just like it's supposed to.

                var/icon/I = new(owner.icon)
I.Blend(rgb(0,0,0,100),ICON_ADD)
owner.icon = I


However, this also takes opacity away. How can I add opacity into an icon?

And yes, owner and M are the same mob, I'm positive.
Blend proc (icon)

...

Note: Currently, the alpha value of each pixel is only calculated as totally transparent or totally opaque. If you use Blend() with partially opaque icons the resulting alpha mask is unpredictable.
In response to Vermolius
Here's the irony: subtracting 100 actually makes the icon partially transparent. Then subtracting 100 more makes it a little more transparent. I think the reference needs updating, I was just tempted to try this recently despite the warnings, and it worked.
The refrence does need updating, but the problem you're experiencing is that you're not accounting for ICON_ADD and ICON_SUBTRACT correctly. In Blend(), alpha does not behave the same as red, green, and blue unless you're using ICON_MULTIPLY.

The ICON_ADD operation adds the RGB values of two icons together, but it combines their transparency; that is, a transparent pixel in one icon is always transparent in the result. Adding two 50% opaque icons together will produce a 25% opaque icon. The flip side of this is ICON_OR, which combines opacity; ORing two 50% opaque icons gives you a 75% opaque icon.

ICON_SUBTRACT is just like ICON_ADD, except it does subtraction on the RGB values instead of addition; it still combines transparency.

Thus, ICON_ADD and ICON_SUBTRACT always multiply the alpha values.

When you subtract rgb(0,0,0,100) from your icon, you're actually saying "Subtract nothing from the RGB colors of the icon, but reduce the opacity to 39%". That is, it's combining your original icon's alpha values with the 100 alpha (about 39% opacity), so it's effectively multiplying the opacity overall by 39%. The same thing happens when you use ICON_ADD because both operations will be identical when the RGB portion is black.

The solution is to use MapColors(). This should cut the alpha in half:

icon.MapColors(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0.5,0, 0,0,0,0)


And this will double it:

icon.MapColors(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,2,0, 0,0,0,0)


Since halving the alpha is as easy as blending with rgb(255,255,255,128) using ICON_MULTIPLY, or rgb(0,0,0,128) with ICON_ADD, I'd suggest that in place of MapColors() for speed.

Ordinarily though if you're doing a temporary change to an icon and want to go back to using the original when you're done, the best way is to just keep track of the original icon, not re-modify the modified version.

Lummox JR
In response to Lummox JR
Thanks for the help, I wondered why it wasn't working correctly; I guess I can only blame my own assumptions!

Ordinarily though if you're doing a temporary change to an icon and want to go back to using the original when you're done, the best way is to just keep track of the original icon, not re-modify the modified version.

Already doing that, I realized my method wasn't so good when looking at it again.

Also, this is the beginning of a good reference entry...