crispy12 Posted July 27, 2021 Posted July 27, 2021 I'm trying to explode units which I've spawned with MOOSE. Or some way to remove them temporarily. This is part of a BFM random spawn setup. Spawn_BFM1 = SPAWN :New( "Spawn BFM1" ) :InitLimit(2, 2) :InitRandomizeZones( AirZoneTable ) :InitRandomizeTemplate(AirTemplateTable) :SpawnScheduled( 1, 0 ) :Spawn() trigger.action.explosion(Unit.getByName('Spawn BFM1#001'):getPosition().p, 100) trigger.action.explosion(Unit.getByName('Spawn BFM1#002'):getPosition().p, 100) I've been using this code but it doesn't quite seem to work Each of the blocks of code are run via F10 triggers Any suggestions?
Wizxrd Posted July 27, 2021 Posted July 27, 2021 You can use :OnSpawnGroup() which would look something like this: Spawn_BFM1 = SPAWN :New( "Spawn BFM1" ) :InitLimit(2, 2) :InitRandomizeZones( AirZoneTable ) :InitRandomizeTemplate(AirTemplateTable) :SpawnScheduled( 1, 0 ) :OnSpawnGroup( function( SpawnGroup ) BFM1GroupName = SpawnGroup.GroupName end ) :Spawn() Then to destroy them individually you just need to use :GetUnit(UnitNumber) and use :Destroy() on that same variable. BFM1Unit1 = GROUP:FindByName(BFM1GroupName):GetUnit(1) BFM1Unit1:Destroy() BFM1Unit2 = GROUP:FindByName(BFM1GroupName):GetUnit(2) BFM1Unit2:Destroy() If you have any questions feel free to ask, I hope this helps some! 2
Dangerzone Posted July 27, 2021 Posted July 27, 2021 (edited) The above will remove them without an explosion I believe (which is part of your "some way to remove them temporary"), of course you will need to recreate them. If you're wanting an actual explosion, then you could possibly use something along the lines such as: local gp = GROUP:FindByName(BFM1GroupName) for i = 1, gp:CountAliveUnits() do gp:GetUnit(i):Explode(power,delay) end (replace power and delay with the power of the explosion you want, and delay accordingly). I think Wizxrd's :destroy() is a more elegant solution - but if you would prefer explosions - this could work. (Please note - not fully tested - just throwing the idea out there) Edited July 27, 2021 by Dangerzone 1
Wizxrd Posted July 27, 2021 Posted July 27, 2021 (edited) 17 minutes ago, Dangerzone said: local gp = GROUP:FindByName(BFM1GroupName) for i = 1, gp:CountAliveUnits() do gp:GetUnit(i):Explode(power,delay) end Adding to this (yes it does work btw, I've tested for you ), if you wanted to destroy the group as a whole it could be flattened to this: local Units = GROUP:FindByName(BFM1GroupName):GetUnits() for id, data in pairs(Units) do Unit.getByName(data:GetName()):destroy() end But as danger mentioned this would be for if you just wanted to remove the group with no visuals Edited July 27, 2021 by Wizxrd 2
crispy12 Posted July 27, 2021 Author Posted July 27, 2021 Perfect... you guys answered my question completely
Recommended Posts