HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Creating Limited Units in a Region with conditions

12-23-2006, 07:26 AM#1
taste
Guys i'm at my wits end here. Spent all day trying and also searching all over the forums but I just can't seem to find it.

The scenario is I have a few locations in the map where at certain timed intervals, it will randomly pick one of these locations and spawn an object.

Two conditions for this is that
i) it won't spawn the object again if there is already an object on that location
ii) there must not be a certain type of unit waiting at that location or the object will not spawn either
iii) if the location that is picked is affected by either one of the first 2 conditions, it will then choose another location.

I've read about arrays, but I'm not very sure how to implement them so currently I'm using a UnitGroup array for this but I just can't seem to get the logic right.

Heres the code I have that I think is the most logical so far...

Code:
function Trig_Create_Food_Func001002 takes nothing returns nothing
    call GroupAddUnitSimple( GetEnumUnit(), GetLastCreatedGroup() )
endfunction

function Trig_Create_Food_Func003001002 takes nothing returns boolean
    return ( GetUnitTypeId(GetEnumUnit()) == 'h004' )
endfunction

function Trig_Create_Food_Func003002 takes nothing returns nothing

endfunction

function Trig_Create_Food_Actions takes nothing returns nothing
    local group gFoodSpawner 
    local group gNearbyCreatures 
    local unit uSpawner
    
    set gFoodSpawner = GetUnitsOfPlayerAndTypeId(Player(8), 'H005')    
    call ForGroupBJ( gFoodSpawnerGroup, function Trig_Create_Food_Func001002 ) 
    set uSpawner = GroupPickRandomUnit(gFoodSpawner)     
    set gNearbyCreatures = GetUnitsOfPlayerAndTypeId(Player(8), 'H005')
    call ForGroupBJ( GetUnitsInRectMatching(RectFromCenterSizeBJ(GetUnitLoc(uSpawner), 300.00, 300.00), Condition(function Trig_Create_Food_Func003001002)), function Trig_Create_Food_Func003002 )
    call CreateNUnitsAtLoc( 1, 'h004', Player(8), GetUnitLoc(uSpawner), GetRandomDirectionDeg() )
endfunction

//===========================================================================
function InitTrig_Create_Food takes nothing returns nothing
    set gg_trg_Create_Food = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Create_Food, function Trig_Create_Food_Actions )
endfunction

Would really appreciate help.. please. Thanks in advance