HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

destroy a unit group?

10-02-2004, 03:20 AM#1
Sicknesslife
what custom script do i need to destroy a unit group... will destroying a unit group kill the units or just clear the group of its population and destroy the name, if it does kill the units then what do i do to clear the group of units so i can repopulate it at a later point?
10-02-2004, 04:55 AM#2
fugly
call DestroyGroup(whichgroup) //* will only destroy the group, not kill the units
call GroupClear(whichgroup) //* Will clear the group and allow units back into it
10-02-2004, 11:38 PM#3
Sicknesslife
I have tried both methods, neither work.

function Trig_Blood_Gout_Action_Func001002 takes nothing returns nothing
call GroupAddUnitSimple( GetEnumUnit(), udg_Blood_Gout_Victims )
endfunction

function Trig_Blood_Gout_Action_Func002002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) - 3.00 ) )
endfunction

function Trig_Blood_Gout_Action_Actions takes nothing returns nothing
call ForGroupBJ( GetUnitsInRangeOfLocAll(512, GetUnitLoc(udg_Fistandantilus)), function Trig_Blood_Gout_Action_Func001002 )
call ForGroupBJ( udg_Blood_Gout_Victims, function Trig_Blood_Gout_Action_Func002002 )
call SetUnitLifeBJ( udg_Fistandantilus, ( GetUnitStateSwap(UNIT_STATE_LIFE, udg_Fistandantilus) + ( 5.00 * I2R(CountUnitsInGroup(udg_Blood_Gout_Victims)) ) ) )
call PolledWait( 1.00 )
call GroupClear(udg_Blood_Gout_Victims)
call ConditionalTriggerExecute( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_Blood_Gout_Action takes nothing returns nothing
set gg_trg_Blood_Gout_Action = CreateTrigger( )
call DisableTrigger( gg_trg_Blood_Gout_Action )
call TriggerAddAction( gg_trg_Blood_Gout_Action, function Trig_Blood_Gout_Action_Actions )
endfunction

that is my trigger, i am trying to set units in a radius of 512 into
unit group = udg_Blood_gout_victims

then have my trigger -5 life from each unit and give the total of life taken away to fistandatilus then clear the group for the next time the trigger runs except the group doesn't clear, when all units are dead and the trigger runs again fistandatilus still recieves life equal to the amount of units previously udg_Blood_Gout_Victims, any help?
10-03-2004, 10:25 AM#4
PitzerMike
You should really use a local group variable here, and you don't need the first enumeration:

Code:
function Trig_Blood_Gout_Action_Func002002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) - 3.00 ) )
endfunction

function Trig_Blood_Gout_Action_Actions takes nothing returns nothing
local group G = GetUnitsInRangeOfLocAll(512, GetUnitLoc(udg_Fistandantilus))
call ForGroupBJ(G, function Trig_Blood_Gout_Action_Func002002)
call SetUnitLifeBJ( udg_Fistandantilus, ( GetUnitStateSwap(UNIT_STATE_LIFE, udg_Fistandantilus) + ( 5.00 * I2R(CountUnitsInGroup(G)) ) ) )
call PolledWait( 1.00 )
//Cleanup local group
call DestroyGroup(G)
set G = null
call ConditionalTriggerExecute( GetTriggeringTrigger() )
endfunction
10-04-2004, 02:41 AM#5
Sicknesslife
I appreciate your attemp to help me but it still doesnt clear the group, when the trigger runs after all nearby units have been killed the trigger still gives me the value of unitgroupnumber = 3

i have attached a copy of my map if anyone wants to take a look and try and help it would be great thanx
10-04-2004, 09:35 AM#6
PitzerMike
The unti group IS properly cleared.
But you know dead units are not removed from the game?
They'll be added to the group even if they're dead. To fix it use this code (which includes a filter for dead units)

Code:
function FilterDeadUnits takes nothing returns boolean
return IsUnitAliveBJ(GetFilterUnit())
endfunction

function Trig_Blood_Gout_Action_Func002002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) - 3.00 ) )
endfunction

