Easy for you, impossible for me

warden13

New Member
Reaction score
32
I am Jassing for two days. That makes me a big noob in Jass. So I coded a spell, that creates units as a line and adds them to a unit group. This is ok.
But I want to do this:
If a unit in unit group dies, kill all units in unit group. And clean the leaks and memory. Thanks...

JASS:
function Trig_ET_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function filtre takes nothing returns boolean
    return ( GetDestructableTypeId(GetFilterDestructable()) == 'ATtr' )
endfunction

function Trig_ET_Actions takes nothing returns nothing
    local unit u
    local player p
    local group g = CreateGroup()
    local destructable t1
    local destructable t2
    local location loc0
    local location loc1
    local location loc2
    local real x
    local real y
    local real dis
    local integer mc
    local integer count
    local rect area
    local unit m
set count = 0
set u = GetSpellAbilityUnit()
set p = GetOwningPlayer(u)
set t1 = GetSpellTargetDestructable()
set loc0 = GetUnitLoc(u)
set area = RectFromCenterSizeBJ(loc0, 300.00, 300.00)
set t2 = RandomDestructableInRectBJ(area, Condition(function filtre))
set loc1 = GetDestructableLoc(t1)
set loc2 = GetDestructableLoc(t2)
set x = GetDestructableX(t2)
set y = GetDestructableY(t2)
set dis = DistanceBetweenPoints(loc1, loc2)
set mc = R2I(dis/30)
set abp = bj_RADTODEG * Atan2(GetLocationY(loc1) - GetLocationY(loc2), GetLocationX(loc1) - GetLocationX(loc2))


loop
    exitwhen count > mc
    set x = x + 30 * Cos(abp * bj_DEGTORAD)
    set y = y + 30 * Sin(abp * bj_DEGTORAD)
    set m = CreateUnit(p, 'n001', x, y, 0)
    call GroupAddUnit(g, m)
    set count = count + 1
endloop
endfunction

function InitTrig_ET takes nothing returns nothing
    set gg_trg_ET = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ET, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_ET, Condition( function Trig_ET_Conditions ) )
    call TriggerAddAction( gg_trg_ET, function Trig_ET_Actions )
endfunction
 

Exide

I am amazingly focused right now!
Reaction score
448
JASS:

set abp = bj_RADTODEG * Atan2(GetLocationY(loc1) - GetLocationY(loc2), GetLocationX(loc1) - GetLocationX(loc2))


-You don't have a local variable named abp.

>If a unit in unit group dies, kill all units in unit group. And clean the leaks and memory.
You should have another trigger checking if *unit* dies, then do ...
 

Exide

I am amazingly focused right now!
Reaction score
448
-local real abp fixed.

-But my group (g) will get removed outside of trigger. Right?

Yes, you will need a global variable.
 

warden13

New Member
Reaction score
32
Can you code it for me? I don't know how to use globals. So I will learn how to use them as well.
 

Exide

I am amazingly focused right now!
Reaction score
448
Global variables are "GUI variables", also known as User Defined Globals (udg).
For example
Trigger:
  • custom script call RemoveLocation(udg_temppoint)


Just change your local variable into a global one. Go into Trigger Editor, click on the Variables Editor (X icon), create a new 'unit group - variable', name it something like 'DeathGroup' or whatever.
Then change this line in your JASS code:

JASS:

    call GroupAddUnit(g, m)


into:

JASS:

    call GroupAddUnit(udg_DeathGroup, m)


Now all units that this trigger creates will be added into that group, and you can do whatever you want with them, in another trigger (for example killing them.)



