• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help with this trigger

Status
Not open for further replies.
Level 3
Joined
Sep 9, 2009
Messages
658
I made this trigger where if a unit enters a region, he gets healed to max health. The trigger checks if it's an allied unit and if it's current hp is lower than the max hp before the unit gets healed.

The problem is that he doesn't get healed. EVerything else works but he doesn't get healed.

JASS:
scope Heal initializer Init
    globals
        private constant string sfx = "Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl"
        private constant string a = "origin"
    endglobals
    
    private function Heal_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        
        call SetUnitAnimation( udg_AmalThazad, "spell" )
        call DestroyEffect(AddSpecialEffectTarget(sfx, u, a))
        call ForceCinematicSubtitles( true )
        call TransmissionFromUnitWithNameBJ( GetPlayersAll(), udg_AmalThazad, "TRIGSTR_050", null, "TRIGSTR_051", bj_TIMETYPE_ADD, 0, true )
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE))
        call SetUnitAnimation( udg_AmalThazad, "stand" )
        
        set u = null
    endfunction
    
    private function Heal_Conditions takes nothing returns boolean
        if not IsUnitEnemy(GetTriggerUnit(), Player(0)) and GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE) < GetUnitState(GetTriggerUnit(), UNIT_STATE_MAX_LIFE) then
            call Heal_Actions()
        endif
        return false
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( t, gg_rct_AmalThazad )
        call TriggerAddCondition(t, Condition(function Heal_Conditions))
        set t = null
    endfunction
endscope
 
Level 11
Joined
Dec 19, 2012
Messages
411
Next time if you want people help in fixing your trigger, please post in Triggers & Scripts forum

call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE)) where is your heal amount of value?

Also run all your actions inside condition block

And also, avoids BJs functions.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The heal amount is there.
Set unit current life to Max life of unit.

Put this just before the heal
"call DisplayTextToForce(GetPlayersAll(), "checkpoint 1")"
and this just after
"call DisplayTextToForce(GetPlayersAll(), "checkpoint 2")"

Post response.
 
Level 3
Joined
Sep 9, 2009
Messages
658
Next time if you want people help in fixing your trigger, please post in Triggers & Scripts forum

call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE)) where is your heal amount of value?

Also run all your actions inside condition block

And also, avoids BJs functions.

Wouldn't UNIT_STATE_MAX_LIFE be the real value? If not, how do I do it?

Yeah...I ran it in the conditions block initially but the this problem came up so I tried separating it in an attempt to fix it. I'll get to it after I get it to heal.

I think the BJs fine as it is, imo. Unless you're saying it's inefficient? But let's focus first on how to get it to heal. What do you mean value?

The heal amount is there.
Set unit current life to Max life of unit.

How do you do that? What do you mean it's there btw.
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
I thought so.
The set life of unit stuff was not wrong. Instead it would work perfectly but it never runs.
To find out where it stops running you put one checkpoint between each and every line of your code.
And one at the beginning and one at the end.
JASS:
private function Heal_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 1")
        call SetUnitAnimation( udg_AmalThazad, "spell" )
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 2")
        call DestroyEffect(AddSpecialEffectTarget(sfx, u, a))
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 3")
        call ForceCinematicSubtitles( true )
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 4")
        call TransmissionFromUnitWithNameBJ( GetPlayersAll(), udg_AmalThazad, "TRIGSTR_050", null, "TRIGSTR_051", bj_TIMETYPE_ADD, 0, true )
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 5")
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE))
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 6")
        call SetUnitAnimation( udg_AmalThazad, "stand" )
        call DisplayTextToForce(GetPlayersAll(), "Checkpoint 7")
        
        set u = null
    endfunction
Then post the latest checkpoint.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Because of this:

JASS:
function TransmissionFromUnitWithNameBJ takes force toForce, unit whichUnit, string unitName, sound soundHandle, string message, integer timeType, real timeVal, boolean wait returns nothing
    call TryInitCinematicBehaviorBJ()

    // Ensure that the time value is non-negative.
    set timeVal = RMaxBJ(timeVal, 0)

    set bj_lastTransmissionDuration = GetTransmissionDuration(soundHandle, timeType, timeVal)
    set bj_lastPlayedSound = soundHandle

    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        if (whichUnit == null) then
            // If the unit reference is invalid, send the transmission from the center of the map with no portrait.
            call DoTransmissionBasicsXYBJ(0, PLAYER_COLOR_RED, 0, 0, soundHandle, unitName, message, bj_lastTransmissionDuration)
        else
            call DoTransmissionBasicsXYBJ(GetUnitTypeId(whichUnit), GetPlayerColor(GetOwningPlayer(whichUnit)), GetUnitX(whichUnit), GetUnitY(whichUnit), soundHandle, unitName, message, bj_lastTransmissionDuration)
            if (not IsUnitHidden(whichUnit)) then
                call UnitAddIndicator(whichUnit, bj_TRANSMISSION_IND_RED, bj_TRANSMISSION_IND_BLUE, bj_TRANSMISSION_IND_GREEN, bj_TRANSMISSION_IND_ALPHA)
            endif
        endif
    endif

    if wait and (bj_lastTransmissionDuration > 0) then
        // call TriggerSleepAction(bj_lastTransmissionDuration)
        @call WaitTransmissionDuration(soundHandle, timeType, timeVal)@
    endif

