Setting course/speed with lua script?

Take command of air and naval assets from post-WW2 to the near future in tactical and operational scale, complete with historical and hypothetical scenarios and an integrated scenario editor.

Moderator: MOD_Command

User avatar
somi83
Posts: 59
Joined: Sat Feb 06, 2016 12:59 pm
Location: Novi Sad, Serbia

RE: Setting course/speed with lua script?

Post 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.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Setting course/speed with lua script?

Post 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() )?
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Setting course/speed with lua script?

Post by michaelm75au »

Using 'math.randomseed( os.time() )' on scenario start-up ensures you get a different of random numbers whenever the scenario is started.
Michael
butch4343
Posts: 327
Joined: Thu Mar 26, 2015 2:09 pm

RE: Setting course/speed with lua script?

Post 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
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Setting course/speed with lua script?

Post 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.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
Post Reply

Return to “Command: Modern Operations series”