Tic-Tac Posted October 12, 2016 Posted October 12, 2016 Hi , putting pride to one side...I have what is a very fundamental question with regard to DCS LUA...I cannot work out how to access attributes of the active player...would someone be able to give me an example of setting a local variable as the player aircraft altitude? Have been at this a couple of days, and although I've learned a lot from the great info and examples on the forum I seem to have a block over some basic principles here! thanks
Grimes Posted October 12, 2016 Posted October 12, 2016 If you know the name of the unit the player is in then it is really simple. local aboveSeaLevel = Unit.getByName('whatever'):getPosition().p.y Above ground level is a little more complex but still pretty straight forward. local pos = Unit.getByName('whatever'):getPosition().p local aboveGroundLevel = pos.y - land.getHeight({x = pos.x, y = pos.z}) The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Tic-Tac Posted October 13, 2016 Author Posted October 13, 2016 thanks for taking the time to reply, that's really helped. One question...so getposition returns a vector with 3 values; x, y, z. So getPosition().p.y is the y is height above sea level, but why the .p, is the fact it's .p significant in any other way than that's just always the syntax, for instance velocity would be getVelocity().p. which ever axis ? or is the .p some kind of switch
Tic-Tac Posted October 13, 2016 Author Posted October 13, 2016 I think I worked this out, but just to check, and in case the explanation is useful to anyone else getting started... getPosition() returns a table of three rows, row 'p' holds the x/y/z coordinates, so if we want height above sea level we are referencing row p of the table, and value y of the vector, hence the .p.y getVelocity however is a straight forward vector, no table, so if we want the y velocity it's just getVelocity.y Correct? thanks again
Grimes Posted October 14, 2016 Posted October 14, 2016 You can also use the function getPoint(), but out of habit I've always used getPosition. getPosition() returns 2 basic forms of information, the orientation and position. Orientation is defined as 3 unit vectors x, y, z. Position is the table p. So by calling getPosition().p it only returns the position value of the function and not the orientation. If I didn't add the p to the end it'd have to look something like: local pos = Unit.getByName('whatever'):getPosition() local aboveGroundLevel = pos.p.y - land.getHeight({x = pos.p.x, y = pos.p.z}) The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Tic-Tac Posted October 15, 2016 Author Posted October 15, 2016 now I'm getting somewhere...Grimes thanks again for taking the time to get back to me
Recommended Posts