• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[General] Make unit Transparent

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
JASS:
call SetUnitVertexColor(whichUnit, red, green, blue, alpha)

Red, green, blue and alpha are integers between 0 and 255.
By reducing alpha you can make the unit transparent.
For example:

JASS:
call SetUnitVertexColor(u, 255, 255, 255, 127)

This will make u 50% transparent.
 

Kusanagi Kuro

Hosted Project: SC
Level 10
Joined
Mar 11, 2012
Messages
708
Or through this action in trigger:
  • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 50.00% transparency
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
This function only hides the unit, the shadow remains.

Did you know you can set a variable to the handle of a newly created image, then destroy the image, then create a unit and then that variable points to the shadow of the newly created unit?
This way you can move the shadow of the unit out of bounds or hide it. Also, both vertex coloring and moving the image out of bounds can be done locally for a player.
I'm not yet sure if it desyncs for showing images locally.
This way you can completely locally hide a unit for a player. But then again, this can also be accomplished with the windwalk ability.

Some time ago I got an example from Magtheridon96:
JASS:
function CreateUnitAndGetShadow takes nothing returns image     
    // Handle id of this image is now 0    
    local image i = CreateImage("dummy.blp", 64, 64, 0, 0, 0, 0, 64, 64, 0, 3)     
    // Image destroyed, i points to 0     
    call DestroyImage(i)     
    // This unit will also create an image (it's shadow)     
    // This shadow will have a Handle Id of 0     
    // i points to an image with Id 0     
    call CreateUnit(...)     
    // Thus i is now the actual shadow of the unit ^_^     
    return i 
endfunction


Some useful natives in this case.
JASS:
native CreateImage takes string file, real sizeX, real sizeY, real sizeZ, real posX, real posY, real posZ, real originX, real originY, real originZ, integer imageType returns image
native DestroyImage takes image whichImage returns nothing
native ShowImage takes image whichImage, boolean flag returns nothing
native SetImageConstantHeight takes image whichImage, boolean flag, real height returns nothing
native SetImagePosition takes image whichImage, real x, real y, real z returns nothing
native SetImageColor takes image whichImage, integer red, integer green, integer blue, integer alpha returns nothing
native SetImageRender takes image whichImage, boolean flag returns nothing
native SetImageRenderAlways takes image whichImage, boolean flag returns nothing
native SetImageAboveWater takes image whichImage, boolean flag, boolean useWaterAlpha returns nothing
native SetImageType takes image whichImage, integer imageType returns nothing

I hope this was useful to someone.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
the function posted above can't do this.

Are you sure about that ^.^?
Because I'm quite sure I can hide an image (shadow) with:
JASS:
native ShowImage takes image whichImage, boolean flag returns nothing
 
I tested your function and didn't work...

I figured out you only need to do this to retrieve the unit shadow:

JASS:
call CreateUnit( Player(0), 'hfoo', 0, 0, 270 )
set UnitShadow = bj_lastCreatedImage

You can also destroy the shadow when the unit is created:

JASS:
call CreateUnit( Player(0), 'hfoo', 0, 0, 270 )
call DestroyImage( bj_lastCreatedImage )

ShowImage(GetLastCreatedImage(), false) doesn't works, like trying to change the position of the shadow.- :/
In order to Show/Hide the shadow you need to use SetImageColor.
JASS:
//Show the Shadow
call SetImageColor( UnitShadow , 255, 255, 255, 255 )
//Hide the Shadow
call SetImageColor( UnitShadow , 0, 0, 0, 0 )
 
Last edited:
Level 14
Joined
Apr 20, 2009
Messages
1,543
@Anvil:

Hmm then it seems Magtheridon96 was wrong on the function I showed.
Refference: http://www.hiveworkshop.com/forums/2083066-post43.html

The function is the same principle though, yours might refer to it more directly.
Magtheridon96's function not working might have something to do with referring to previously created handles (handle ID's messing up), but I suppose your approach is much better in this case.

Thanks a lot for testing that out, I didn't really have the time to go through it myself.

It's great to see how it works, thanks ;)
 
Status
Not open for further replies.
Top