HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Chicken spawn system

02-29-2004, 04:29 PM#1
Oinkerwinkle
I'm trying to make a chicken spawning system. After a coop is created, it spawns a chicken every x seconds until 10 chickens is reached. My problem is that it doesn't work (surprise!). It displays "Chicken!" once, creates the test chicken, and does nothing else.

Code:
function Trig_Chickens_Actions takes nothing returns nothing
    local unit coop = GetTriggerUnit()
    local group chickens
    call CreateNUnitsAtLoc( 1, 'n001', GetOwningPlayer(coop), GetUnitLoc(coop), bj_UNIT_FACING )
    call GroupAddUnitSimple( GetLastCreatedUnit(), chickens ) 

    loop
        call DisplayTextToForce( GetPlayersAll(), "Chicken!" )
        if CountUnitsInGroup(chickens)<10 then
            call DisplayTextToForce( GetPlayersAll(), "Spawn!" )
            call CreateNUnitsAtLoc( 1, 'n001', GetOwningPlayer(coop), GetUnitLoc(coop), bj_UNIT_FACING )
            call GroupAddUnitSimple( GetLastCreatedUnit(), chickens )  
        endif

        call TriggerSleepAction(1)
        //exitwhen IsUnitAliveBJ(coop) == false
    endloop
endfunction

//===========================================================================
function InitTrig_Chickens takes nothing returns nothing
    set gg_trg_Chickens = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Chickens, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
    call TriggerAddAction( gg_trg_Chickens, function Trig_Chickens_Actions )
endfunction

Edit: The polt thickens! I added a line that displays "done" at the end, and it never displays. Somehow, it is staying it the loop but not saying "Chicken!"? Also, it isn't saying "Chicken!" at all now.

More edits: The trigger stops when I use any command relating to that unit group. Do I have to initialize it somehow?
02-29-2004, 09:07 PM#2
Oinkerwinkle
Nevermind, I figured it out. I had to initialize it with CreateGroup() .