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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • 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 Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top