• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Matching condition function for pick unit in range

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
JASS:
call GroupEnumUnitsInRange(gr,ux,uy,600.00,Condition(function Unit_Group6))
JASS:
function Unit_Group6 takes nothing returns boolean
    local unit u = GetFilterUnit()
    local unit ut = GetTriggerUnit()
    local real x1 = GetUnitX(ut)
    local real y1 = GetUnitY(ut)
    local real x2 = GetUnitX(u)
    local real y2 = GetUnitY(u)
    local real ang = Atan2( y2 - y1,  x2 - x1)
    local real x3 = x1 + 500 * Cos(ang)  
    local real y3 = y1 + 500 * Sin(ang)  
    local real dmg = 10 + (GetUnitAbilityLevel(ut, 'AOws')) * 50
    if ((IsUnitEnemy(u, GetTriggerPlayer())==true)) then
       call UnitDamageTarget(ut, u, dmg, true, false, ConvertAttackType(6), ConvertDamageType(4), ConvertWeaponType(0))
       call IssuePointOrder (u, "move" , x3, y3) 
       call SetUnitFacing(u, ang*180/3.14159-180)
       call SetUnitPosition (u, x3, y3)
    endif
    set u = null
    set ut = null
    return false 
endfunction

1.How can i pass variable to Unit_Group6 function without useing global variables?

like in bottom example when i pass boolean, integer and unit to function?

coz in every trigger if i use unit group function then allways name must different and idk if i cant rreplace it to a global unit group function what i can call when i need it ...
2.
since in Unit_Group6 function dont exist loop, how can i index the picked units?
example: u=getenumedunit();set i=i+1



JASS:
 call AddHPMP(true, i, u)

if i changed takes nothing to takes integer i in 1st trigger then i got something expected error '
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
I don't understand completely what you mean, but if your trying to pass an integer to function Unit_Group6.
Then when adding takes integer i, you should ofcourse pass the integer...
JASS:
call GroupEnumUnitsInRange(gr,ux,uy,600.00,Condition(function Unit_Group6(i)))

I'm not sure if this is what is causing your error, but could you explain more thorough?

EDIT: I think I understand now. Your trying to group units together using GroupEnumUnitsInRange and you want to index the units that get grouped together right?
Since GroupEnumUnitsInRange does not return anything this might be hard to do. What if you use GetUnitsInRangeOfLocMatching in order to return them?
I know, location is bad but it might be worth a shot...
You should be abled to index and group the picked units then.
 
Last edited:
Level 17
Joined
Nov 13, 2006
Messages
1,814
JASS:
call GroupEnumUnitsInRange(gr,ux,uy,600.00,Condition(function Unit_Group6(i)))

its gived "expected error ' "

i tryed avoid the locations.

JASS:
loop
   set u = FirstOfGroup(gr)
   exitwhen u==null   
   //if conditions here
    
   ///endif
   call GroupRemoveUnit(gr, u)
endloop
only way if i clear units from then group 1by1? if group is empty and i use
JASS:
call GroupEnumUnitsInRange(gr,ux,uy,600.00,null)
again then it dont cause leak right?
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
groups doesnt leak if you dont create it again and again...
use "bj_lastCreatedGroup" instead of a global group like "gr" instead...

sample;
set u = FirstOfGroup(bj_lastCreatedGroup)

gr is local group not global, this is why i asked, coz i created group inside the trigger (local group gr = CreateGroup()) and i used more time call GroupEnumUnitsInRange(gr,ux,uy,600.00,null) in same trigger with same group (coz i thought 2nd groupenum clear the unit group [gr] and add pick again the units to group)
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
"bj_lastCreatedGroup" doesnt need to be created nor destroyed, so its better than the local group you created...your gr is leaking if its not destroyed...

sorry but i dont understanded when leak the group's or how it work.
its leak when i create a group and dont destroyed it and create same group again or when i use GroupEnumUnits more times for same group?

in my example i created a group with local 1x but till the end of trigger i used 2x GroupEnumUnitsInRange... if i understand the GroupEnumUnitsInRange dunction then its add unit to unitgroup (and not recreate a group) and if i use GroupEnumUnitsInRange again then its clear the group and add another unit (adding unit to group not leaking, no?)

JASS:
local group gr = CreateGroup())
call GroupEnumUnitsInRange(gr,ux,uy,600.00,null)
loop
   set u = FirstOfGroup(gr)
   call GroupRemoveUnit(gr, u) 
   if ((IsUnitEnemy(u, GetTriggerPlayer())==true)) then
    ***blabla***
   endif
   exitwhen u==null  
endloop
TriggerSleepAction (1)
call GroupEnumUnitsInRange(gr,ux,uy,900.00,null)
loop
   set u = FirstOfGroup(gr)
   call GroupRemoveUnit(gr, u) 
   if (((IsUnitEnemy(u, GetTriggerPlayer())==true)) and (range>300)) then
    ***blabla***
   endif
   exitwhen u==null  
endloop
call DestroyGroup(gr)
set gr = null
set u = null

