| 04-21-2008, 06:06 PM | #1 |
Ok so I've got some units with the ability Locust and i'm trying to select them and change their owner and coming up with nothing... here's the code. JASS:function GetGoldMine takes real X,real Y,player p returns unit local rect TempRect local group GroupTemp = CreateGroup() local unit U set TempRect = Rect(X-(GRID_SIZE / 2), Y-(GRID_SIZE / 2), (X-(GRID_SIZE / 2)) + I2R(GRID_SIZE), (Y-(GRID_SIZE / 2)) + I2R(GRID_SIZE)) call GroupEnumUnitsInRect(GroupTemp,TempRect, null) loop set U = FirstOfGroup(GroupTemp) exitwhen U == null call GroupRemoveUnit(GroupTemp, U) if GetOwningPlayer(U) != p then if GetUnitTypeId(U) == 'n003' then return U endif endif endloop return U endfunction Works fine if the unit doesn't have 'Aloc'. Is there anything special i need to be doing to get this to work? |
| 04-21-2008, 06:12 PM | #2 | |
Quote:
GroupEnumUnitsOfPlayer(group g, player owner, boolexpr filter) does work though; you can loop through enuming for all players with a filter that uses temp global reals to find if a unit is in range. |
| 04-21-2008, 07:54 PM | #3 |
Awesome thanks! +Rep |
| 04-22-2008, 12:39 AM | #4 |
well in truth it's not awesome... =) hmmm =\ *have an idea* split the map into 512x512 rects andd triggers with events on enter and live add groups to this rects and keep all unit in this rect in that group (you will add only "Aloced" unit's into it) so for 512 range you will need to check 9 such rects xD. it just an idea... |
| 04-22-2008, 01:52 AM | #5 |
Here's what I ended up doing. JASS:function GetUnitType takes nothing returns boolean if GetUnitTypeId(GetFilterUnit()) == 'n003' then return true else return false endif endfunction function GetGoldMine takes player p returns nothing local group GroupTemp = CreateGroup() local group array CheckAgainst local unit U local unit U2 local integer array looped local integer i = 1 set CheckAgainst[1] = CreateGroup() set CheckAgainst[2] = CreateGroup() set CheckAgainst[3] = CreateGroup() set CheckAgainst[4] = CreateGroup() set CheckAgainst[16] = CreateGroup() set looped[1] = 1 set looped[2] = 2 set looped[3] = 3 set looped[4] = 4 set looped[5] = 16 call GroupEnumUnitsOfPlayer(GroupTemp,p, null) loop set U = FirstOfGroup(GroupTemp) exitwhen U == null call GroupRemoveUnit(GroupTemp, U) set i = 1 loop exitwhen i > 5 //call DisplayTextToForce( GetPlayersAll(), "Grabbing for player " + I2S(looped[i])) call GroupEnumUnitsOfPlayer(CheckAgainst[looped[i]],ConvertedPlayer(looped[i]), Condition(function GetUnitType)) set i = i+1 endloop set i = 1 loop exitwhen i > 5 loop set U2 = FirstOfGroup(CheckAgainst[looped[i]]) exitwhen U2 == null call GroupRemoveUnit(CheckAgainst[looped[i]],U2) //call DisplayTextToForce( GetPlayersAll(), "Player " + I2S(GetConvertedPlayerId(p)) + " checked Player " + I2S(GetConvertedPlayerId(GetOwningPlayer(U2)))) if GetOwningPlayer(U2) != p then if GetUnitTypeId(U2) == 'n003' then if DistanceBetweenPoints(GetUnitLoc(U), GetUnitLoc(U2)) <= 255.00 then call GoldMineTake(U2,p) endif endif endif endloop set i = i + 1 endloop endloop endfunction It wouldn't add all players units that I picked to the group, it just overwrote the last one ran so i had to set them up in an array then loop through the arrays. Probably not the best way but it works. |
| 04-22-2008, 01:59 AM | #6 |
Hmm... you should use search properly - http://wc3campaigns.net/showthread.php?t=99589 |
| 04-22-2008, 02:17 AM | #7 | |
Quote:
Ya I saw that thread, the answer wasn't clear so I re-asked and fixed my problem. |
| 04-22-2008, 03:00 PM | #8 |
I think you could do it with only two groups; here's an example since I don't know how your function works: Aloc Grouping:function t_callback takes nothing returns nothing local integer n=0 local integer max=5 local unit u=null local group temp_group=CreateGroup() local group g=CreateGroup() loop call GroupEnumUnitsOfPlayer( temp_group, Player(n), null ) call GroupAddGroup( temp_group, g ) set n=n+1 exitwhen n==max endloop loop set u=FirstOfGroup(g) exitwhen u==null call BJDebugMsg( GetUnitName( u )+" is Owned by: "+GetPlayerName( GetOwningPlayer( u ) ) ) call GroupRemoveUnit( g, u ) endloop call DestroyGroup( temp_group ) call DestroyGroup( g ) set temp_group=null set g=null set u=null endfunction //=========================================================================== function InitTrig_test takes nothing returns nothing local integer max_unit=5 local integer n=0 loop call UnitAddAbility( CreateUnit( Player(n), 'hmtt', n*100, n*100, 0 ), 'Aloc' ) set n=n+1 exitwhen n==max_unit endloop call TimerStart( CreateTimer(), 5, true, function t_callback ) endfunction Make 2 groups, 1 group to store the Aloc units by player then copy those units to another group to store them for usage. I hope it helped. |
