Jump to content

Recommended Posts

Posted

Hey, So i've got the following lua function:

 

StaticObject.getByName('StaticObjectName'):destroy()

 

I can use this to delete a single Static object, however i wish to delete >10 at the same time, rather than re-writing this line with a new object name each time. Is it possible to automate it to delete all static objects with a specific prefix on their name? something like DeleteMe #01, DeleteMe #02 and so on.

Posted

I run this MOOSE script at the beginning of a mission (300 seconds in) to disappear a bunch of static Hornets from the fantail of the carrier. All of the Hornets names start with zDS_. I think it was Hardcard that helped me figure it out.

 

 local HornetSet = SET_STATIC:New()
:FilterPrefixes("zDS_")
:FilterStart()

local function HornetDestroy(HornetUnit)

HornetUnit:Destroy()

end

HornetSet:ForEachStatic(
function(HornetUnit)

timer.scheduleFunction(HornetDestroy, HornetUnit, timer.getTime() + 300 )

end
)

9800X3D,  MSI 5080 , G.SKILL 64GB DDR5-6000, Win 11, MSI X870, 2/4TB nVME, Quest 3, OpenHornet Pit 

Posted (edited)

This code should help, sorry, I mis-read what you posted earlier; for some reason I thought you wanted to delete some on a trigger at one time and some and a later time. This code works for me:

 

do
local statObj = coalition.getStaticObjects(2) --(1=Red 2=Blue)
for i, static in pairs(statObj) do
	local staticName = static:getName()
		if string.match(staticName, "StaticDelete.*") then --test names are "StaticDelete" the .* tells is to ignore anything after this.
			static:destroy()
		end
end
end

Edited by shnicklefritz
Just re-read your needs, sorry.
Posted

Thanks for both the moose and lua suggestions!

 

I'l have a play around, try and disect/understand them better.

Somewhat of a beginner so i apriciate the help.

 

I've used Shnicklefritz suggestion (it works great!) as it's not dependent on other scripts, but Moose is an interesting extension for when im somewhat more savy on script!

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...