- Joined
- Apr 25, 2011
- Messages
- 73
Hi. I seem to have problems with the spawning trigger I made. Here it is:
Ok. So... I works perfectly, I don't think it leaks or something (but if it does, please let me know). The problem is the amount of units it creates. I want 1 unit to spawn and it spawns 5... The thing is that it doesn't spawn them in the same point. It spawns them in different locations. Just like a loop. But I didn't use one there...
In game, after I kill 2 or 3 units, it will spawn the 2 or 3 units (which is correct), but it does it simultaneously. I tried with CreateUnitAtLoc, but it seemed to have the same result. So I changed it with CreateNUnitsAtLoc which still has the same effect.
If you know how to solve my problem, please let me know. But, please, don't post here your spawning triggers, unless they are really "Only for dummies", 'cuz I'm not in the mood of thinking how to make another trigger for spawning creeps.
JASS:
function Spw1 takes nothing returns boolean
return ( GetUnitTypeId(GetFilterUnit()) == 'npig' )
endfunction
function Spw2 takes nothing returns boolean
return ( GetUnitTypeId(GetFilterUnit()) == 'nder' )
endfunction
function Spw_A takes nothing returns nothing
local integer a
local integer b
local player p
local group g
local rect r
local location l
local boolexpr e
set r = Rect(-10500.00, -15700.00, -5400.00, -14300.00)
set l = Location(GetRandomReal(GetRectMinX(r), GetRectMaxX(r)), GetRandomReal(GetRectMinY(r), GetRectMaxY(r)))
set p = Player(PLAYER_NEUTRAL_AGGRESSIVE)
set e = (Condition (function Spw1))
set g = CreateGroup()
call GroupEnumUnitsInRect(g, r, e )
set a = CountUnitsInGroup(g)
call DestroyBoolExpr(e)
call DestroyGroup(g)
set g = null
set e = (Condition (function Spw2))
set g = CreateGroup()
call GroupEnumUnitsInRect(g, r, e)
set b = CountUnitsInGroup(g)
call DestroyBoolExpr(e)
call DestroyGroup(g)
if ( a < 5 ) then
call CreateNUnitsAtLoc( 1, 'npig', p, l, bj_UNIT_FACING )
call RemoveLocation(l)
endif
set l = Location(GetRandomReal(GetRectMinX(r), GetRectMaxX(r)), GetRandomReal(GetRectMinY(r), GetRectMaxY(r)))
if ( b < 5 ) then
call CreateNUnitsAtLoc( 1, 'nder', p, l, bj_UNIT_FACING )
call RemoveLocation(l)
endif
set e = null
set p = null
set l = null
set r = null
set g = null
endfunction
//===========================================================================
function InitTrig_Spw takes nothing returns nothing
local trigger t
local integer index
set t = CreateTrigger( )
set index = 0
loop
call TriggerRegisterTimerEvent(t, 30, true)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction( t, function Spw_A )
set t = null
endfunction
Ok. So... I works perfectly, I don't think it leaks or something (but if it does, please let me know). The problem is the amount of units it creates. I want 1 unit to spawn and it spawns 5... The thing is that it doesn't spawn them in the same point. It spawns them in different locations. Just like a loop. But I didn't use one there...
In game, after I kill 2 or 3 units, it will spawn the 2 or 3 units (which is correct), but it does it simultaneously. I tried with CreateUnitAtLoc, but it seemed to have the same result. So I changed it with CreateNUnitsAtLoc which still has the same effect.
If you know how to solve my problem, please let me know. But, please, don't post here your spawning triggers, unless they are really "Only for dummies", 'cuz I'm not in the mood of thinking how to make another trigger for spawning creeps.