- Joined
- Jan 11, 2009
- Messages
- 3,414
I'm working with a map that uses a grouping system in which you can replace one of the standard units in your group whith a "special" unit.
For finding a standard unit in a group i use this script:
As you can see, i use the units custom value as the group array index.
The array sq_g holds the group.
Note that DestroyEffectTimed is a custom function.
This works brilliantly the first time, though after that it wont find any more units even if there are some idle. Even if the replaced unit dies, it will still only work once.
The script is triggered through this line:
Please help.
For finding a standard unit in a group i use this script:
JASS:
function unitReplace takes unit u, integer new returns nothing
local location l = GetUnitLoc(u)
local integer d = GetUnitUserData(u)
call BJDebugMsg(I2S(d)+" SPECIAL TYPE")
call DestroyEffectTimed(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\DeathPact\\DeathPactTarget.mdl", l), 2.)
call ReplaceUnitBJ(u, new, bj_UNIT_STATE_METHOD_RELATIVE ) //BJ OH NO!!!!
call GroupAddUnit(udg_sq_g[d], GetLastReplacedUnitBJ())
call SetUnitUserData(GetLastReplacedUnitBJ(), d)
call BJDebugMsg(R2S(GetLocationY(l))+R2S(GetLocationX(l))) //those are just debug stuff
call RemoveLocation(l)
set l = null
endfunction
As you can see, i use the units custom value as the group array index.
The array sq_g holds the group.
Note that DestroyEffectTimed is a custom function.
This works brilliantly the first time, though after that it wont find any more units even if there are some idle. Even if the replaced unit dies, it will still only work once.
The script is triggered through this line:
-
Add Specialist
-
Events
- Unit - A unit Uses an item
-
Conditions
- (Item-type of (Item being manipulated)) Equal to Add Specialist
-
Actions
- Custom script: call unitReplace(getFreeUnit(GetTriggerUnit()), 'h003')
-
Events
Please help.