Page 2 of 2

RE: Setting course/speed with lua script?

Posted: Wed Aug 16, 2017 3:43 pm
by somi83
If you add units with lua, you have to add waypoints via lua also, if not there is no need to do it.
Here is the code if you want tho add it with LUA.

Code: Select all

ScenEdit_SetUnit({side="Guatemala", unitname="tank1",course={{latitude='17.0565979083558', longitude='-89.2178220232281'},{latitude='17.0572042889711', longitude='-89.1964406652192'}}, manualSpeed="9"})

I have added this code as an example for tank1. You can try it out. One thing to note is that I have added two waypoint's on purpose, so that you can see how to add two or more waypoint's,

course={{latitude='17.0565979083558', longitude='-89.2178220232281'} is waypoint 1
and {latitude='17.0572042889711', longitude='-89.1964406652192'}} is waypoint 2.
every next waypoint you want to add should be in curly brackets {}, with latitude="" and longitude="".
Latitude and longitude, can be in two formats:

1st: N17.35.25 Just point your mouse on the map where your waypoint sholud be and write it down from the information panel.

2nd: 17.0565979083558 in decimals
Second is easier to get, just point your mouse to the place on the map where your waypoint should be then press CTRL+X , this command will copy latitude and longitude. Then you can paste this inside brackets as a waypoint.

NOTE: (when you paste the lat/long data in the LUA, you should change the semicolon to full stop), because CTRL+X copies lat/long data with semicolon. When you paste it it should look like this latitude='17,0572042889711', longitude='-89,1964406652192', when you change it it should look like this latitude='17.0572042889711', longitude='-89.1964406652192'

If you have any more questions feel free to ask.

RE: Setting course/speed with lua script?

Posted: Thu Aug 17, 2017 5:18 pm
by tjhkkr
ORIGINAL: michaelm

You can set a course for a unit currently.
example...

unit=ScenEdit_GetUnit({Name="Cactus #2"}); print(unit);
-- give the aircraft a random course to follow
x=math.random(-10,10)
y=math.random(-10,10)
-- course is a pair of point (lon/lat)
unit.course={ {lat=34.39 +x, lon=136.09 +y}, {lat=37.9 +y, lon=140.0 +x } }; print(unit);

To see the course..
print( unit.course )

Hey MichaelM...
Thank you... I did not know the random number generator would take a negative.

Did you not also say that to seed the math.random function to math.randomseed( os.time() )?

RE: Setting course/speed with lua script?

Posted: Fri Aug 18, 2017 6:17 am
by michaelm75au
Using 'math.randomseed( os.time() )' on scenario start-up ensures you get a different of random numbers whenever the scenario is started.

RE: Setting course/speed with lua script?

Posted: Tue Aug 22, 2017 5:00 am
by butch4343
ORIGINAL: somi83

If you add units with lua, you have to add waypoints via lua also, if not there is no need to do it.
Here is the code if you want tho add it with LUA.

Code: Select all

ScenEdit_SetUnit({side="Guatemala", unitname="tank1",course={{latitude='17.0565979083558', longitude='-89.2178220232281'},{latitude='17.0572042889711', longitude='-89.1964406652192'}}, manualSpeed="9"})

I have added this code as an example for tank1. You can try it out. One thing to note is that I have added two waypoint's on purpose, so that you can see how to add two or more waypoint's,

course={{latitude='17.0565979083558', longitude='-89.2178220232281'} is waypoint 1
and {latitude='17.0572042889711', longitude='-89.1964406652192'}} is waypoint 2.
every next waypoint you want to add should be in curly brackets {}, with latitude="" and longitude="".
Latitude and longitude, can be in two formats:

1st: N17.35.25 Just point your mouse on the map where your waypoint sholud be and write it down from the information panel.

2nd: 17.0565979083558 in decimals
Second is easier to get, just point your mouse to the place on the map where your waypoint should be then press CTRL+X , this command will copy latitude and longitude. Then you can paste this inside brackets as a waypoint.

NOTE: (when you paste the lat/long data in the LUA, you should change the semicolon to full stop), because CTRL+X copies lat/long data with semicolon. When you paste it it should look like this latitude='17,0572042889711', longitude='-89,1964406652192', when you change it it should look like this latitude='17.0572042889711', longitude='-89.1964406652192'

If you have any more questions feel free to ask.


Somi83

Thanks, you genuinely have helped me save a scenario, I havent managed thus far to manage to get the LAU to follow more than one WP, but that doesnt matter, I can work around that one.

Thanks again mate am indebted

[:)][:)][:)]

Butch

RE: Setting course/speed with lua script?

Posted: Thu Aug 24, 2017 12:06 am
by tjhkkr
ORIGINAL: somi83

If you add units with lua, you have to add waypoints via lua also, if not there is no need to do it.
Here is the code if you want tho add it with LUA.

Code: Select all

ScenEdit_SetUnit({side="Guatemala", unitname="tank1",course={{latitude='17.0565979083558', longitude='-89.2178220232281'},{latitude='17.0572042889711', longitude='-89.1964406652192'}}, manualSpeed="9"})

I have added this code as an example for tank1. You can try it out. One thing to note is that I have added two waypoint's on purpose, so that you can see how to add two or more waypoint's,

course={{latitude='17.0565979083558', longitude='-89.2178220232281'} is waypoint 1
and {latitude='17.0572042889711', longitude='-89.1964406652192'}} is waypoint 2.
every next waypoint you want to add should be in curly brackets {}, with latitude="" and longitude="".
Latitude and longitude, can be in two formats:

1st: N17.35.25 Just point your mouse on the map where your waypoint sholud be and write it down from the information panel.

2nd: 17.0565979083558 in decimals
Second is easier to get, just point your mouse to the place on the map where your waypoint should be then press CTRL+X , this command will copy latitude and longitude. Then you can paste this inside brackets as a waypoint.

NOTE: (when you paste the lat/long data in the LUA, you should change the semicolon to full stop), because CTRL+X copies lat/long data with semicolon. When you paste it it should look like this latitude='17,0572042889711', longitude='-89,1964406652192', when you change it it should look like this latitude='17.0572042889711', longitude='-89.1964406652192'

If you have any more questions feel free to ask.
[/color]

Thank you somi83... I am copying this down to my pad...
That is the thing I struggle with the most with LUA, not the programming but the CMANO tables... this is a HUGE help.