Local fade filter?

Parsival

Active Member
Reaction score
6
Hi there,

I think I'm not the first one who needs this feature.

I need to create fade filter for one player.
I found this stuff:
Variables:
cineFadeFinishTimer --> timer array with size 11, preset value new timer
cineFadeContinueTimer --> timer array with size 11, preset value new timer
cineFadeContinueRed --> real array
cineFadeContinueGreen --> real array
cineFadeContinueBlue --> real array
cineFadeContinueTrans --> real array
cineFadeContinueDuration --> real array
cineFadeContinueTex --> string array

JASS:
function CinematicFadeCommonForPlayer takes player p, real red, real green, real blue, real duration, string tex, real startTrans, real endTrans returns nothing
    if (duration == 0) then
        set startTrans = endTrans
    endif
    if (GetLocalPlayer() == p) then
        call EnableUserUI(false)
        call SetCineFilterTexture(tex)
        call SetCineFilterBlendMode(BLEND_MODE_BLEND)
        call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
        call SetCineFilterStartUV(0, 0, 1, 1)
        call SetCineFilterEndUV(0, 0, 1, 1)
        call SetCineFilterStartColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-startTrans))
        call SetCineFilterEndColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-endTrans))
        call SetCineFilterDuration(duration)
        call DisplayCineFilter(true)
    endif
endfunction

function FinishCinematicFadeForPlayer takes nothing returns nothing
    local integer playerid
    local integer index = 0
    loop
        exitwhen index > 11
        if (GetExpiredTimer() == udg_cineFadeFinishTimer[index]) then
            set playerid = index
        endif
        set index = index + 1
    endloop
    call DestroyTimer(udg_cineFadeFinishTimer[playerid])
    set udg_cineFadeFinishTimer[playerid] = null
    if (GetPlayerId(GetLocalPlayer()) == playerid) then
        call DisplayCineFilter(false)
        call EnableUserUI(true)
    endif
endfunction

function FinishCinematicFadeAfterForPlayer takes integer playerid, real duration returns nothing
    set udg_cineFadeFinishTimer[playerid] = CreateTimer()
    call TimerStart(udg_cineFadeFinishTimer[playerid], duration, false, function FinishCinematicFadeForPlayer)
endfunction

function ContinueCinematicFadeForPlayer takes nothing returns nothing
    local integer playerid
    local integer index = 0
    loop
        exitwhen index > 11
        if (GetExpiredTimer() == udg_cineFadeContinueTimer[index]) then
            set playerid = index
        endif
        set index = index + 1
    endloop
    call DestroyTimer(udg_cineFadeContinueTimer[playerid])
    set udg_cineFadeContinueTimer[playerid] = null
    call CinematicFadeCommonForPlayer(Player(playerid), udg_cineFadeContinueRed[playerid], udg_cineFadeContinueGreen[playerid], udg_cineFadeContinueBlue[playerid], udg_cineFadeContinueDuration[playerid], udg_cineFadeContinueTex[playerid], udg_cineFadeContinueTrans[playerid], 100)
endfunction

function ContinueCinematicFadeAfterForPlayer takes integer playerid, real duration, real red, real green, real blue, real trans, string tex returns nothing
    set udg_cineFadeContinueRed[playerid] = red
    set udg_cineFadeContinueGreen[playerid] = green
    set udg_cineFadeContinueBlue[playerid] = blue
    set udg_cineFadeContinueTrans[playerid] = trans
    set udg_cineFadeContinueDuration[playerid] = duration
    set udg_cineFadeContinueTex[playerid] = tex
    set udg_cineFadeContinueTimer[playerid] = CreateTimer()
    call TimerStart(udg_cineFadeContinueTimer[playerid], duration, false, function ContinueCinematicFadeForPlayer)
endfunction

function AbortCinematicFadeForPlayer takes integer playerid returns nothing
    if (udg_cineFadeContinueTimer[playerid] != null) then
        call DestroyTimer(udg_cineFadeContinueTimer[playerid])
    endif
    if (udg_cineFadeFinishTimer[playerid] != null) then
        call DestroyTimer(udg_cineFadeFinishTimer[playerid])
    endif
endfunction

function CinematicFadeForPlayer takes player p, integer fadetype, real duration, string tex, real red, real green, real blue, real trans returns nothing
    local integer playerid = GetPlayerId(p)
    if (fadetype == bj_CINEFADETYPE_FADEOUT) then
        call AbortCinematicFadeForPlayer(playerid)
        call CinematicFadeCommonForPlayer(p, red, green, blue, duration, tex, 100, trans)
    elseif (fadetype == bj_CINEFADETYPE_FADEIN) then
        call AbortCinematicFadeForPlayer(playerid)
        call CinematicFadeCommonForPlayer(p, red, green, blue, duration, tex, trans, 100)
        call FinishCinematicFadeAfterForPlayer(playerid, duration)
    elseif (fadetype == bj_CINEFADETYPE_FADEOUTIN) then
        if (duration > 0) then
            call AbortCinematicFadeForPlayer(playerid)
            call CinematicFadeCommonForPlayer(p, red, green, blue, duration * 0.5, tex, 100, trans)
            call ContinueCinematicFadeAfterForPlayer(playerid, duration * 0.5, red, green, blue, trans, tex)
            call FinishCinematicFadeAfterForPlayer(playerid, duration)
        endif
    endif
