| 01-07-2005, 06:18 PM | #1 |
I wanted to make a unit comes within range event to units added later. The problem is that I want to respond the unit in the event...and I can't know the event since I add it later. Anyway I had an idea for solution: Code:
function Trig_MineTrigger_Actions takes unit WhichUnit returns nothing
call KillUnit( WhichUnit )
call SetUnitAnimation( WhichUnit, "stand" )
call KillUnit( GetTriggerUnit() )
endfunction
function Trig_S04DropMines_Func001Func001Func012C takes nothing returns boolean
if ( not ( GetUnitCurrentOrder(udg_PriMinUnit[GetForLoopIndexA()]) != String2OrderIdBJ("move") ) ) then
return false
endif
if ( not ( GetUnitCurrentOrder(udg_PriMinUnit[GetForLoopIndexA()]) != String2OrderIdBJ("smart") ) ) then
return false
endif
return true
endfunction
function Trig_S04DropMines_Func001Func001C takes nothing returns boolean
if ( not ( IsUnitAliveBJ(udg_PriMinUnit[GetForLoopIndexA()]) == true ) ) then
return false
endif
return true
endfunction
function Trig_S04DropMines_Actions takes nothing returns nothing
local code c
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = 8
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
if ( Trig_S04DropMines_Func001Func001C() ) then
set udg_CountInt = ( udg_CountInt + 1 )
set udg_tempPoint2 = GetUnitLoc(udg_PriMinUnit[GetForLoopIndexA()])
set udg_tempPoint1 = PolarProjectionBJ(udg_tempPoint2, 75.00, ( GetUnitFacing(udg_PriMinUnit[GetForLoopIndexA()]) - 180.00 ))
set udg_MineTrigger[ udg_CountInt ] = CreateTrigger()
call TriggerRegisterUnitInRangeSimple( udg_MineTrigger[udg_CountInt], 50.00, GetLastCreatedUnit() )
call TriggerAddAction( udg_MineTrigger[udg_CountInt], function Trig_MineTrigger_Actions[color=red](GetLastCreatedUnit())[/color] )
call CreateNUnitsAtLocFacingLocBJ( 1, 'nglm', Player(11), udg_tempPoint1, udg_tempPoint2 )
call RemoveLocation( udg_tempPoint1 )
call RemoveLocation( udg_tempPoint2 )
if ( Trig_S04DropMines_Func001Func001Func012C() ) then
call SetUnitLifeBJ( udg_PriMinUnit[GetForLoopIndexA()], ( GetUnitStateSwap(UNIT_STATE_LIFE, udg_PriMinUnit[GetForLoopIndexA()]) - 1 ) )
else
endif
else
endif
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
endfunction
//===========================================================================
function InitTrig_S04DropMines takes nothing returns nothing
set gg_trg_S04DropMines = CreateTrigger( )
call DisableTrigger( gg_trg_S04DropMines )
call TriggerRegisterTimerEventPeriodic( gg_trg_S04DropMines, 0.25 )
call TriggerAddAction( gg_trg_S04DropMines, function Trig_S04DropMines_Actions )
endfunctionI thought it maybe would work the way as shown in the code (I'm not even sure about that) but the part made in red is not accepted. It says it expects a '. Do you know any way to make this work or do I have to use a periodic event for making this (I really think this would be both better and more fun)? |
| 01-07-2005, 07:45 PM | #2 |
Guest | Your problem is that TriggerAddAction takes some code as a parameter, and that code on its turn does not accept an own parameter. The parameter is passed as a parameter, not evaluated as a function. So Trig_MineTrigger_Actions shouldn't be taking any parameters.. One solution might be to replace the whichUnit variable in Trig_MineTrigger_Actions with GetLastCreatedUnit(). Or you could make a global variable like LastCreatedUnit and set it to GetLastCreatedUnit() right before TriggerAddAction is called. Or if you need the function Trig_MineTrigger_Actions also for another unit, you could use an intermediary function like: Code:
function Trig_MineTrigger_Actions_ForLastCreatedUnit takes nothing returns nothing
call Trig_MineTrigger_Actions(GetLastCreatedUnit())
endfunction |
| 01-08-2005, 04:48 PM | #3 | |
Quote:
Notice this isn't my primar problem. I want it to be the last created unit WHEN you add the trigger. Like how the events work. I know I could do it that way you told me but I don't think any of them would work, and especially not your method. How can I add so it returns the unit that WAS the last created at the moment when you add the trigger? |
| 01-08-2005, 05:51 PM | #4 |
Guest | I only looked at the red part. Sorry for that. There is nothing local to the Trigger, since you always have to pass it the same code. So, no, it is not possible I think, unless you define one for each seperate mine... For your code, can't you write a function GetClosestMine takes unit, and use that instead of GetLastCreatedUnit()? |
