Jump to content

Lua, possible MiST issue; and Escort Task with Late Activation


shnicklefritz

Recommended Posts

First, which would solve the second question, does anyone know of a way to get a unit to perform the escort task when both aircraft are set to late activation? I am using a do script command in the unit route options to complete this currently rather than the perform task feature. Either way, the result is the same, no escorting is being had.

 

To get around this I have been having to forego the late activation and instead call the destroy() function. This destroys the groups; then I respawn them with MiST. This works great and escort service is working. However, leading into my second question, when I call the destroy() function it messes up another function of mine (reconInZone, below), which works perfectly until the destroy function is called. Please see below. The only thing that I can think of is that it is screwing with the mist.makUnitTable(), because as I said, the function works great until the destroy() function is introduced, whether it's by do script, in the same file, or delayed long after the reconInZone function has run.

 

Any thoughts, input, and recommendations are welcome and appreciated. Thank you.

 

--Problem code
local despawnAirAtStart = {
"Red4: An-30M",
"Red4: F-4E",
"Red4: F-4E_2",
"Red4: F-5E",
"Red4: M-2000C",
"Red4: MiG-21Bis",
"Red4: MiG-23MLD",
"Red4: MiG-25PD",
"Red4: MiG-25RBT",
"Red4: MiG-29S",
"Red4: Su-24MR",
"Red4: Su-24MR_2",
"Red4: Su-30",
"Red4: Tu-142",

}
do

for i = 1, #despawnAirAtStart do
local uName = Unit.getByName(despawnAirAtStart[i])
local despawn = uName:destroy()

end
end

 

--Works great
reconFlagCounter = 0

function reconInZone()
local allRedAircraft = mist.makeUnitTable({"[red][plane]"})
for i = 1, #allRedAircraft do

	if Unit.getByName(allRedAircraft[i]):getTypeName() == "An-30M" or "Su-24MR" or "MiG-25RBT" or "Tu-142" then
	local zUnit = Unit.getByName(allRedAircraft[i])
	local zType = zUnit:getTypeName()
	local pos = zUnit:getPosition().p
	local zone = trigger.misc.getZone("Red1: InnerReconZone")
	local oZone = trigger.misc.getZone("Red1: OuterReconZone")
	
		if (((pos.x - zone.point.x)^2 + (pos.z - zone.point.z)^2)^0.5 <= zone.radius) then
		
			if zType == "An-30M" then
			reconFlagCounter = reconFlagCounter + 10
			end
			if zType == "Su-24MR" then
			reconFlagCounter = reconFlagCounter + 10
			end	
			if zType == "MiG-25RBT" then
			reconFlagCounter = reconFlagCounter + 4
			end
			if zType ==	"Tu-142" then
			reconFlagCounter = reconFlagCounter + 20
			end

				else
				if (((pos.x - oZone.point.x)^2 + (pos.z - oZone.point.z)^2)^0.5 <= oZone.radius) and (((pos.x - zone.point.x)^2 + (pos.z - zone.point.z)^2)^0.5 > zone.radius) then
					if zType == "An-30M" then
					reconFlagCounter = reconFlagCounter + 5
					end
					if zType == "Su-24MR" then
					reconFlagCounter = reconFlagCounter + 5
					end	
					if zType == "MiG-25RBT" then
					reconFlagCounter = reconFlagCounter + 2
					end
					if zType ==	"Tu-142" then
					reconFlagCounter = reconFlagCounter + 10
					end

				end
		end
	end
	
end
if reconFlagCounter >= 500 then
trigger.action.setUserFlag("ReconPoints", 500)
else
trigger.action.setUserFlag("ReconPoints", reconFlagCounter)
end
end

mist.scheduleFunction(reconInZone, {}, timer.getTime() + 5, 20)


Edited by shnicklefritz
Grammar
Link to comment
Share on other sites

If I had to guess there error is occurring at the line corresponding to the following line?

 

if Unit.getByName(allRedAircraft[i]):getTypeName() == "An-30M" or "Su-24MR" or "MiG-25RBT" or "Tu-142" then

 

If so the issue is because when you destroy a unit it removes it from the scripting engine. So that Unit.getByName(allRedAircraft) returns nil. So it is like running nil:getTypeName(), which will cause the error. You need to add another check if the unit object exists. At the basics

 

if Unit.getByName(allRedAircraft[i]) then
 if Unit.getByName(allRedAircraft[i]):getTypeName() ... etc 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • Recently Browsing   0 members

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