function Trig_Blood_Gout_Action_Actions takes nothing returns nothing
local filterfunc F = Filter(function FilterDeadUnits)
local group G = GetUnitsInRangeOfLocMatching(512, GetUnitLoc(udg_Fistandantilus),F)
call DestroyFilter(F)
call ForGroupBJ(G, function Trig_Blood_Gout_Action_Func002002)
call SetUnitLifeBJ( udg_Fistandantilus, ( GetUnitStateSwap(UNIT_STATE_LIFE, udg_Fistandantilus) + ( 5.00 * I2R(CountUnitsInGroup(G)) ) ) )
call PolledWait( 1.00 )
//Cleanup local group
call DestroyGroup(G)
set G = null
call ConditionalTriggerExecute( GetTriggeringTrigger() )
endfunction
10-04-2004, 01:13 PM#7
Sicknesslife
Thank you for your help, everything is nearly in place now i only have one more question if it is not to much to ask. How do i filter out Fistandantilus from the group, i never even realized that it is stealing his own life and giving it back to him?
10-04-2004, 01:47 PM#8
PitzerMike
Quote:
Originally Posted by Sicknesslife
Thank you for your help, everything is nearly in place now i only have one more question if it is not to much to ask. How do i filter out Fistandantilus from the group, i never even realized that it is stealing his own life and giving it back to him?

Simply replace the filter function by this one:

Code:
function FilterDeadUnits takes nothing returns boolean
if IsUnitAliveBJ(GetFilterUnit()) then
  return GetFilterUnit() != udg_Fistandantilus
else
  return false
endif
endfunction
10-04-2004, 05:19 PM#9
Sicknesslife
Thank you very much for your help and all your patience with a JASS noob. I really appreciate the fact that you choose to help me, my trigger is working perfectly now, once again thank you
10-04-2004, 06:15 PM#10
Sicknesslife
I was wondering if you could help me with something else, i want to create a special effect at each unit location of the units in group G. I want to make it a local var by the name of TempSpecEffect and then destroy every instance of it after it has been displayed so as to not cause memory leak. My main problems are:

i don't know how to declare a special effect as a local var,
local _________ TempSpecEffect = blah blah
what do i put in _________ <---- that space?

so my trigger will be ForGroupBJ(G,______________) i don't know what goes here either. do i write createspecial effect or just the variable nem or what?
10-04-2004, 08:21 PM#11
curi
their var type is: effect

you need to get an MPQ editor and extract blizzard.j and common.j from the scripts folder in war3patch.mpq, and look around in there.
10-04-2004, 08:28 PM#12
BuRnInSpartan
lol what a waste of space all you need to do is unit pick every unit in ( group w/e) and do action kill picked unit
10-04-2004, 09:14 PM#13
PitzerMike
Quote:
Originally Posted by BuRnInSpartan
lol what a waste of space all you need to do is unit pick every unit in ( group w/e) and do action kill picked unit

Don't be foolish, we're talking about JASS here, and not GUI triggers. Not to mention that you didn't even read the posts - Noone wanted to kill all units in a group! Also not to mention that ForGroupBJ IS the jass-equivalent of <pick every unit and do action>

But curi is right you should at least get Scripts\Common.j from the Patch.mpq, because all the variable types are declared there (so you won't have to ask here in future)

As for your problem; You've already seen how ForGroupBJ works (it takes a callback function as argument), so something like this would work for you:

Use this function if it's a effect that should simply show its birth animation and then disappear:

function AttachEffects takes nothing returns nothing
call DestroyEffect(AddSpecialEffectTarget("Model-Path.mdl",GetEnumUnit(),"attach-point"))
endfunction

Otherwise use this function:

function AttachEffects takes nothing returns nothing
local effect E = AddSpecialEffectTarget("Model-Path.mdl",GetEnumUnit(),"attach-point"))
call TriggerSleepAction(1) //replace 1 by the wait duration you want
call DestroyEffect(E)
endfunction

then you call it in your main function from with the ForGroup construct:

call ForGroupBJ(G,function AttachEffects)
10-05-2004, 01:02 AM#14
curi
you can't use triggersleep if you are adding effects to a group, b/c it puts the thread to sleep, and thus won't add the second effect until first is destroyed.
10-05-2004, 01:55 AM#15
curi
Quote:
Originally Posted by Sicknesslife
I was wondering if you could help me with something else, i want to create a special effect at each unit location of the units in group G. I want to make it a local var by the name of TempSpecEffect and then destroy every instance of it after it has been displayed so as to not cause memory leak.

here are some SFX functions that won't leak. the one just named sfx takes a duration, location, and path of the effect you want, you can use that. be sure to put double \\ in the path. http://www.wc3sear.ch/index.php?p=JASS&ID=247