EDIT: I tried to optimize your trigger a little. (Getting rid of most of the BJ's, and point variables, using coordinates instead.) Try using this trigger:

JASS:

function Trig_ET_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function filter_func takes nothing returns boolean
    return (GetDestructableTypeId(GetFilterDestructable()) == 'ATtr')
endfunction

function Trig_ET_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local player p = GetOwningPlayer(u)
    local group g = CreateGroup()
    local destructable t1 = GetSpellTargetDestructable()
    local destructable t2
    local real array x
    local real array y
    local real dis
    local integer mc
    local integer i = 0
    local rect area
    local unit m
    local real abp


    set x[1] = GetUnitX(u)
    set y[1] = GetUnitY(u)

    set area = Rect(x[1] - 300*0.5, y[1] - 300*0.5, x[1] + 300*0.5, y[1] + 300*0.5)
    set t2 = RandomDestructableInRectBJ(area, Condition(function filter_func))
    
    set x[2] = GetDestructableX(t1)
    set y[2] = GetDestructableY(t1)
    set x[3] = GetDestructableX(t2)
    set y[3] = GetDestructableY(t2)
    set x[4] = x[3] - x[2]
    set y[4] = y[3] - y[2]
    set dis = SquareRoot(x[4] * x[4] + y[4] * y[4])
    
    set mc = R2I(dis/30)
    set abp = bj_RADTODEG * Atan2(y[2] - y[3], x[2] - x[3])
    
    loop
        exitwhen i > mc
        set x[5] = x[3] + 30 * Cos(abp * bj_DEGTORAD)
        set y[5] = y[3] + 30 * Sin(abp * bj_DEGTORAD)
        set m = CreateUnit(p, 'n001', x[5], y[5], 270)
        call GroupAddUnit(g, m)
        set i = i + 1
    endloop
    
    set area = null
    set g = null
    set u = null
    set m = null
    set p = null
endfunction

function InitTrig_ET takes nothing returns nothing
    local trigger ET = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( ET, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( ET, Condition( function Trig_ET_Conditions ) )
    call TriggerAddAction( ET, function Trig_ET_Actions )
endfunction


-But save your old trigger to a notepad first, not sure if I miscalcuated something and screwed it up. :p
EDIT #2: Oh, and you should always null local variables that extends handle at the end of the function. (Such as player, unit, group, point (or location), etc.)
If you decide on using a global variable for the unit group in this trigger you don't need the local unit group 'g', obviously (so make sure you get rid of it.)
 

warden13

New Member
Reaction score
32
First part is working good, thanks.But second part, killing all units in group when one of them dies part is not seems to work.
I want to make it MUI, so I don't want to use global variable. Anyway, is there a function that takes the group of unit. Anything like that : GetGroupofUnit(dying unit)

And Is there a problem with these lines? If yes, how can i fix it? I heard BJs are bad :D

JASS:
set mana[1] = GetUnitStateSwap(UNIT_STATE_MANA, u)
set mana[2] = mana[1] + 200
call SetUnitManaBJ(u, mana[2])
 

Exide

I am amazingly focused right now!
Reaction score
448
Yes, BJ's are "bad". Because they call a function, when you can really just get rid of the 'BJ', and do the same thing.
For example:

JASS:

function SetUnitManaBJ takes unit whichUnit, real newValue returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_MANA, RMaxBJ(0,newValue))
endfunction


or:

JASS:

function GetUnitStateSwap takes unitstate whichState, unit whichUnit returns real
    return GetUnitState(whichUnit, whichState)
endfunction


or:

JASS:

function SetUnitLifeBJ takes unit whichUnit, real newValue returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_LIFE, RMaxBJ(0,newValue))
endfunction


If you don't already have it, I suggest you get JassCraft, when triggering with JASS. It's awesome. =)


In your example, you could do this:




For your unit group problem you could do something like this:

Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in DeathGroup) Equal to True
    • Actions
      • Unit Group - Pick every unit in DeathGroup and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)


Or

Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in DeathGroup[1]) Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in DeathGroup[1] and do (Actions)
            • Loop - Actions
              • Unit - Kill (Picked unit)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in DeathGroup[2]) Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in DeathGroup[2] and do (Actions)
            • Loop - Actions
              • Unit - Kill (Picked unit)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in DeathGroup[3]) Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in DeathGroup[3] and do (Actions)
            • Loop - Actions
              • Unit - Kill (Picked unit)
        • Else - Actions


-Where you use a Unit Group Array in your JASS trigger like this:

JASS:

        call GroupAddUnit(udg_DeathGroup[GetPlayerId(p) +1], m)




You can also change:

JASS:


into:

JASS:

    local unit u = GetTriggerUnit()


it doesn't really matter.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • 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!
  • 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

      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