Jump to content

Passing a vec3 instead of a triggerzone for mist.flagFunc.mapobjs_dead_zones


LFCChameleon_Silk

Recommended Posts

Anyone have any ideas on how to pass a vec3 coordinate for mist.flagFunc.mapobjs_dead_zones?

I know it accepts a table of zones or triggerZone string name but that is not suitable for what i want.

 

Strike_Area_Zone = {
                    point = {y = buildPsn.y, x = buildPsn.x, z = buildPsn.z},
                    radius = 10000
                    }

 

I want to be able to define the area for it to check dynamically and not with a preset triggerzone, I can't pass my table above to it as it must not know of the triggerzone (since its dynamically created)

 

I'm at a loss... spent all day trying to make my strike mission progress track. surely there is a way to either modify the function in MIST to accept a vec3.

on another note what is up with not being able to name statics in the editor. what kind of madness is this?

any takers? Grimes? anyone 🤔

Link to comment
Share on other sites

All it does is it searches mist.DBs.deadObjects table for the category to see if an object represents a map object and then checks the distance from a given point. This is the code it ultimately uses. Just replace the bit of code where it references zones, though its not a flag function, so you have to manually call it whenever you want it to do the check and set a flag or do whatever action once the conditions are met. Realized it'd be a good idea to have a function that works with point so I'm adding a mist.getDeadMapObjectsFromPoint function now. As is life with DCS I decided to add an object filter to look for certain object types but the results are not what I expected and is a possible DCS bug. 

	local map_objs = {}
	local zones = {}
	for i = 1, #zone_names do
		if mist.DBs.zonesByName[zone_names[i]] then
			zones[#zones + 1] = mist.DBs.zonesByName[zone_names[i]]
		end
	end
	for obj_id, obj in pairs(mist.DBs.deadObjects) do
		if obj.objectType and obj.objectType == 'building' then --dead map object
			for i = 1, #zones do
				if ((zones[i].point.x - obj.objectPos.x)^2 + (zones[i].point.z - obj.objectPos.z)^2)^0.5 <= zones[i].radius then
					map_objs[#map_objs + 1] = mist.utils.deepCopy(obj)
				end
			end
		end
	end
	return map_objs

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

yeah I had just started to dissect the function after a day of frustration once I realized the problem. I think it would be a good addition. Then I have to solve the problem of removing the statics that got hit from the map.. which I'm also a bit unclear about because it doesn't seem like dynaddstatic is giving it a name or group name (but I have yet to investigate the group data for them) on the bright side these are last of the obstacles left for my magnum opus mission and script.

Link to comment
Share on other sites

working code in next post down

Haven't tried it yet but maybe you can see issues as you are more well versed in LUA. figured it would probably be better to have it as a flagFunc since that is still the behavior I wanted. there is parts that maybe I butchered as I don't quite understand all of it.


Edited by LFCChameleon_Silk
antiquated code attempt
Link to comment
Share on other sites

if anyone wants to add a new function to mist copy these into your MIST LUA (at least until Grimes adds it)

function mist.getDeadMapObjsAtPoint(locations)
	-- location: a table or multiple tables formated in the style of a preplaced ME triggerZone
	-- returns: table of dead map objects (indexed numerically)
	local map_objs = {}

	for obj_id, obj in pairs(mist.DBs.deadObjects) do
		if obj.objectType and obj.objectType == 'building' then --dead map object
			for i = 1, #locations do
				if ((locations[i].point.x - obj.objectPos.x)^2 + (locations[i].point.z - obj.objectPos.z)^2)^0.5 <= locations[i].radius then
					map_objs[#map_objs + 1] = mist.utils.deepCopy(obj)
				end
			end
		end
	end
	return map_objs
end
                                                                                                                                      
                                                                                                                                      		function mist.flagFunc.mapobjs_dead_point(vars)
		--[[vars needs to be:
location = a table or mutliple tables that are identical to a ME triggerzone
flag = number,
stopflag = number or nil,
req_num = number or nil

AND used by function,
initial_number

]]
		-- type_tbl
		local type_tbl = {
			[{'locations'}] = {'table'},
			flag = {'number', 'string'},
			[{'stopflag', 'stopFlag'}] = {'number', 'string', 'nil'},
			[{'req_num', 'reqnum'}] = {'number', 'nil'},
		}

		local err, errmsg = mist.utils.typeCheck('mist.flagFunc.mapobjs_dead_point', type_tbl, vars)
		assert(err, errmsg)
		local locations = vars.locations
		local flag = vars.flag
		local stopflag = vars.stopflag or vars.stopFlag or -1
		local req_num = vars.req_num or vars.reqnum or 1
		local initial_number = vars.initial_number

		if not initial_number then
			initial_number = #mist.getDeadMapObjsAtPoint(locations)
		end

		if stopflag == -1 or (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
			if (#mist.getDeadMapObjsAtPoint(locations) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == 0 then
				trigger.action.setUserFlag(flag, true)
				return
			else
				mist.scheduleFunction(mist.flagFunc.mapobjs_dead_point, {{locations = locations, flag = flag, stopflag = stopflag, req_num = req_num, initial_number = initial_number}}, timer.getTime() + 1)
			end
		end
	end

here is an example of its use

zoneUsed = 'some triggerZone'
buildPsn = mist.getRandomPointInZone(zoneUsed, zoneUsed.radius)	-- get a random point in that triggerZone area


Strike_Area_Zone = { -- format a table to look exactly like a triggerZone but with the new point we want and the new desired radius to check for dead map objects
					point = {y = buildPsn.y, x = buildPsn.x, z = buildPsn.z},
					radius = 10000
					}

mist.flagFunc.mapobjs_dead_point{locations = {Strike_Area_Zone}, flag = 1001, req_num = 1} -- when 1 map object is dead in that area toggle flag 1001 to be true

it should also work with a list of tables like this: mist.flagFunc.mapobjs_dead_point{locations = {strike1, strike2,strike3}. flag = 1001, req_num = 1}

 

Thanks Grimes for all your hard work, hope this helps someone else out. pay it forward. feel free to modify or use directly in any MIST update Grimes, much thanks!


Edited by LFCChameleon_Silk
remove my debug stuff
Link to comment
Share on other sites

  • Recently Browsing   0 members

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