• 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.

[JASS] Help with ability using GetLocalPlayer()

Status
Not open for further replies.
Level 10
Joined
Sep 29, 2006
Messages
447
Okay so I'm trying to make an ability called Optical Flare that stuns units in an area for 2 seconds and makes the screen white for the owner of those units for 2 seconds. The screen will then fade back in depending on the ability of the level. Right now my trigger doesn't work, and I know that GetLocalPlayer() can desync people so I need to know how to get this to work without desyncing everyone. Here's the trigger:

JASS:
function Trig_optical_flare_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A016'
endfunction

function is_organic takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false )
endfunction

function Fade takes nothing returns nothing
    if GetLocalPlayer() == GetOwningPlayer(GetEnumUnit()) then
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.50, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0 )
        call TriggerSleepAction( 2.00 )
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, ( 2.00 + I2R(GetUnitAbilityLevelSwapped('A016', GetTriggerUnit())) ), "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0 )
    endif
endfunction

function Trig_optical_flare_Actions takes nothing returns nothing
    local location TempPoint = GetSpellTargetLoc()
    local unit TempUnit
    local unit caster = GetTriggerUnit()
    local group TempGroup
    set TempUnit = CreateUnitAtLoc( GetOwningPlayer(caster), 'h005', TempPoint, 270.00 )
    call UnitAddAbility( TempUnit, 'A017' )
    call UnitApplyTimedLife( TempUnit, 'BTLF', 1.00 )
    call IssueImmediateOrder( TempUnit, "stomp" )
    set TempGroup = GetUnitsInRangeOfLocMatching(200.00, TempPoint, Condition(function is_organic))
    call ForGroup( TempGroup, function Fade )
    call RemoveLocation(TempPoint)
    call DestroyGroup(TempGroup)
    set TempUnit = null
    set caster = null
endfunction

//===========================================================================
function InitTrig_optical_flare takes nothing returns nothing
    set gg_trg_optical_flare = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_optical_flare, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddCondition( gg_trg_optical_flare, Condition( function Trig_optical_flare_Conditions ) )
    call TriggerAddAction( gg_trg_optical_flare, function Trig_optical_flare_Actions )
endfunction
 
Level 8
Joined
Aug 6, 2008
Messages
451
I dont know if that TriggerSleepAction desyncs. Either way, you should do as few actions inside GetLocalPlayer if/then/else as possible.

Do all function calls you can outside of GetLocalPlayer. Store that Triggering unit to local variable etc. Also replace that CinematicFadeBJ with some native function. CinematicFadeBJ might do something you dont really want to do, so at least use NewGens function list to check what it actually does.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
function Fade takes nothing returns nothing
if GetLocalPlayer() == GetOwningPlayer(GetEnumUnit()) then
call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.50, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0 )
call TriggerSleepAction( 2.00 )
call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, ( 2.00 + I2R(GetUnitAbilityLevelSwapped('A016', GetTriggerUnit())) ), "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0 )
endif
endfunction

I am quite sure this function you did will desync.
The explanations of that is, that CinematicFadeBJ is creating and destroying timers.
However, I found this, and it should work similar or even better than Blizzard's BJ function.

KaTTaNa said:
Displays a cinematic fade filter for the specified player.
JASS:
function CinematicFilterGenericForPlayer takes player whichPlayer, real duration, blendmode bmode, string tex, real red0, real green0, real blue0, real trans0, real red1, real green1, real blue1, real trans1 returns nothing
    if ( GetLocalPlayer() == whichPlayer ) then
        call SetCineFilterTexture(tex)
        call SetCineFilterBlendMode(bmode)
        call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
        call SetCineFilterStartUV(0, 0, 1, 1)
        call SetCineFilterEndUV(0, 0, 1, 1)
        call SetCineFilterStartColor(PercentTo255(red0), PercentTo255(green0), PercentTo255(blue0), PercentTo255(100-trans0))
        call SetCineFilterEndColor(PercentTo255(red1), PercentTo255(green1), PercentTo255(blue1), PercentTo255(100-trans1))
        call SetCineFilterDuration(duration)
        call DisplayCineFilter(true)
    endif
endfunction

So, based on his Cinematic filter we can adjust it slightly and use it (it was usable before as well):

JASS:
function CinematicFilterForPlayer takes player whichPlayer, real duration, string tex, real red0, real green0, real blue0, real trans0, real red1, real green1, real blue1, real trans1 returns nothing
    if ( GetLocalPlayer() == whichPlayer ) then
        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(red0), PercentTo255(green0), PercentTo255(blue0), PercentTo255(100-trans0))
        call SetCineFilterEndColor(PercentTo255(red1), PercentTo255(green1), PercentTo255(blue1), PercentTo255(100-trans1))
        call SetCineFilterDuration(duration)
        call DisplayCineFilter(true)
    endif
endfunction

