Jump to content

Recommended Posts

Posted

Hello,

 

I'm trying to prepare a script for range training of helicopter in compliance with FM4-03-140 training targets description. Since I'm not that good in lua programming, I'm trying to build it by steps.

 

The first step is a modification of SNAFU's* excellent range script for single target, this one:

http://forums.eagle.ru/showthread.php?t=109174

 

I modified the script so that:

- S8 rockets are taken into account

- The script look at the closest target of any group "tagged" in its name in a particoular way (I will have only one, so I'm not worried about multiple result for each tagged group).

- The script only give an offset distance and an evaluation about the 10 and 50 metres distance

 

But before moving to the TEA range implementation, I had the common problem about measuring: Only the last rocket is taken into account. As said here:

http://forums.eagle.ru/showthread.php?t=109174&page=5

 

Well, I'm not sufficiently experienced to understand how to implement the single shot event tracking: given that I may like a "1 second" time frame from first and least launch of the salvo, Can you give me some hint or some example?

 

Thanks!

 

PS:

 

this is the actual code:

 

-- RANGE VARIABLES
local VerticalOffset = 2 -- variable that define when the "gimme the offset" is calculated.
local RangeGroupTag = "140rngTGT"


RocketHandler = {}												
function RocketHandler:onEvent(event)
	if event.id == world.event.S_EVENT_SHOT then
	
		RocketInit = event.initiator									
		RocketInitGroup = RocketInit:getGroup()
		RocketInitGroupName = event.initiator:getName() --"Prova" --RocketInitGroup.name
		--_alpha = mist.getHeading(RocketInit)

			_ordnance = event.weapon									
			_ordnanceName = _ordnance:getTypeName()							
			if (_ordnanceName == "weapons.nurs.C_8" or _ordnanceName == "weapons.nurs.C_8OFP2" or _ordnanceName == "weapons.nurs.S-8KOM" or _ordnanceName == "weapons.nurs.C_8OM" or _ordnanceName == "weapons.nurs.C_8CM" or _ordnanceName == "weapons.nurs.HYDRA_70_M156") then
			
				function TrackRocket()
					local RocketPos = _ordnance:getPoint()
					local _time = timer.getTime()
							
					if RocketPos.y < land.getHeight({x = RocketPos.x, y = RocketPos.z}) + VerticalOffset then

						local minimumoffset = 100000
						local NearestTargetPos = ""
						local NearestTargeName = ""
						local NearestTargetOffset = ""			
						
						-- check for nearest target
						for _, tgtData in pairs(mist.DBs.aliveUnits) do
							if string.find(tgtData.groupName,RangeGroupTag) then
							
								local tgtName = tgtData.unitName
								local tgtPos = tgtData.pos
								local tgtType = tgtData.type

								local offsetDist = mist.utils.get2DDist(RocketPos, tgtPos)
								
								if minimumoffset > offsetDist then 
									minimumoffset = offsetDist 
									NearestTargetPos = tgtPos 
									NearestTargeName = tgtName
									NearestTargetOffset = offsetDist
								end								
							end
						end
						
						--give the text
						if NearestTargetOffset < 10 then -- cerchio interno AWWS
							trigger.action.outText(RocketInitGroupName .. ", il colpo è a ".. string.format("%.1f",NearestTargetOffset) .. " mt dal bersaglio " .. NearestTargeName .. ", nel cerchio da 10 mt", 10)
						elseif NearestTargetOffset < 50 then -- cerchio esterno AWWS
							trigger.action.outText(RocketInitGroupName .. ", il colpo è a ".. string.format("%.1f",NearestTargetOffset) .. " mt dal bersaglio " .. NearestTargeName .. ", nel cerchio da 50 mt", 10)
						else -- if NearestTargetOffset < 5000 then -- safety check, può diventare solo else.
							trigger.action.outText(RocketInitGroupName .. ", il colpo è a ".. string.format("%.1f",NearestTargetOffset) .. " mt dal bersaglio " .. NearestTargeName .. ", fuori dal cerchio da 50 mt", 10)
						end
							
						return -- a che serve?
					end
					
					return timer.getTime() + 0.005					
				end
				
				timer.scheduleFunction(TrackRocket, nil, timer.getTime() + 1)
				--mist.scheduleFunction(TrackRocket,{},timer.getTime() + 1,0.005,60)
				
			end
	end
end
world.addEventHandler(RocketHandler)

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Posted

Maybe.... is there an "events table" or something similar? Or a way in witch I can assign a different "TrackRocket()" function to every shot?

 

:(

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Posted

No suggestion, I think it's more complicated that it seems.. :(. I'll try to work it out...

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Posted

Ok I found this temporary solution (not the best, but... it's ok):

 

	-- RANGE VARIABLES
local VerticalOffset = 2 -- variable that define when the "gimme the offset" is calculated.
local RangeGroupTag = "140rngTGT"
local SalvoDelay = 1 -- second
local ProduceLog = true -- if this is set as "true" it will save any tracked shot to a CSV file.




local HitTable = {}


-- this one track every shot to a single target in a 1000 mt distance range
RocketHandler = {}												
function RocketHandler:onEvent(event)
	if event.id == world.event.S_EVENT_SHOT then
	
		RocketInit = event.initiator									
		RocketInitGroup = RocketInit:getGroup()
		RocketInitGroupName = event.initiator:getName() --"Prova" --RocketInitGroup.name

		_ordnance = event.weapon									
		_ordnanceName = _ordnance:getTypeName()			
		
		if (_ordnanceName == "weapons.nurs.C_8" or _ordnanceName == "weapons.nurs.C_8OFP2" or _ordnanceName == "weapons.nurs.S-8KOM" or _ordnanceName == "weapons.nurs.C_8OM" or _ordnanceName == "weapons.nurs.C_8CM" or _ordnanceName == "weapons.nurs.HYDRA_70_M156") then
			
			
			function TrackRocket()
				local RocketPos = _ordnance:getPoint()
				local _time = timer.getTime()
						
				if RocketPos.y < land.getHeight({x = RocketPos.x, y = RocketPos.z}) + VerticalOffset then

					local minimumoffset = 100000
					local NearestTargetPos = ""
					local NearestTargeName = ""
					local NearestTargetOffset = ""			
					
					-- check for nearest target
					for _, tgtData in pairs(mist.DBs.aliveUnits) do
						if string.find(tgtData.groupName,RangeGroupTag) then
						
							local tgtName = tgtData.unitName
							local tgtPos = tgtData.pos
							local tgtType = tgtData.type

							local offsetDist = mist.utils.get2DDist(RocketPos, tgtPos)
							
							if minimumoffset > offsetDist then 
								minimumoffset = offsetDist 
								NearestTargetPos = tgtPos 
								NearestTargeName = tgtName
								NearestTargetOffset = offsetDist
							end								
						end
					end
					
					--[[give the text
					if NearestTargetOffset < 10 then -- cerchio interno AWWS
						trigger.action.outText(RocketInitGroupName .. ", il colpo è a ".. string.format("%.1f",NearestTargetOffset) .. " mt dal bersaglio " .. NearestTargeName .. ", nel cerchio da 10 mt", 10)
					elseif NearestTargetOffset < 50 then -- cerchio esterno AWWS
						trigger.action.outText(RocketInitGroupName .. ", il colpo è a ".. string.format("%.1f",NearestTargetOffset) .. " mt dal bersaglio " .. NearestTargeName .. ", nel cerchio da 50 mt", 10)
					else -- if NearestTargetOffset < 5000 then -- safety check, può diventare solo else.
						trigger.action.outText(RocketInitGroupName .. ", il colpo è a ".. string.format("%.1f",NearestTargetOffset) .. " mt dal bersaglio " .. NearestTargeName .. ", fuori dal cerchio da 50 mt", 10)
					end
					]]
					if NearestTargetOffset < 1000 then
						HitTable[#HitTable + 1] = { pilot = RocketInitGroupName, offset = NearestTargetOffset, target = NearestTargeName, timeShot = _time}
					end
					
					return -- a che serve?
					end						
				return timer.getTime() + 0.005					
			end
			
			timer.scheduleFunction(TrackRocket, nil, timer.getTime() + 1)
			--mist.scheduleFunction(TrackRocket,{},timer.getTime() + 1,0.005,60)
			
		end
	end
end
world.addEventHandler(RocketHandler)


function iterateHit()
	local message = ""
	for hitID, hitData in pairs(HitTable) do
		if hitID then
			if hitData.offset < 10 then
				message = message .. "Lancio di " .. hitData.pilot .. ", il colpo è a ".. string.format("%.1f",hitData.offset) .. " mt dal bersaglio " .. hitData.target .. ", nel cerchio da 10 mt" .. "\n"
			elseif hitData.offset < 50 then
				message = message .. "Lancio di " .. hitData.pilot .. ", il colpo è a ".. string.format("%.1f",hitData.offset) .. " mt dal bersaglio " .. hitData.target .. ", nel cerchio da 50 mt" .. "\n"	
			elseif hitData.offset < 1000 then
				message = message .. "Lancio di " .. hitData.pilot .. ", il colpo è a ".. string.format("%.1f",hitData.offset) .. " mt dal bersaglio " .. hitData.target .. ", fuori dal cerchio da 50 mt" .. "\n"	
			end
			table.remove(HitTable, hitID)
		end
	end
	trigger.action.outText(message,15)
end
mist.scheduleFunction(iterateHit,{},timer.getTime() + 1,5,nil)


 

What it does is to put every ON SHOT event data in a table that is read every once a 5 seconds. If there are data stored in the table, it prints out a text and remove it from the table. The overlapping messages is prevented by concatenating text in multiple lines and printing out the summa.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Posted

Well I noticed that sadly the script tracks correctly every couple of rockets fired... so, I have to assume that when a coulple of rockets its fired, there is only one "on-shot" event generated... even if I check the rocket position every 0.0001 secs.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

  • Recently Browsing   0 members

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