Lua Question (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios



Message


Primarchx -> Lua Question (1/4/2016 6:11:55 PM)

I'd like to create a quasi-linked set of RPs for Side B that tracks the movement of Side A.

I see it working something like this..

Use ScenEdit_GetUnit (unit) to extract the latitude and longitude of the Side A unit I want to track. I assume since ScenEdit_GetUnit (unit) returns a Unit data set with that info in it, it should be accessible by putting the pertinent Lat/Long variables it into the ScenEdit_SetReferencePoint (descriptor) with some offsets attached (say Lat/Long +/- 1 minute for each of the four points of a tracking box) which can be set up for Side B.

So every once in a while Side A's ship has this function run on it to create an RP box around it on the B side, accurate at that time.

Not being a Lua wiz, I'm not sure how to extract or address the info I need to make this work.

Any ideas? Thanks!





ckfinite -> RE: Lua Question (1/4/2016 6:15:17 PM)

Yep, that's totally possible, and I did something similar to it for my upcoming Tam Kung scene, to indicate where boats to rescue could be. I can't get the code right now, but will when I get home. In the meantime, if you want, try out the new Q&A site - it's meant for this kind of question, and should be less rubbish to search




Primarchx -> RE: Lua Question (1/4/2016 6:19:10 PM)


quote:

ORIGINAL: ckfinite

Yep, that's totally possible, and I did something similar to it for my upcoming Tam Kung scene, to indicate where boats to rescue could be. I can't get the code right now, but will when I get home. In the meantime, if you want, try out the new Q&A site - it's meant for this kind of question, and should be less rubbish to search


Thanks! I was just on the FAQ site, too, but I was thinking this might need some 'discussion' to clarify so started here. Definitely worth the FAQ site, though!




Yokes -> RE: Lua Question (1/4/2016 7:49:29 PM)

Primarchx,

As you said, you use the "GetUnit" function and assign the results to a variable. You then can access the sub-components of that variable using the "." operator.

Example:
a = ScenEdit_GetUnit({side="SideA", name="Unit Name"})
ID = a.guid

This accesses the GUID. You can do the same with lat/lon.

By the way, you can also do this by enabling "God's eye" mode and setting the reference points as relative to the unit.

Yokes




Primarchx -> RE: Lua Question (1/4/2016 8:09:54 PM)

Thanks, Yokes! Didn't know the God Eye mode would let you do that. That's a nice short cut! I'll use the . operator to access the proper element of the Unit data structure.




ckfinite -> RE: Lua Question (1/4/2016 11:36:04 PM)

Okay, at home now. To use (most) of my code, you'll need my math library, just paste it into a lua script that runs on startup.

Then, here's the function I use to generate a circle with some random error (so that the target isn't always centered):

local function circle_around(side, point, error, radius, number, naming)
	local center = (Quaternion.fromEuler(rng()*error,0,0)*Quaternion.fromEuler(0,0,rng() * 2 * math.pi)) * Quaternion.new(point)
	-- debug, real center ScenEdit_AddReferencePoint(point ^ {side=side, name = naming(0)})
	local angle = Quaternion.fromEuler(radius,0,0)
	local rps = {}
	for i=1,number do
		rp = ScenEdit_AddReferencePoint((angle * center):toPoint() ^ {side=side, name = naming(i)})
		angle = angle * Quaternion.fromEuler(0,0,2*math.pi/number)
		table.insert(rps, rp.guid)
	end
	return rps
end


side is the side you want to make the RPs on, point is a new Point object (make it with Point.new([getunit call])) that represents the point that is the "real" location of the target, error is the maximum distance from the actual center you want to draw the circle, radius is the radius of the circle of RPs, number is the number of RPs to make (if you want to make a square, set this to 4), and naming is a function that given the number of the RP around the circle (from north clockwise), provides the name of the RP (e.g. function (number) return "RP-"..number end)




ckfinite -> RE: Lua Question (1/4/2016 11:45:34 PM)

Oh, and you'll also need

rng = math.random


Somewhere before this. Sorry, my scene uses a custom RNG and I left that in...




Primarchx -> RE: Lua Question (1/5/2016 12:06:20 PM)

Excellent! I've got to dust off my haxor skills one of these days... :>




Gunner98 -> RE: Lua Question (1/5/2016 4:15:16 PM)

Man you guys make my brain hurt![:D][&o]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.703125