New to jassing

Zackreaver

New Member
Reaction score
2
Hello everyone, I just got the hang of making a trigger entirely with jass, and I made a trigger that works perfectly, no flaws what so ever.

But, I'm still new to using jass, so I want to make a quick check, is there anything wrong or rather is there anything I could do better in the following pieces of code?

Code:
function Trig_Volcano_Occupy_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h005' ) ) then
        return false
    endif
    if ( not ( GetUnitTypeId(GetTransportUnitBJ()) == 'h007' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Volcano_Occupy_Actions takes nothing returns nothing
    local unit vguard = GetTriggerUnit()
    local unit volcano = GetTransportUnitBJ()
    local integer count = udg_VolcanoGuardCounter
    local group vgroup = udg_VolcanoGuardLaunchGroup
    
    
    call SetUnitUserData(vguard, count)
    call SetUnitUserData(volcano, count)
    call GroupAddUnitSimple(vguard, vgroup)

    set udg_VolcanoGuardCounter = udg_VolcanoGuardCounter + 1
    set vguard = null
    set volcano = null


endfunction

//===========================================================================
function InitTrig_Volcano_Occupy takes nothing returns nothing
    set gg_trg_Volcano_Occupy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Volcano_Occupy, EVENT_PLAYER_UNIT_LOADED )
    call TriggerAddCondition( gg_trg_Volcano_Occupy, Condition( function Trig_Volcano_Occupy_Conditions ) )
    call TriggerAddAction( gg_trg_Volcano_Occupy, function Trig_Volcano_Occupy_Actions )
endfunction

Code:
function Trig_Volcano_Guard_Launch_2_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A005' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Volcano_Guard_Launch_2_Func001C takes nothing returns boolean
    return true
endfunction

function VolcanoGuardGroup takes nothing returns nothing
      local unit pickedguard
      local unit volcano = GetTriggerUnit()

      set pickedguard = GetEnumUnit()
      if (GetUnitUserData(volcano) == GetUnitUserData(pickedguard)) then
          set udg_TempUnit = pickedguard
      else
      endif

      set pickedguard = null
      set volcano = null

endfunction


function Trig_Volcano_Guard_Launch_2_Actions takes nothing returns nothing

    local group vgroup = udg_VolcanoGuardLaunchGroup
    local unit volcano = GetTriggerUnit()
    set udg_TempUnit = null
    if ( Trig_Volcano_Guard_Launch_2_Func001C() ) then

        call ForGroupBJ( vgroup, function VolcanoGuardGroup )


        if ( IsUnitInTransportBJ(udg_TempUnit, volcano) == true ) then

            if (not (udg_TempUnit == null)) then 

                call RemoveUnit(udg_TempUnit)
                call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(GetTriggerPlayer()) + " is launching a Volcano Guard." ) )
                call PlaySoundBJ( gg_snd_GoodJob )
            else
                call IssueImmediateOrderBJ( GetTriggerUnit(), "stop" )
                call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), "TRIGSTR_1268" )
                call PolledWait( 0.01 )
                call SetUnitManaBJ( GetTriggerUnit(), 100.00 )
            endif
        else
            call IssueImmediateOrderBJ( GetTriggerUnit(), "stop" )
            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), "TRIGSTR_1268" )
            call PolledWait( 0.01 )
            call SetUnitManaBJ( GetTriggerUnit(), 100.00 )
        endif
    else
    endif

    set udg_TempUnit = null

endfunction





//===========================================================================
function InitTrig_Volcano_Guard_Launch_2 takes nothing returns nothing
    set gg_trg_Volcano_Guard_Launch_2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Volcano_Guard_Launch_2, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Volcano_Guard_Launch_2, Condition( function Trig_Volcano_Guard_Launch_2_Conditions ) )
    call TriggerAddAction( gg_trg_Volcano_Guard_Launch_2, function Trig_Volcano_Guard_Launch_2_Actions )
endfunction

What the code does, is it check's to see if theres a "Volcano Guard" in a Volcano when the ability eruption is used, if there isnt, it stops the spell, gives an error message, and gives back the mana. If there is a volcano guard garrisoned, it gets removed, and the Eruption spell, made from inferno, launches the volcano guard where the spell was cast.

I'm still catching on to alot of this, so I'm not sure if anything im doing in there is either inefficient/slower/difficult than what I could be doing.

Thank you

ps. also HiveWorkshop is down so I cant get that program JassCraft, which I hear would be really helpful >.<, anyone know any external links for that program?
 

substance

New Member
Reaction score
34
JassCraft.

I would also suggest you get the NewGenPack (i dont have a link,wc3c is still down) and try to stay away from BJ functions. Also, stuff like this
JASS:
function Trig_Volcano_Guard_Launch_2_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == &#039;A005&#039; ) ) then
        return false
    endif
    return true
