Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua Question

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Question Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua Question - 1/4/2016 6:11:55 PM   
Primarchx


Posts: 3102
Joined: 1/20/2013
Status: offline
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!



< Message edited by Primarchx -- 1/4/2016 7:13:13 PM >
Post #: 1
RE: Lua Question - 1/4/2016 6:15:17 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
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

(in reply to Primarchx)
Post #: 2
RE: Lua Question - 1/4/2016 6:19:10 PM   
Primarchx


Posts: 3102
Joined: 1/20/2013
Status: offline

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!

(in reply to ckfinite)
Post #: 3
RE: Lua Question - 1/4/2016 7:49:29 PM   
Yokes

 

Posts: 298
Joined: 3/14/2007
Status: offline
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

(in reply to Primarchx)
Post #: 4
RE: Lua Question - 1/4/2016 8:09:54 PM   
Primarchx


Posts: 3102
Joined: 1/20/2013
Status: offline
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.

(in reply to Yokes)
Post #: 5
RE: Lua Question - 1/4/2016 11:36:04 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
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)

(in reply to Primarchx)
Post #: 6
RE: Lua Question - 1/4/2016 11:45:34 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
Oh, and you'll also need

rng = math.random


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

(in reply to ckfinite)
Post #: 7
RE: Lua Question - 1/5/2016 12:06:20 PM   
Primarchx


Posts: 3102
Joined: 1/20/2013
Status: offline
Excellent! I've got to dust off my haxor skills one of these days... :>

(in reply to ckfinite)
Post #: 8
RE: Lua Question - 1/5/2016 4:15:16 PM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
Man you guys make my brain hurt!

(in reply to Primarchx)
Post #: 9
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Question Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.359