function Fade takes nothing returns nothing
    local unit eu = GetEnumUnit()
    //0,0,0,100,0,0,0,0 means StartRed = 0, StartGreen = 0, StartBlue = 0, StartTransparancy = 100%, EndRed = 0, EndGreen = 0, EndBlue = 0, EndTransparancy = 0%
    call CinematicFilterForPlayer( GetOwningPlayer(eu), 0.5, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 100, 0, 0, 0, 0)
    //I am not sure that TSA works here, but I dont see any harm trying.
    call TriggerSleepAction(2.0)
    //0,0,0,0,0,0,0,100 means StartRed = 0, StartGreen = 0, StartBlue = 0, StartTransparancy = 0%, EndRed = 0, EndGreen = 0, EndBlue = 0, EndTransparancy = 100%
    call CinematicFilterForPlayer( GetOwningPlayer(eu), 2.00 + GetUnitAbilityLevel(eu, 'A016'), "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0, 0, 0, 0, 100)
    set eu = null
endfunction

I hope that helps. Tell me if it doesn't.
~Eccho~
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
That is weird indeed. I tried pasting it both in JassNewGenPack and in the standard World Editor, both seems to work and not crash the editor.

Please recheck again that you got every line, everything right, when you copied the functions. It should not happend :s

Also, make sure you didnt double post any function. The standard world editor crashes when it tries to compile wrong scripts sometimes.
 
Level 10
Joined
Sep 29, 2006
Messages
447
So would this be the correct trigger? This is what crashed my editor.


JASS:
function Trig_optical_flare_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A017'
endfunction

function CinematicFilterForPlayer takes player whichPlayer, real duration, string tex, real red0, real green0, real blue0, real trans0, real red1, real green1, real blue1, real trans1 returns nothing
    if ( GetLocalPlayer() == whichPlayer ) then
        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(red0), PercentTo255(green0), PercentTo255(blue0), PercentTo255(100-trans0))
        call SetCineFilterEndColor(PercentTo255(red1), PercentTo255(green1), PercentTo255(blue1), PercentTo255(100-trans1))
        call SetCineFilterDuration(duration)
        call DisplayCineFilter(true)
    endif
endfunction

function Fade takes nothing returns nothing
    local unit eu = GetEnumUnit()
    call CinematicFilterForPlayer( GetOwningPlayer(eu), 0.5, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 100, 0, 0, 0, 0)
    call TriggerSleepAction(2.0)
    call CinematicFilterForPlayer( GetOwningPlayer(eu), 2.00 + GetUnitAbilityLevel(eu, 'A016'), "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0, 0, 0, 0, 100)
    set eu = null
endfunction

function is_organic takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false )
endfunction

function Trig_optical_flare_Actions takes nothing returns nothing
    local location TempPoint = GetSpellTargetLoc()
    local unit TempUnit
    local unit caster = GetTriggerUnit()
    local group TempGroup
    set TempUnit = CreateUnitAtLoc( GetOwningPlayer(caster), 'h005', TempPoint, 270.00 )
    call UnitAddAbility( TempUnit, 'A016' )
    call UnitApplyTimedLife( TempUnit, 'BTLF', 1.00 )
    call IssueImmediateOrder( TempUnit, "stomp" )
    set TempGroup = GetUnitsInRangeOfLocMatching(200.00, TempPoint, Condition(function is_organic))
    call ForGroup( TempGroup, function Fade )
    call RemoveLocation(TempPoint)
    call DestroyGroup(TempGroup)
    set TempUnit = null
    set caster = null
    set TempPoint = null
    set TempGroup = null
endfunction

//===========================================================================
function InitTrig_optical_flare takes nothing returns nothing
    set gg_trg_optical_flare = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_optical_flare, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddCondition( gg_trg_optical_flare, Condition( function Trig_optical_flare_Conditions ) )
    call TriggerAddAction( gg_trg_optical_flare, function Trig_optical_flare_Actions )
endfunction
 
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
o_O Darn? It doesn't crash my editor at all.

Have you done it in the standard editor? I should work, I tried there too :s, the exact trigger.
In what way are the editor crashing?

Oh and a sidenote: you never null the TempPoint and the TempGroup in your trigger. Don't forget , it causes handle counter leaks .-.
 
Level 10
Joined
Sep 29, 2006
Messages
447
Im using the standard editor and when I try to enable the ability I get this error message:

Picture1-2.jpg


I edited the above post to what the trigger looks like now. What's the problem here?
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
What is function.execute? Once again, I apologize, my JASS skills are at a novice level.
function.execute is a vJass thing.
But one way you could do it is replace the ForGroup() with a loop that loops through the units in the group.
Like this:
JASS:
    set TempGroup = GetUnitsInRangeOfLocMatching(200.00, TempPoint, Condition(function is_organic))
    loop
        set u = FirstOfGroup(TempGroup)
        exitwhen u == null
        call GroupRemoveUnit(TempGroup, u)
        call CinematicFilterForPlayer( GetOwningPlayer(eu), 0.5, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 100, 0, 0, 0, 0)
        set u = null
    endloop
You must also use a timer that expires in 2 seconds so you can fade back.
 
Status
Not open for further replies.
Top