- Joined
- Feb 2, 2006
- Messages
- 1,633
Hello,
for my creep respawn system I would like to get the last unit of a group. However, there seems to be an issue when getting the last member.
This is my JASS code:
And this is my trigger to create a respawn group:
It behaves like I would have added the same unit twice to the group.
When I switch the two lines of "Dunkeltrollberserker":
I am confused.
I have attached the corresponding map. The trigger is called "Kalimdor Creep Groups". You should see the debug output in the beginning of the game.
for my creep respawn system I would like to get the last unit of a group. However, there seems to be an issue when getting the last member.
This is my JASS code:
JASS:
function GetLastMemberOfGroup takes group whichGroup returns unit
local group tmpGroup = CreateGroup()
local unit tmpLast = null
local unit last = null
call GroupAddGroup(whichGroup, tmpGroup)
loop
set tmpLast = FirstOfGroup(tmpGroup)
exitwhen (tmpLast == null)
set last = tmpLast
call GroupRemoveUnit(tmpGroup, last)
endloop
call DestroyGroup(tmpGroup)
set tmpGroup = null
set tmpLast = null
return last
endfunction
function GetLastIndexOfGroup takes group whichGroup returns integer
local group tmpGroup = CreateGroup()
local unit tmpLast = null
local integer last = -1
call GroupAddGroup(whichGroup, tmpGroup)
loop
set tmpLast = FirstOfGroup(tmpGroup)
exitwhen (tmpLast == null)
call GroupRemoveUnit(tmpGroup, tmpLast)
set last = last + 1
endloop
call DestroyGroup(tmpGroup)
set tmpGroup = null
set tmpLast = null
return last
endfunction
function AssignUnitToCurrentGroup takes nothing returns nothing
local integer lastIndex = GetLastIndexOfGroup(udg_RespawnGroup[udg_TmpGroupIndex])
local integer memberIndex = Index2D(udg_TmpGroupIndex, lastIndex, udg_RespawnGroupMaxMembers)
local unit lastMember = GetLastMemberOfGroup(udg_RespawnGroup[udg_TmpGroupIndex])
call BJDebugMsg("Assign to unit " + GetUnitName(lastMember) + " with handle ID " + I2S(GetHandleId(lastMember)) + " with index " + I2S(lastIndex) + " the current group " + I2S(udg_TmpGroupIndex) + " the unit group has a size of " + I2S(CountUnitsInGroup(udg_RespawnGroup[udg_TmpGroupIndex])))
set udg_RespawnUnitType[memberIndex] = GetUnitTypeId(lastMember)
set udg_RespawnLocationPerUnit[memberIndex] = GetUnitLoc(lastMember)
call AssignUnitToGroup(lastMember, udg_TmpGroupIndex)
set lastMember = null
endfunction
function InitCurrentGroup takes nothing returns nothing
set udg_TmpGroupIndex = udg_TmpGroupIndex + 1
set udg_RespawnGroup[udg_TmpGroupIndex] = CreateGroup()
endfunction
And this is my trigger to create a respawn group:
-
Actions
-
Set VariableSet TmpGroupIndex = -1
-
-------- KALIMDOR --------
-
-------- Trolle 1 --------
-
Custom script: call InitCurrentGroup()
-
Unit Group - Add Dunkeltrollfallensteller 0348 <gen> to RespawnGroup[TmpGroupIndex]
-
Custom script: call AssignUnitToCurrentGroup()
-
Unit Group - Add Dunkeltrollhohepriester 0350 <gen> to RespawnGroup[TmpGroupIndex]
-
Custom script: call AssignUnitToCurrentGroup()
-
Unit Group - Add Dunkeltrollberserker 0353 <gen> to RespawnGroup[TmpGroupIndex]
-
Custom script: call AssignUnitToCurrentGroup()
-
Unit Group - Add Dunkeltrollberserker 0351 <gen> to RespawnGroup[TmpGroupIndex]
-
Custom script: call AssignUnitToCurrentGroup()
-
Set VariableSet RespawnItemType[TmpGroupIndex] = Heilsalbe
-
It behaves like I would have added the same unit twice to the group.
When I switch the two lines of "Dunkeltrollberserker":
-
Unit Group - Add Dunkeltrollberserker 0351 <gen> to RespawnGroup[TmpGroupIndex]
-
Custom script: call AssignUnitToCurrentGroup()
-
Unit Group - Add Dunkeltrollberserker 0353 <gen> to RespawnGroup[TmpGroupIndex]
-
Custom script: call AssignUnitToCurrentGroup()
I am confused.
I have attached the corresponding map. The trigger is called "Kalimdor Creep Groups". You should see the debug output in the beginning of the game.