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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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