endfunction


Call the lowest function if you want to use this.

Should it work properly?
What do You use when You need fade filter for specific player?


Thanks in advance and sorry for my poor English :)
 

UndeadDragon

Super Moderator
Reaction score
447
It should work. Whenever I used to need them, I would use:

Trigger:
  • Actions:
    • Custom Script: if (GetLocalPlayer() == playerNum) then
    • Cinematic: Whatever fade filter stuff - I don&#039;t even know if its cinematic anymore <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue :p" loading="lazy" data-shortname=":p" />
    • Custom Script: endif
 

Whisky

New Member
Reaction score
45
It would cause desync I think.

Why would it? The rule of thumb is to not alter/create handles with GetLocalPlayer, most of the other stuff works fine.

Besides, the trigger you posted uses practically the same method as UndeadDragon's one.
 

Parsival

Active Member
Reaction score
6
Huh, I was sure it will cause desync.

I'm not able to test it now. Anyway, thanks and expect +rep sometime. :)
 

WaterKnight

Member
Reaction score
7
Why would it? The rule of thumb is to not alter/create handles with GetLocalPlayer, most of the other stuff works fine.

The BJ-functions used in GUI do alter it. Desyncing the native filter functions is fine as you see in CinematicFadeCommonForPlayer but in the other functions it creates, destroys and starts timers. You can decide whether you need them. This was just designed to mimic the GUI's Video - Fade Filter action for one player, including the timer framework.
 

Parsival

Active Member
Reaction score
6
Huh. Welcome, WaterKnight. :)

So should I use Your script instead? Is it up to date and works fine?
 

WaterKnight

Member
Reaction score
7
You can use it. It works as intented, not new and could be written in other ways but plain jass that is still compatible. The question is what you exactly need. This was meant to deactivate the filter after a time again and avoid overlappings, the new one gets immediately rid of the last. It also disables the user ui like the normal GUI action has done.

But you could also take a more native approach.

Trigger:
  • Actions
    • Custom script: if (GetLocalPlayer() == yourPlayer) then
      • Custom script: call SetCineFilterTexture(tex)
      • Custom script: call SetCineFilterBlendMode(BLEND_MODE_BLEND)
      • Custom script: call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
      • Custom script: call SetCineFilterStartUV(0, 0, 1, 1)
      • Custom script: call SetCineFilterEndUV(0, 0, 1, 1)
      • Custom script: call SetCineFilterStartColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-startTrans))
      • Custom script: call SetCineFilterEndColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-endTrans))
      • Custom script: call SetCineFilterDuration(duration)
      • Custom script: call DisplayCineFilter(true)
      • Custom script: if (IsCineFilterDisplayed()) then
        • Custom script: call BJDebugMsg(&quot;hooray&quot;)
      • Custom script: endif
    • Custom script: endif


These are all the filter natives there are and you can play with these functions, they can all be desynced.
 

Parsival

Active Member
Reaction score
6
Hi :)

I'm new to JASS. I have a problem with running this function.

I just created a new trigger, converted it to text, pasted Your script (from 1st post) and then I created a few GUI "Custom script" functions in other trigger.
I've got compile errors. Expecting "endif" and "expecting name of function".

Trigger:
  • Actions
    • Custom script: local player NAME = GetTriggerPlayer()
    • Custom script: call CinematicFadeForPlayer(NAME, bj_CINEFADETYPE_FADEOUT, 2., &quot;ReplaceableTextures\\CameraMasks\\White_mask.blp&quot;, 0., 0., 0., 0.)
    • Custom script: set NAME = null

It tells me to put "endif" in place of "local player NAME = GetTriggerPlayer()", so I just created a new variable in Variable Editor and wrote this:
Trigger:
  • Actions
    • Custom script: set udg_NAME = GetTriggerPlayer()
    • Custom script: call CinematicFadeForPlayer(udg_NAME, bj_CINEFADETYPE_FADEOUT, 2., &quot;ReplaceableTextures\\CameraMasks\\White_mask.blp&quot;, 0., 0., 0., 0.)
    • Custom script: set udg_NAME = null

But it still expects the name of function in this line:
Trigger:
  • Actions
    • Custom script: call CinematicFadeForPlayer(udg_NAME, bj_CINEFADETYPE_FADEOUT, 2., &quot;ReplaceableTextures\\CameraMasks\\White_mask.blp&quot;, 0., 0., 0., 0.)

It looks like it doesn't see a definition of those all functions.

What's wrong? I know it has to be very easy. I'm just new to JASS.

Thanks.

EDIT//
Ok, I managed :p

Local variables have to be declared before any other actions.
Global functions must be defined in a Custom Script Section.

Works on single player.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top