| 01-30-2010, 11:20 AM | #1 |
Cheers. Keeping it short I'm making a spell in which I want to make 6 random units invisible. For this I'm removing the unit from my group when I've made it invisible (using GroupRemoveUnit() ). However, my debugmessages say that he's being retargeted. (msgs) 1048726 1048723 1048710 1048710 1048710 1048710 Part of interest:
loop
call ForGroup( g, function GroupPickRandomUnitEnum )
exitwhen i > NumberOfEffected( level ) or bj_groupRandomCurrentPick == null
call BJDebugMsg( I2S( GetHandleId( bj_groupRandomCurrentPick ) ) )
call SaveUnitHandle( hash, GetHandleId( g ), i, bj_groupRandomCurrentPick )
call UnitAddAbilityEx( bj_groupRandomCurrentPick, PERMANENT_INVIS_ID )
call SetUnitPathingEx( bj_groupRandomCurrentPick, false )
call GroupRemoveUnit( g, bj_groupRandomCurrentPick )
call GroupRemoveUnit( g, bj_groupRandomCurrentPick )
set i = i + 1
endloop
GroupPickRandomUnitEnum:function GroupPickRandomUnitEnum takes nothing returns nothing set bj_groupRandomConsidered = bj_groupRandomConsidered + 1 if (GetRandomInt(1,bj_groupRandomConsidered) == 1) then set bj_groupRandomCurrentPick = GetEnumUnit() endif endfunction Entire Code:scope CloakOfShadows initializer Init //=========================================================================== //=========================================================================== //=========================================================================== globals private constant integer SPELL_ID = 'A00J' public constant integer PERMANENT_INVIS_ID = 'A00K' endglobals private constant function AreaOfEffect takes integer level returns real return 500. endfunction private constant function NumberOfEffected takes integer level returns integer return 4 + level endfunction private constant function Duration takes integer level returns real return 20. endfunction //=========================================================================== //=========================================================================== //=========================================================================== globals private hashtable hash private trigger trg endglobals private function Actions takes nothing returns nothing local group g = NewGroup() local group copy = NewGroup() local unit u = GetTriggerUnit() local integer level = GetUnitAbilityLevel( u, SPELL_ID ) local integer i = 0 local real r = AreaOfEffect( level ) local real x = GetUnitX( u ) local real y = GetUnitY( u ) call GroupEnumUnitsInRange( g, x, y, r, DEFAULT_FRIEND_NOT_SELF_FILTER ) set copy = CopyGroup( g ) loop call ForGroup( g, function GroupPickRandomUnitEnum ) exitwhen i > NumberOfEffected( level ) or bj_groupRandomCurrentPick == null call BJDebugMsg( I2S( GetHandleId( bj_groupRandomCurrentPick ) ) ) call SaveUnitHandle( hash, GetHandleId( g ), i, bj_groupRandomCurrentPick ) call UnitAddAbilityEx( bj_groupRandomCurrentPick, PERMANENT_INVIS_ID ) call SetUnitPathingEx( bj_groupRandomCurrentPick, false ) call GroupRemoveUnit( g, bj_groupRandomCurrentPick ) call GroupRemoveUnit( g, bj_groupRandomCurrentPick ) set i = i + 1 endloop endfunction private function Debug takes nothing returns nothing call UnitRemoveAbility( GetAttacker(), PERMANENT_INVIS_ID ) endfunction //=========================================================================== private function Init takes nothing returns nothing call NewSpell( SPELL_ID, function Actions ) set hash = InitHashtable() set trg = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_ATTACKED ) call TriggerAddAction( trg, function Debug ) call DisableTrigger( trg ) endfunction endscope Any idea of what's going on? |
| 01-30-2010, 01:27 PM | #2 |
GroupPickRandomUnitEnum:function GroupPickRandomUnitEnum takes nothing returns nothing set bj_groupRandomConsidered = bj_groupRandomConsidered + 1 if (GetRandomInt(1,bj_groupRandomConsidered) == 1) then set bj_groupRandomCurrentPick = GetEnumUnit() endif endfunction I bet that's why it happens. bj_groupRandomCurrentPick doesn't change unless that integer thing is always 1, that's why a unit gets retargeted. I guess *even* this: GroupPickRandomUnitEnum:function GroupPickRandomUnitEnum takes nothing returns nothing set bj_groupRandomCurrentPick = GetEnumUnit() endfunction would be more effective for your purpose, since the already targeted units would be out of the group. Also: JASS:loop call ForGroup( g, function GroupPickRandomUnitEnum ) exitwhen i > NumberOfEffected( level ) or bj_groupRandomCurrentPick == null call BJDebugMsg( I2S( GetHandleId( bj_groupRandomCurrentPick ) ) ) call SaveUnitHandle( hash, GetHandleId( g ), i, bj_groupRandomCurrentPick ) call UnitAddAbilityEx( bj_groupRandomCurrentPick, PERMANENT_INVIS_ID ) call SetUnitPathingEx( bj_groupRandomCurrentPick, false ) call GroupRemoveUnit( g, bj_groupRandomCurrentPick ) call GroupRemoveUnit( g, bj_groupRandomCurrentPick ) set i = i + 1 endloop |
| 01-30-2010, 02:58 PM | #3 |
GroupPickRandomUnitEnum is made by blizzard and I highly doubt it's disfunctional... And that duplicate is unneccessary, was just a test to see if it for some reason would work. I had a version before which used GetEnumUnit() but it kept targeting the same units in a specific pattern, so I decided to rewrite it. It didn't look very natural. |
| 01-30-2010, 03:03 PM | #4 | |
Quote:
|
| 01-30-2010, 03:16 PM | #5 |
I think you're missing something that Blizzard does: JASS://=========================================================================== // Picks a random unit from a group. // function GroupPickRandomUnit takes group whichGroup returns unit // If the user wants the group destroyed, remember that fact and clear // the flag, in case it is used again in the callback. local boolean wantDestroy = bj_wantDestroyGroup set bj_wantDestroyGroup = false set bj_groupRandomConsidered = 0 set bj_groupRandomCurrentPick = null call ForGroup(whichGroup, function GroupPickRandomUnitEnum) // If the user wants the group destroyed, do so now. if (wantDestroy) then call DestroyGroup(whichGroup) endif return bj_groupRandomCurrentPick endfunction |
| 01-30-2010, 05:26 PM | #6 |
Thanks a lot Iron_Doors, you saved the day! +rep on that |