endfunction

JASS:
function WaitTransmissionDuration takes sound soundHandle, integer timeType, real timeVal returns nothing
    if (timeType == bj_TIMETYPE_SET) then
        // If we have a static duration wait, just perform the wait.
        @call TriggerSleepAction(timeVal)@

    elseif (soundHandle == null) then
        // If the sound does not exist, perform a default length wait.
        @call TriggerSleepAction(bj_NOTHING_SOUND_DURATION)@

    elseif (timeType == bj_TIMETYPE_SUB) then
        // If the transmission is cutting off the sound, wait for the sound
        // to be mostly finished.
        call WaitForSoundBJ(soundHandle, timeVal)

    elseif (timeType == bj_TIMETYPE_ADD) then
        // If the transmission is extending beyond the sound's length, wait
        // for it to finish, and then wait the additional time.
        call WaitForSoundBJ(soundHandle, 0)
        @call TriggerSleepAction(timeVal)@

    else
        // Unrecognized timeType - ignore.
    endif
endfunction

Sleeps halts a triggercondition's execution. You could:
a. Not use TransmissionFromUnitWithNameBJ
b. Use a triggeraction
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
call TransmissionFromUnitWithNameBJ( GetPlayersAll(), udg_AmalThazad, "TRIGSTR_050", null, "TRIGSTR_051", bj_TIMETYPE_ADD, 0, true )
Causes an error, either it has a null value given and cannot continue any more or it has infinite loops. Or anything else.

I actually never used this specific method before and even have never seen it.
You do use the trigger editor longer than me I can tell you that.

There are 4 possible null-pointer-exceptions in this function with those parameters/arguments:
- unit udg_AmalThazad
- string "TRIGSTR_050"
- sound null
- string "TRIGSTR_051"

Between the Transmission function and the checkpoint 4 add these codelines:
call DisplayTextToForce(GetPlayersAll(), GetUnitName(udg_AmalThazad))
call DisplayTextToForce(GetPlayersAll(), "TRIGSTR_051")

Also change the "TRIGSTR_050" to GetUnitName(udg_AmalThazad) as this is the name of the unit.

Try to run the same code but then with a sound.
If that will fix the problem (which I assume) you can create a dummy/blank sound and import it.

I think you have to create a file with notepad (empty) and save it as blank.wav
Then import it and use that one instead of null.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Try using a triggeraction first, it wouldn't hurt to try.

JASS:
scope Heal initializer Init
    globals
        private constant string sfx = "Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl"
        private constant string a = "origin"
    endglobals
   
    private function Heal_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
       
        call SetUnitAnimation( udg_AmalThazad, "spell" )
        call DestroyEffect(AddSpecialEffectTarget(sfx, u, a))
        call ForceCinematicSubtitles( true )
        call TransmissionFromUnitWithNameBJ( GetPlayersAll(), udg_AmalThazad, "TRIGSTR_050", null, "TRIGSTR_051", bj_TIMETYPE_ADD, 0, true )
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE))
        call SetUnitAnimation( udg_AmalThazad, "stand" )
       
        set u = null
    endfunction
   
    private function Heal_Conditions takes nothing returns boolean
        return not IsUnitEnemy(GetTriggerUnit(), Player(0)) and GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE) < GetUnitState(GetTriggerUnit(), UNIT_STATE_MAX_LIFE) then
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( t, gg_rct_AmalThazad )
        call TriggerAddCondition(t, Condition(function Heal_Conditions))
        call TriggerAddAction(t, function Heal_Actions)
        set t = null
    endfunction
endscope
 
Level 3
Joined
Sep 9, 2009
Messages
658
Here's the map. Hope the size is okay.

Can you also give some comments on the citadel?

edit: It's sorta fixed now. I replaced it with
call SetCinematicScene(GetUnitTypeId(udg_AmalThazad), GetPlayerColor(GetOwningPlayer(udg_AmalThazad)), "TRIGSTR_50", "TRIGSTR_51", 5, 0)

I may be forgetting some of the checks the BJfunction does but oh well. The unit's invulnerable from the start anyway. So I doubt he's going to die.

EDIT: I found that adding any kind of wait makes the next actions stop. Wonder what's wrong with it =.=
 

Attachments

  • Frozen Throne.w3x
    5.7 MB · Views: 64
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
As chobibo said, conditions (which you use for efficiency) stop running when they get a wait timer.

Shame on me though.
My version of vJASS is not high enough to compile the map XD
I was so relieved that I actually had newgen installed after 12 attempts but I got an earlier version.
I never use vJASS though. Everything vJASS can do can also be done in plain JASS which every player can compile.

As for the terrain feedback: In this case, the Blizzard cliffs kill your map.
There are some nice tutorials about custom cliffs here on the hive and you should definately take a look at it and what it can do.
 
Level 3
Joined
Sep 9, 2009
Messages
658
The I'll try putting it in an actions block again. But the problem was still there even when I used TriggerAddAction before.

Btw I only use vJass for the private functions and globals block.

EDIT: Adding the actions block works now! Thanks!!

Last question...how do I extract the code Victory/Defeat conditions? I want to edit it so I can predefine my custom Town Halls.
 
Last edited:
Status
Not open for further replies.
Top