Jump to content

Recommended Posts

Posted

Is there a way to check the health status of runways?

 

I have tried using MIST map object destroyed in polygon to no avail. I haven't tried SLMod but I think it's the exact same function as that in MIST.

 

I'm trying to make a training mission that will check a pilot's hits on a runway without using the SLMod weapons impacting in zone function. I'd like to stay away from SLMod if at all possible for maximum exportability to users. I also want to stay away from putting actual targets on the runway (troops, etc)

 

Am I out of luck?

Posted

If you have FC3 check out the MP mission "Su-27 - Sukhoi Surprise - Coop4"

 

Speed has a scoring system in there for getting hits on the runway using only Mist.

 

I'm pretty sure that most of the mission scripting type of functions from slmod will get ported in Mist, but that is Speeds code and that is up to him.

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

Posted (edited)

Thanks, I'll check it out.

 

Edit: I've searched all the sites I know and can't find this. Can you provide a link?

Edited by johnv2pt0
Posted
Its installed with FC3: C:\Program Files\Eagle Dynamics\DCS World\Mods\aircrafts\Flaming Cliffs\Missions\EN\Multiplayer

 

lol ok, thanks! I don't think I've fired up single player missions in years!

Posted

I've played with Speed's script a bit in an effort to learn some things and have it be more in line with what I will need for one of my missions, but I have a problem

 

Instead of checking 5 segments I've reduced it to 2 (west and east) and once the scoring script get's enough hits in each section it will simply turn a flag on.

 