endfunction
can just be
JASS:
function Trig_Volcano_Guard_Launch_2_Conditions takes nothing returns boolean
return GetSpellAbilityId() == &#039;A005&#039;
endfunction
 

elmstfreddie

The Finglonger
Reaction score
203
Also you set locals to a global... Why not getting rid of the globals in the first place and just using locals o_O
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
Here's what I would change:
  • call GroupAddUnitSimple(vguard, vgroup) should be GroupAddUnit(vgroup, vguard)
    [*]EVENT_PLAYER_UNIT_SPELL_CAST should be EVENT_PLAYER_UNIT_SPELL_EFFECT
    [*]What substance said about the return true/false stuff for conditions
    [*]Why does this exist if the function just returns true?: if ( Trig_Volcano_Guard_Launch_2_Func001C() ) then
    [*]call ForGroupBJ( vgroup, function VolcanoGuardGroup ) can be replaced with a handy-dandy workaround. The format of the workaround goes as so:
    JASS:
    loop
        set u = FirstOfGroup(g) //&quot;u&quot; being a unit variable and &quot;g&quot; being the group to loop through
        exitwhen u == null
        //Do stuff with &quot;u&quot; as you normally would
        call GroupRemoveUnit(g, u)
    endloop

    So in your case, it would look like this (it also removes the need for the global TempUnit variable):
    JASS:
    local unit pickedguard
    local unit TempUnit
    //...
    loop
        set pickedguard = FirstOfGroup(vgroup) //&quot;u&quot; being a unit variable and &quot;g&quot; being the group to loop through
        exitwhen u == null
        if (GetUnitUserData(volcano) == GetUnitUserData(pickedguard)) then
            set TempUnit = pickedguard
        //Notice how there&#039;s no &quot;else&quot; line here; it&#039;s not needed unless you have &quot;else&quot; actions to do
        endif
        call GroupRemoveUnit(vgroup, pickedunit)
    endloop

    [*]IsUnitInTransportBJ(...) should be IsUnitInTransportBJ(...)
    [*]if (not (udg_TempUnit == null)) then should be if TempUnit != null then. The "!=" operator means "does not equal" or "not equal to".
    [*]If you really wanted to, you could replace call PlaySoundBJ( gg_snd_GoodJob ) with the appropriate natives, but sounds really are not fun to do without them.
    [*]call SetUnitManaBJ( GetTriggerUnit(), 100.00 ) should be call SetUnitManaBJ( volcano, 100.00 ), since you've already set GetTriggerUnit() equal to a variable.
    [*]Remove the "BJ" in call IssueImmediateOrderBJ( GetTriggerUnit(), "stop" ).
    [*]call SetUnitManaBJ( GetTriggerUnit(), 100.00 ) should be call SetUnitState(volcano, UNIT_STATE_MANA, 100.00)
    [*]This entire thing (with corrections, obviously):
    JASS:
            if ( IsUnitInTransportBJ(udg_TempUnit, volcano) == true ) then
    
                if (not (udg_TempUnit == null)) then 
    
                    call RemoveUnit(udg_TempUnit)
                    call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(GetTriggerPlayer()) + &quot; is launching a Volcano Guard.&quot; ) )
                    call PlaySoundBJ( gg_snd_GoodJob )
                else
                    call IssueImmediateOrderBJ( GetTriggerUnit(), &quot;stop&quot; )
                    call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), &quot;TRIGSTR_1268&quot; )
                    call PolledWait( 0.01 )
                    call SetUnitManaBJ( GetTriggerUnit(), 100.00 )
                endif
            else
                call IssueImmediateOrderBJ( GetTriggerUnit(), &quot;stop&quot; )
                call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), &quot;TRIGSTR_1268&quot; )
                call PolledWait( 0.01 )
                call SetUnitManaBJ( GetTriggerUnit(), 100.00 )
            endif

    Could be changed to this, which uses an "and" comparison in the if statement.
    JASS:
    if ( IsUnitInTransportBJ(udg_TempUnit, volcano) == true and TempUnit != null ) then
         call RemoveUnit(udg_TempUnit)
         call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(GetTriggerPlayer()) + &quot; is launching a Volcano Guard.&quot; ) )
         call PlaySoundBJ( gg_snd_GoodJob )
    else
         call IssueImmediateOrderBJ( GetTriggerUnit(), &quot;stop&quot; )
         call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), &quot;TRIGSTR_1268&quot; )
         call PolledWait( 0.01 )
         call SetUnitManaBJ( GetTriggerUnit(), 100.00 )
    endif

    [*]Any "== true"s can be removed.
    [*]Your code could use some more standard formatting and better function names.


That's 'bout it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top