another question how could i make random unit from gr group without another functions?

i tryed make bounceing spell with shurriken

JASS:
function Trig_shuriken_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'AHtb' ) ) then
        return false
    endif
    return true
endfunction

function Trig_shuriken_Actions takes nothing returns nothing
local boolean exit = false
local unit u = GetTriggerUnit()
local unit ut = GetSpellTargetUnit()
local unit us = null
local unit pu = null
local unit lu = null
local integer mu = 3 + (GetUnitAbilityLevel(u, 'AHtb'))*2
local integer cu = 0
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real nx = GetUnitX(ut)
local real ny = GetUnitY(ut)
local real xs 
local real ys 
local real dx = 0
local real dy = 0
local real d = 600
local real dmg = 10 + (GetUnitAbilityLevel(u, 'AHtb')) * 50
local player p = GetOwningPlayer(u)
local group gr = CreateGroup()

set us = CreateUnit (p, 'h000', x , y, 0)  
loop
exitwhen ( cu >= mu )
set exit = false
if (cu>0) then
 call GroupEnumUnitsInRange(gr,xs,ys,450.00,null)
  loop
   set pu = GroupPickRandomUnit(gr)
   exitwhen (pu==null) or (exit==true)
    if ((IsUnitEnemy(pu, GetTriggerPlayer())) and (pu!=ut) and (pu!=lu) and (GetUnitState(pu, ConvertUnitState(0)) > 0)) then 
      set lu = ut
      set ut = pu
     set d = 450
     set exit = true
    endif
   call GroupRemoveUnit(gr, pu)
  endloop
endif
if (ut == null) then
call SetUnitExploded(us, true)
call KillUnit(us)
endif
call IssueTargetOrder( us, "attack", ut )
    loop
        exitwhen ( d < 60.00 )
            set xs =  GetUnitX(us)
            set ys =  GetUnitY(us)
            set nx =  GetUnitX(ut)
            set ny =  GetUnitY(ut)
            set dx = nx - xs
            set dy = ny - ys
            set d = SquareRoot(dx * dx + dy * dy)
            call TriggerSleepAction(0.05)
    endloop
call UnitDamageTarget(u, ut, dmg, true, false, ConvertAttackType(6), ConvertDamageType(4), ConvertWeaponType(0))
set cu = cu + 1
endloop
call UnitApplyTimedLife( us, 'BUan', 0.1 )
//BTLF
call DestroyGroup(gr)
set ut = null
set us = null
set pu = null
set lu = null
set p = null
set gr = null
endfunction

//===========================================================================
function InitTrig_Shuriken_bounce takes nothing returns nothing
    set gg_trg_Shuriken_bounce = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Shuriken_bounce, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Shuriken_bounce, Condition( function Trig_shuriken_Conditions ) )
    call TriggerAddAction( gg_trg_Shuriken_bounce, function Trig_shuriken_Actions )
endfunction
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
local group gr = CreateGroup()
call GroupEnumUnitsInRange(gr,ux,uy,600.00,null)
loop
   set u = FirstOfGroup(gr)
   exitwhen u==null 
   call GroupRemoveUnit(gr, u) 
   if IsUnitEnemy(u, GetTriggerPlayer()) then
    ***blabla***
   endif 
endloop
TriggerSleepAction (1)
call GroupEnumUnitsInRange(gr,ux,uy,900.00,null)
loop
   set u = FirstOfGroup(gr)
   exitwhen u==null
   call GroupRemoveUnit(gr, u) 
   if IsUnitEnemy(u, GetTriggerPlayer()) and range>300 then
    ***blabla***
   endif  
endloop
call DestroyGroup(gr)
set gr = null
// u will be null due to the exitwhen

another question how could i make random unit from gr group without another functions?

I think FirstOfGroup is pretty random.
 
like I said, 'if its not destroyed'...coz there's no "call DestroyGroup(gr)" in your first post...
after your "local group gr = CreateGroup()", you did not create anything but just
using it and you destroyed it so no leak there...
FirstOfGroup is fine with Random like Maker said, although the filtered unit is
picked from the far "y" of the coordinate...
an alternative method can be this...
JASS:
set Random = 0 //global integer variable
    loop
        set u = FirstOfGroup(gr)
        exitwhen u==null
        if not IsUnitType(u, UNIT_TYPE_DEAD) then
            set Random = Random + 1
            if Random==1 then
                call KillUnit(u)
            endif
        endif        
        call GroupRemoveUnit(gr, u)
    endloop
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
thx i understand

about FirstOfGroup the problem was this(this like a map with a-d units):
---------d----------
---b-a--c-----------
--e-----------------
i tryed make a bounceing shuriken what jump to another unit and if 1st target was a then 1st from group was b what is closest unit then again a unit and again b, never jumped to another unit coz allways 1st unit in group was the closest.

(i think my mistake was the making 2 pickunitinrange instead 1 but acctually i must allways repick coz the range must be caculated from current target position not from 1st target position :/)
 
Status
Not open for further replies.
Top