do 

   local runwayHitsWest = { [1] = {} }
   local runwayHitsEast = { [2] = {} }

   -- Runway segment polygon zones
   local segmentPolys = {}
   segmentPolys[1] = mist.getGroupPoints('segment1')
   segmentPolys[2] = mist.getGroupPoints('segment2')
       
   local tracked_wpns = {}
   
   local shotHandler = function(event)
       if event.id == world.event.S_EVENT_SHOT then
           if event.weapon then 
               local wpn = LuaClass.createFor(Unit, event.weapon.id_)
               if wpn:isExist() then
                   local wpnName = wpn:getTypeName()
                   if wpnName and type(wpnName) == 'string' and ((wpnName:find('BetAB_500') or wpnName:find('BetAB_500ShP') or wpnName:find('Mk_82') or wpnName:find('Mk_84') or wpnName:find('Mk_82AIR') or wpnName:find('GBU_31') or wpnName:find('GBU_38') or wpnName:find('GBU_10') or wpnName:find('GBU_12') or wpnName:find('FAB_500') or wpnName:find('FAB_250') or wpnName:find('FAB_500P') or wpnName:find('FAB_250P') or wpnName:find('FAB_500_3'))) then
                       local init = LuaClass.createFor(Unit, event.initiator.id_)
                       local init_name = ''
                       if init:isExist() then
                           init_name = init:getName()
                       end
                       tracked_wpns[event.weapon.id_] = { wpn = wpn, init = init_name, pos = wpn:getPosition().p, dir = wpn:getPosition().x }
                   end
               end
           end
       end
   end
   mist.addEventHandler(shotHandler)

   local function track_wpns()
       mist.scheduleFunction(track_wpns, {}, timer.getTime() + 0.05)  -- reschedule first
       
       for wpn_id_, wpnData in pairs(tracked_wpns) do
           if wpnData.wpn:isExist() then  -- just update position and direction.
               wpnData.pos = wpnData.wpn:getPosition().p
               wpnData.dir = wpnData.wpn:getPosition().x
           else -- wpn no longer exists, must be dead.
               tracked_wpns[wpn_id_] = nil -- remove from tracked weapons first.
               local ip = land.getIP(wpnData.pos, wpnData.dir, 20)  -- terrain intersection point with weapon's nose.  Only search out 20 meters though.
               local impactPoint
               if not ip then -- use last position
                   impactPoint = wpnData.pos
               else -- use intersection point
                   impactPoint = ip
               end
               for i = 1, #segmentPolys do
                   if mist.pointInPolygon(impactPoint, segmentPolys[i]) then -- weapon impacted in West runway segment!
                       runwayHitsWest[i][#runwayHitsWest[i] + 1] = wpnData.init
				end
			end		
			for i = 2, #segmentPolys do
                   if mist.pointInPolygon(impactPoint, segmentPolys[i]) then -- weapon impacted in East runway segment!
                       runwayHitsEast[i][#runwayHitsEast[i] + 1] = wpnData.init		
				end
			end
           end
       end
   end
   
   track_wpns()
   
   function scoreMission()    -- for testing right now
       local hitBonus = 50
       local reqPoints = 150
   
       local scoreTotal = 0
	local scoreWest = 0
	local scoreEast = 0
       
	local westEndFlag = 2000
	local eastEndFlag = 2001
           
       for i = 1, #runwayHitsWest do
           local hitScoreWest = 0
            for i = 1, #runwayHitsWest[i] do
               hitScoreWest = hitScoreWest + hitBonus
            end
            scoreWest = scoreWest + hitScoreWest
       end
       
	for i = 2, #runwayHitsEast do
           local hitScoreWest = 0
            for i = 2, #runwayHitsEast[i] do
               hitScoreEast = hitScoreEast + hitBonus
            end
            scoreEast = scoreEast + hitScoreEast
       end
	
       if scoreWest >= reqPoints then
          trigger.action.setUserFlag(westEndFlag, true)
	end
	
	if scoreEast >= reqPoints then
          trigger.action.setUserFlag(eastEndFlag, true)
	end
	
end
   
end

 

It's working fine for the first segment but not for the second. Where am I going wrong?

Posted (edited)
I've played with Speed's script a bit in an effort to learn some things and have it be more in line with what I will need for one of my missions, but I have a problem

 

Instead of checking 5 segments I've reduced it to 2 (west and east) and once the scoring script get's enough hits in each section it will simply turn a flag on.

 

 

It's working fine for the first segment but not for the second. Where am I going wrong?

 

There were a couple problems. Try the attached code and see if it works.

 

do 

local runwayHits = { [1] = {}, [2] = {}, }

-- Runway segment polygon zones
local segmentPolys = {}
segmentPolys[1] = mist.getGroupPoints('segment1')
segmentPolys[2] = mist.getGroupPoints('segment2')

local tracked_wpns = {}

local shotHandler = function(event)
	if event.id == world.event.S_EVENT_SHOT then
		if event.weapon then 
			local wpn = LuaClass.createFor(Unit, event.weapon.id_)
			if wpn:isExist() then
				local wpnName = wpn:getTypeName()
				if wpnName and type(wpnName) == 'string' and ((wpnName:find('BetAB_500') or wpnName:find('BetAB_500ShP') or wpnName:find('Mk_82') or wpnName:find('Mk_84') or wpnName:find('Mk_82AIR') or wpnName:find('GBU_31') or wpnName:find('GBU_38') or wpnName:find('GBU_10') or wpnName:find('GBU_12') or wpnName:find('FAB_500') or wpnName:find('FAB_250') or wpnName:find('FAB_500P') or wpnName:find('FAB_250P') or wpnName:find('FAB_500_3'))) then
					local init = LuaClass.createFor(Unit, event.initiator.id_)
					local init_name = ''
					if init:isExist() then
						init_name = init:getName()
					end
					tracked_wpns[event.weapon.id_] = { wpn = wpn, init = init_name, pos = wpn:getPosition().p, dir = wpn:getPosition().x }
				end
			end
		end
	end
end
mist.addEventHandler(shotHandler)

local function track_wpns()
	mist.scheduleFunction(track_wpns, {}, timer.getTime() + 0.05)  -- reschedule first

	for wpn_id_, wpnData in pairs(tracked_wpns) do
		if wpnData.wpn:isExist() then  -- just update position and direction.
			wpnData.pos = wpnData.wpn:getPosition().p
			wpnData.dir = wpnData.wpn:getPosition().x
		else -- wpn no longer exists, must be dead.
			tracked_wpns[wpn_id_] = nil -- remove from tracked weapons first.
			local ip = land.getIP(wpnData.pos, wpnData.dir, 20)  -- terrain intersection point with weapon's nose.  Only search out 20 meters though.
			local impactPoint
			if not ip then -- use last position
				impactPoint = wpnData.pos
			else -- use intersection point
				impactPoint = ip
			end
			for i = 1, #segmentPolys do
				if mist.pointInPolygon(impactPoint, segmentPolys[i]) then -- weapon impacted in West runway segment!
					runwayHits[i][#runwayHits[i] + 1] = wpnData.init
				end
			end		
		end
	end
end

track_wpns()

function scoreMission()    -- for testing right now
	local hitBonus = 50
	local reqPoints = 150

	local scoreTotal = 0
	local scoreWest = 0
	local scoreEast = 0

	local westEndFlag = 2000
	local eastEndFlag = 2001

	local runwayHitsWest = runwayHits[1]
	local runwayHitsEast = runwayHits[2]

	for i = 1, #runwayHitsWest do
		local hitScoreWest = 0
		for i = 1, #runwayHitsWest[i] do
			hitScoreWest = hitScoreWest + hitBonus
		end
		scoreWest = scoreWest + hitScoreWest
	end

	for i = 1, #runwayHitsEast do
		local hitScoreEast = 0
		for i = 1, #runwayHitsEast[i] do
			hitScoreEast = hitScoreEast + hitBonus
		end
		scoreEast = scoreEast + hitScoreEast
	end

	if scoreWest >= reqPoints then
		trigger.action.setUserFlag(westEndFlag, true)
	end

	if scoreEast >= reqPoints then
		trigger.action.setUserFlag(eastEndFlag, true)
	end

end

end

Edited by Speed

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Posted (edited)

Thanks Speed, I'll give it a go and try to learn some more poop.

 

EDIT: It works great, thanks again for the help

Edited by johnv2pt0
  • 1 year later...
Posted

Fixed his script. The only thing I changed was the shotHandler function. But I copied the whole thing in there anyways.

 

do 

local runwayHits = { [1] = {}, [2] = {}, }

-- Runway segment polygon zones
local segmentPolys = {}
segmentPolys[1] = mist.getGroupPoints('segment1')
segmentPolys[2] = mist.getGroupPoints('segment2')

local tracked_wpns = {}

local shotHandler = function(event)
	if event.id == world.event.S_EVENT_SHOT then
		if event.weapon then 
			local wpn = event.weapon
			if wpn:isExist() then
				local wpnName = wpn:getTypeName()
				if wpnName and type(wpnName) == 'string' and ((wpnName:find('BetAB_500') or wpnName:find('BetAB_500ShP') or wpnName:find('Mk_82') or wpnName:find('Mk_84') or wpnName:find('Mk_82AIR') or wpnName:find('GBU_31') or wpnName:find('GBU_38') or wpnName:find('GBU_10') or wpnName:find('GBU_12') or wpnName:find('FAB_500') or wpnName:find('FAB_250') or wpnName:find('FAB_500P') or wpnName:find('FAB_250P') or wpnName:find('FAB_500_3'))) then
					local init = event.initiator
					local init_name = ''
					if init:isExist() then
						init_name = init:getName()
					end
					tracked_wpns[event.weapon.id_] = { wpn = wpn, init = init_name, pos = wpn:getPosition().p, dir = wpn:getPosition().x }
				end
			end
		end
	end
end
mist.addEventHandler(shotHandler)

local function track_wpns()
	mist.scheduleFunction(track_wpns, {}, timer.getTime() + 0.05)  -- reschedule first

	for wpn_id_, wpnData in pairs(tracked_wpns) do
		if wpnData.wpn:isExist() then  -- just update position and direction.
			wpnData.pos = wpnData.wpn:getPosition().p
			wpnData.dir = wpnData.wpn:getPosition().x
		else -- wpn no longer exists, must be dead.
			tracked_wpns[wpn_id_] = nil -- remove from tracked weapons first.
			local ip = land.getIP(wpnData.pos, wpnData.dir, 20)  -- terrain intersection point with weapon's nose.  Only search out 20 meters though.
			local impactPoint
			if not ip then -- use last position
				impactPoint = wpnData.pos
			else -- use intersection point
				impactPoint = ip
			end
			for i = 1, #segmentPolys do
				if mist.pointInPolygon(impactPoint, segmentPolys[i]) then -- weapon impacted in West runway segment!
					runwayHits[i][#runwayHits[i] + 1] = wpnData.init
				end
			end		
		end
	end
end

track_wpns()

function scoreMission()    -- for testing right now
	local hitBonus = 50
	local reqPoints = 150

	local scoreTotal = 0
	local scoreWest = 0
	local scoreEast = 0

	local westEndFlag = 2000
	local eastEndFlag = 2001

	local runwayHitsWest = runwayHits[1]
	local runwayHitsEast = runwayHits[2]

	for i = 1, #runwayHitsWest do
		local hitScoreWest = 0
		for i = 1, #runwayHitsWest[i] do
			hitScoreWest = hitScoreWest + hitBonus
		end
		scoreWest = scoreWest + hitScoreWest
	end

	for i = 1, #runwayHitsEast do
		local hitScoreEast = 0
		for i = 1, #runwayHitsEast[i] do
			hitScoreEast = hitScoreEast + hitBonus
		end
		scoreEast = scoreEast + hitScoreEast
	end

	if scoreWest >= reqPoints then
		trigger.action.setUserFlag(westEndFlag, true)
	end

	if scoreEast >= reqPoints then
		trigger.action.setUserFlag(eastEndFlag, true)
	end

end

end

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

  • 2 years later...
Posted

It works, you just have two minor issues preventing it from working.

 

Two issues:

 

1. The zone defining the runway is was named "runwayzone #001" in the editor, the script was looking for "runwayzone".

 

2. You have to call the scoreMission() function because it isn't called automatically. I think the mission that used this script had a condition like Once a unit enters a zone and then exists it, it will run the scoreMission() function.

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

  • Recently Browsing   0 members

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