diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index 6a498797a..e89d53b63 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -1880,6 +1880,11 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth ) -- SpawnTemplate.uncontrolled = self.SpawnUnControlled -- end -- end + + + if self.BeforeTemplateSpawnFunc then + self:BeforeTemplateSpawnFunc(SpawnTemplate, SpawnIndex) + end end if not NoBirth then @@ -1995,6 +2000,31 @@ function SPAWN:SpawnScheduleStop() return self end +--- Allows to place a CallFunction hook just before spawning the group to tweak the template. +-- The provided method will be called just before a new group is spawned, including its given parameters. +-- The first parameter of the BeforeTemplateSpawnFunc is the raw Template used to spawn the group, the second is the SpawnIndex. +-- @param #SPAWN self +-- @param #function BeforeTemplateSpawnFunc The function to be called before the group spawns. +-- @return #SPAWN +-- @usage +-- +-- -- Declare SpawnObject and call a function when a new Group is spawned. +-- local SpawnObject = SPAWN:New( "SpawnObject" ) +-- :InitLimit( 2, 10 ) +-- :OnBeforeSpawnGroup( function( SpawnTemplate ) + -- Tweaking the template units +-- end +-- ) +-- :SpawnScheduled( 300, 0.3 ) +-- +function SPAWN:OnBeforeTemplateSpawnGroup( BeforeTemplateSpawnFunc ) + --self:F( "OnBeforeSpawnGroup" ) + + self.BeforeTemplateSpawnFunc = BeforeTemplateSpawnFunc + + return self +end + --- Allows to place a CallFunction hook when a new group spawns. -- The provided method will be called when a new group is spawned, including its given parameters. -- The first parameter of the SpawnFunction is the @{Wrapper.Group#GROUP} that was spawned.