• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Unit Fading Effect

Status
Not open for further replies.
Level 9
Joined
Nov 17, 2004
Messages
277
Hi. In my map I have units that can cloak. I've used a dummy spell to cause a trigger to add permanent invisibilty to them, and can be cast again to remove it. That all works fine. What I was wondering was if someone could write a custom script so that when the invisibility is removed, their transparency is set to 95%, then to 0% over about 1.5 seconds. Is this possible? I'm trying to make an inverse effect to when the invisibility is added and they appear to fade to the enemy: I'd like them to fade back in. I tried doing this with unit groups but had no luck.
Basically, the cloaked unit casts the spell, the permament invis is removed, * , it is removed from the unit group. I would like a script to put where the * is. The unit is set to the variable "Casting_Unit" if thats any help. Thanks.
 
i do not exactly get what you want.. just fading a unit in over time?
then this would help

JASS:
function FadeIn takes real time , unit u returns nothing
local integer i = 1
local integer ii = 8
    loop
        exitwhen i>ii
        call SetUnitVertexColor(u,255,255,255,(255-(32*q)))  
        call TriggerSleepAction(time/8)
        set i = i + 1
    endloop
endfunction

the function to call
JASS:
call FadeIn.execute(1.50,CasterUnit)

(btw , uses vJass , youll need JassNewGenPack)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
-JonNny, TSA should be avoided at all costs.

Here we go, vJass required. Haven't tested but it should work, I'll test after dinner --

JASS:
library FadeIn
    private struct Data
        unit fade
        real alpha = 0
        real alphaPerInterval
    endstruct
    globals
        private constant real interval = .03
        private timer T = CreateTimer()
        private integer max = 0
        private Data array darr
    endglobals
    private function Loop takes nothing returns nothing
        local integer i = 0
        local Data dat
        loop
            exitwhen i >= max
            set dat = darr[i]
            set dat.alpha = dat.alpha + dat.alphaPerInterval
            if dat.alpha > 255. then
                set dat.alpha = 255.
            endif
            call SetUnitVertexColor(dat.fade,255,255,255,R2I(dat.alpha))
            if dat.alpha == 255. then
                set max = max - 1
                set darr[i] = darr[max]
                if max == 0 then
                    call PauseTimer(T)
                endif
                call dat.destroy()
            else
                set i = i + 1
            endif
        endloop
    endfunction
    function FadeInUnit takes unit u, real time returns nothing
        local Data dat = Data.create()
        set dat.fade = u
        set dat.alphaPerInterval = 255.*interval/time
        if max == 0 then
            call TimerStart(T,interval,true,function Loop)
        endif
        set darr[max] = dat
        set max = max + 1
    endfunction
endlibrary
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
JassNewGenPack

Note that it only works on the 1.21b worldedit.exe, which is available for download in a number of places.

To use this, just put it in a trigger of whatever name you like (overwrite the entire contents). Then write (replacing words in <>):

  • Some Trigger
    • Actions
      • Custom script: call FadeInUnit(<unit variable>,<time>)
-JonNny, TSA = Trigger Sleep Action, and among other things it's rather horribly inaccurate, hence timers.

EDIT: Minor changes to my code to make the timing a little more accurate.
 
Last edited:
Level 5
Joined
Oct 17, 2006
Messages
151
If you don't jass, the GUI version would be this:
  • Fade Away
    • Actions
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 95.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 85.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 75.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 65.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 55.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 45.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 35.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 25.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 15.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 5.00% transparency
      • Wait 0.15 seconds
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 0.00% transparency
GUI FTW!!!

Although its probably not as slick as PurplePoot, its GUI... :grin:
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
You can make the transparency in function of the loop index. Like:

  • Trigger
  • For Each Integer A from 0 to 9 do:
    • Loop - actions
      • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with (95.00 - (10*Integer A)%) transparency
      • Wait 0.15 seconds
  • Animation - Change (Triggering unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 0% transparency
 
Status
Not open for further replies.
Top