Jump to content

MIssion Scripting Tools (Mist)- enhancing mission scripting Lua


Recommended Posts

You used wrong brackets for the function arguments.

{ } limit tables,

[ ] limit table indices

( ) limit function arguments

 

Try this:

 

local pos = trigger.misc.getZone('Zone1')

 

local newpoint = mist.getRandPointInCircle(pos.point, pos.radius)

 

--getRandPointInCircle returns a Vec2, so you'll have to make it Vec3

local altitude = land.getHeight(newpoint)

local vec3 = mist.utils.makeVec3(newpoint, altitude)

 

trigger.action.explosion(vec3, 2000)

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

  • ED Team

Thanks! I will try that out when I get home.

 

You used wrong brackets for the function arguments.

{ } limit tables,

[ ] limit table indices

( ) limit function arguments

 

Try this:

 

local pos = trigger.misc.getZone('Zone1')

 

local newpoint = mist.getRandPointInCircle(pos.point, pos.radius)

 

--getRandPointInCircle returns a Vec2, so you'll have to make it Vec3

local altitude = land.getHeight(newpoint)

local vec3 = mist.utils.makeVec3(newpoint, altitude)

 

trigger.action.explosion(vec3, 2000)

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Well got that error to go away by changing some stuff...

 

local pos = trigger.misc.getZone{'Zone1'}

local newpoint = mist.getRandPointInCircle{pos.point, pos.radius}

local vec3 = {
x = newpoint.1000,
y = land.getHeight(newpoint),
z = newpoint.1000
}

trigger.action.explosion{vec3, 2000}

 

Of course I have a new one something about, expecting a close on line 5 near 1000.... me thinks I need to load the Lua manual to the iPad :)

 

newpoint has components of x, y z- it looks like this:

 

newpoint = {

["x"] = number,

["y"] = number,

["z"] = number,

}

 

So when you type newpoint.1000 there are two things wrong with that. First, you are asking for the value of newpoint at the index that is a string equal to "1000". That's not the number one thousand- that's the one character followed by three zero characters. Huge difference. If you want to get the value of a table at an actual number index you must use this notation:

 

newpoint[1000]

 

The table.<index> method is a shortcut that only works for string indexes.

 

Anyway, so the other thing wrong with it is that newpoint.1000 is undefined- nil. The only defined parts of your table are newpoint["x"], newpoint["y"], and newpoint["z"]. (As those are string indexes, we can get those values by using the newpoint.x, newpoint.y, and newpoint.z).

 

 

Anyway, there is a third thing wrong too. land.getHeight uses a 2D vector, not a 3D vector. So Vec3.x gets mapped to Vec2.x, and Vec3.z gets mapped to Vec2.y, and Vec3.y gets thrown away. There is a mist function that does this for you, but in the code below, I do it manually so you can see what is happening.

 

Also, functions are called with parenthesis ( ), not { }. The { } characters are for defining a table. (There IS a Lua shortcut that allows you to skip using the ( ) in a function call in some situations, but don't worry about that right now.)

 

Finally, I'm not sure where do script is run- environmentally, I mean. It might be running in a closure, or it might be running directly in the global environment. If the latter, you should enclose your function in a do - end statement to make your own closure and make your local variable declarations truly local.

 

Anyway, try this.

do
local pos = trigger.misc.getZone('Zone1')

local newpoint = mist.getRandPointInCircle(pos.point, pos.radius)

local vec3 = {
	x = newpoint.x,
	y = land.getHeight({x = newpoint.x, y = newpoint.z}),
	z = newpoint.z
}

trigger.action.explosion(vec3, 2000)
end


Edited by Speed

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

  • ED Team

Thanks Speed... that helps as well. I really need to sit down and understand Lua better, I think thats my biggest stumbling block right now, trying to learn Lua on the fly :)

 

newpoint has components of x, y z- it looks like this:

 

newpoint = {

["x"] = number,

["y"] = number,

["z"] = number,

}

 

So when you type newpoint.1000 there are two things wrong with that. First, you are asking for the value of newpoint at the index that is a string equal to "1000". That's not the number one thousand- that's the one character followed by three zero characters. Huge difference. If you want to get the value of a table at an actual number index you must use this notation:

 

newpoint[1000]

 

The table.<index> method is a shortcut that only works for string indexes.

 

Anyway, so the other thing wrong with it is that newpoint.1000 is undefined- nil. The only defined parts of your table are newpoint["x"], newpoint["y"], and newpoint["z"]. (As those are string indexes, we can get those values by using the newpoint.x, newpoint.y, and newpoint.z).

 

 

Anyway, there is a third thing wrong too. land.getHeight uses a 2D vector, not a 3D vector. So Vec3.x gets mapped to Vec2.x, and Vec3.z gets mapped to Vec2.y, and Vec3.y gets thrown away.

 

Also, functions are called with parenthesis ( ), not { }. The { } characters are for defining a table. (There IS a Lua shortcut that allows you to skip using the ( ) in a function call, but don't worry about that right now.)

 

Finally, I'm not sure where do script is run- environmentally, I mean. It might be running in a closure, or it might be running directly in the global environment. If the latter, you should enclose your function in a do - end statement to make your own closure and make your local variable declarations truly local.

 

Anyway, try this.

do
   local pos = trigger.misc.getZone('Zone1')

   local newpoint = mist.getRandPointInCircle(pos.point, pos.radius)

   local vec3 = {
       x = newpoint.x,
       y = land.getHeight({x = newpoint.x, y = newpoint.z}),
       z = newpoint.z
   }

   trigger.action.explosion(vec3, 2000)
end

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Thanks Speed... that helps as well. I really need to sit down and understand Lua better, I think thats my biggest stumbling block right now, trying to learn Lua on the fly :)

 

The most important thing is to understand tables. They are Lua's only data structure, so once you have an understanding of tables, you have an understanding of a huge portion of Lua.

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

  • ED Team

Roger that. My 1 year old no fly times are Saturday and Sunday morning, I hope to get in some quality Lua time then :)

 

The most important thing is to understand tables. They are Lua's only data structure, so once you have an understanding of tables, you have an understanding of a huge portion of Lua.

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Anyway, try this.

do
local pos = trigger.misc.getZone('Zone1')

local newpoint = mist.getRandPointInCircle(pos.point, pos.radius)

local vec3 = {
	x = newpoint.x,
	y = land.getHeight({x = newpoint.x, y = newpoint.z}),
	z = newpoint.z
}

trigger.action.explosion(vec3, 2000)
end

 

If mist.getRandPointInCircle returns a Vec2 as described, you need to change it like this:

 

local vec3 = {

x = newpoint.x,

y = land.getHeight(newpoint),

z = newpoint.y

}

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

  • ED Team
If mist.getRandPointInCircle returns a Vec2 as described, you need to change it like this:

 

local vec3 = {

x = newpoint.x,

y = land.getHeight(newpoint),

z = newpoint.y

}

 

 

Perfect, that works great, thanks! Now with the above, is it possible to specify X or Y or Z, either a specific number or a range of numbers? Say you want the event to happen only between a certain altitude or distance one way or another, but still maintain the randomness?

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Mission script trigger for allowing destroyed aircraft or pilots to have AI re-spawn at the base once they were killed?

 

How I do that I set a trigger for dead pilots but to respawn that group?


Edited by Mastiff

" any failure you meet, is never a defeat; merely a set up for a greater come back, "  W Forbes

"Success is not final, failure is not fatal, it is the courage to continue that counts,"  Winston Churchill

" He who never changes his mind, never changes anything," 

MSI z690MPG DDR4 || i914900k|| ddr4-64gb PC3200 || MSI RTX 4070Ti|Game1300w|Win10x64| |turtle beach elite pro 5.1|| ViRpiL,T50cm2|| MFG Crosswinds|| VT50CM-plus rotor Throttle || G10 RGB EVGA Keyboard/MouseLogitech || PiMax Crystal VR || 32 Samsung||

Link to comment
Share on other sites

  • ED Team
Perfect, that works great, thanks! Now with the above, is it possible to specify X or Y or Z, either a specific number or a range of numbers? Say you want the event to happen only between a certain altitude or distance one way or another, but still maintain the randomness?

 

 

Wait, I guess you cant do altitude in this one as its just a Vec2, is that right?

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Sith, You can change the values however you want. mist.getRandPointInCircle generates a random coordinate from the center of a coordinate given to a random distance of radius. If you pass it a radius of 0 it just returns the center point. There is also the 3rd optional value to specify an inner radius which will generate a point somewhere between inner radius and the radius. Since it returns a vec2 you gotta run the land.getHeight() function so you can get the vec3 y coordinate that is at ground level. You can then manipulate that however you want. y = land.getHeight(vec2) + math.random(100) will create a random point between 0 and 100 agl at the randomly generated point from mist.getRandPointInCircle().

 

Mission script trigger for allowing destroyed aircraft or pilots to have AI re-spawn at the base once they were killed?

 

How I do that I set a trigger for dead pilots but to respawn that group?

 

I don't quite follow. Currently dynamically spawned groups will not be recognized by triggers.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

 

I don't quite follow. Currently dynamically spawned groups will not be recognized by triggers.

 

ok so how is this guy doing it?

 

http://forums.eagle.ru/showthread.php?t=104831

 

every time I get into a F15C he has a AI Mig23 spawn. but I would like only one 2 ship flight spawn then after they are destoryed they respawn and at the original base and fly the same mission again..


Edited by Mastiff

" any failure you meet, is never a defeat; merely a set up for a greater come back, "  W Forbes

"Success is not final, failure is not fatal, it is the courage to continue that counts,"  Winston Churchill

" He who never changes his mind, never changes anything," 

MSI z690MPG DDR4 || i914900k|| ddr4-64gb PC3200 || MSI RTX 4070Ti|Game1300w|Win10x64| |turtle beach elite pro 5.1|| ViRpiL,T50cm2|| MFG Crosswinds|| VT50CM-plus rotor Throttle || G10 RGB EVGA Keyboard/MouseLogitech || PiMax Crystal VR || 32 Samsung||

Link to comment
Share on other sites

He does it the same way we've always been able to do it before. He has placed copies of the group within the mission and then simply Group Activates em when he needs to. Eventually the flights will "run out".

 

While triggers won't react to a dynamically spawned group, the scripting engine can. So you could use these tools: http://forums.eagle.ru/showthread.php?t=106234 and use scripting to respawn a group when you need it to. Use the sct to spawn a group and get its group data, then schedule a function using mist to check if said group is still alive. Once the group is killed, run the respawn function.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • ED Team
Sith, You can change the values however you want. mist.getRandPointInCircle generates a random coordinate from the center of a coordinate given to a random distance of radius. If you pass it a radius of 0 it just returns the center point. There is also the 3rd optional value to specify an inner radius which will generate a point somewhere between inner radius and the radius. Since it returns a vec2 you gotta run the land.getHeight() function so you can get the vec3 y coordinate that is at ground level. You can then manipulate that however you want. y = land.getHeight(vec2) + math.random(100) will create a random point between 0 and 100 agl at the randomly generated point from mist.getRandPointInCircle().

 

 

Thanks Grimes, was just reading up on the Vec2 Vec 3 stuff trying to figure that out, the formula I didnt get, starting to get less murky though... thanks again...

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

So is there a youtube video on how to?

" any failure you meet, is never a defeat; merely a set up for a greater come back, "  W Forbes

"Success is not final, failure is not fatal, it is the courage to continue that counts,"  Winston Churchill

" He who never changes his mind, never changes anything," 

MSI z690MPG DDR4 || i914900k|| ddr4-64gb PC3200 || MSI RTX 4070Ti|Game1300w|Win10x64| |turtle beach elite pro 5.1|| ViRpiL,T50cm2|| MFG Crosswinds|| VT50CM-plus rotor Throttle || G10 RGB EVGA Keyboard/MouseLogitech || PiMax Crystal VR || 32 Samsung||

Link to comment
Share on other sites

I could use some help with the mist.goRoute function.

 

So far I have 2 functions, the first to generate a random airplane and spawn it randomly in a given zone. This function works fine and looks as following:

 

groupcounter = 0


function generateAirplane()

   randomnr1 = math.random(1,2) -- random for spawnpoints; 1=arrival, 2=depature
   randomnr2 = math.random(1,2) -- random for aircrafttype
   
   groupcounter = groupcounter + 1

   if randomnr2 == 1 
       then
           _aircrafttype = "C-17A" --or whatever type
       else
       if randomnr2 == 2
           then
           _aircrafttype = "Yak-40" --or whatever type
         end
   end
       

   
   if randomnr1 == 1
       then
           _spawnairplane = trigger.misc.getZone('airspawnzone1')
           _spawnairplanepos = {}
           _spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
           _spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
           _alt = 6000
           _speed = 250
           _waypointtype = "Turning Point"
           _waypointaction = "Turning Point"
           _airdromeId = nil
           route = 'arrival'
   else
       if randomnr1 == 2
           then
               _spawnairplane = trigger.misc.getZone('landingpoint')
               _spawnairplanepos = {}
               _spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
               _spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
               _alt = 88
               _speed = 0
               _waypointtype = "TakeOffParking"
               _waypointaction = "From Parking Area"
               _airdromeId = 24
               route = 'departure'
       end    
   end

           
           
   _airplanedata = {
                              ["modulation"] = 0,
                               ["tasks"] = 
                               {
                               }, -- end of ["tasks"]
                               ["task"] = "CAS",
                               ["uncontrolled"] = false,
                               ["route"] = 
                               {
                                   ["points"] = 
                                   {
                                       [1] = 
                                       {
                                           ["alt"] = _alt,
                                           ["type"] = _waypointtype,
                                           ["action"] = _waypointaction,
                                           ["alt_type"] = "BARO",
                                           ["formation_template"] = "",
                                           ["ETA"] = 0,
                                           ["airdromeId"] = _airdromeId,
                                           ["y"] = _spawnairplanepos.z,
                                           ["x"] = _spawnairplanepos.x,
                                           ["speed"] = _speed,
                                           ["ETA_locked"] = true,
                                           ["task"] = 
                                           {
                                               ["id"] = "ComboTask",
                                               ["params"] = 
                                               {
                                                   ["tasks"] = 
                                                   {
                                                      
                                                   }, -- end of ["tasks"]
                                               }, -- end of ["params"]
                                           }, -- end of ["task"]
                                           ["speed_locked"] = true,
                                       }, -- end of [1]
                                   }, -- end of ["points"]
                               }, -- end of ["route"]
                               ["groupId"] = 1,
                               ["hidden"] = false,
                               ["units"] = 
                               {
                                   [1] = 
                                   {
                                       ["alt"] = _alt,
                                       ["heading"] = 0,
                                       ["type"] = _aircrafttype,
                                       ["psi"] = 0,
                                       ["onboard_num"] = "10",
                                       ["parking"] = 19,
                                       ["y"] = _spawnairplanepos.z,
                                       ["x"] = _spawnairplanepos.x,
                                       ["name"] = string.format(groupcounter),
                                       ["payload"] = 
                                       {
                                       }, -- end of ["payload"]
                                       ["speed"] = _speed,
                                       ["unitId"] = string.format(groupcounter),
                                       ["alt_type"] = "BARO",
                                       ["skill"] = "High",
                                   }, -- end of [1]
                               }, -- end of ["units"]
                               ["y"] = _spawnairplanepos.z,
                               ["x"] = _spawnairplanepos.x,
                               ["name"] = string.format(groupcounter),
                               ["communication"] = true,
                               ["start_time"] = 0,
                               ["frequency"] = 124,
                   }
       trigger.action.outText("airplane data generated", 3)
       coalition.addGroup(country.id.USA, Group.Category.AIRPLANE, _airplanedata)
       trigger.action.outText("airplane spawned", 3)
       
end

generateAirplane()
   

 

Then I have a second function, which creates waypoints in defined triggerzones and let an airplane follow these waypoints with the mist.goRoute function. This function works on its own, too, and looks like the following:

 

groupcounter = 1 --airplanename = 1
route = 'departure' --waypoints set for departure, alternative 'arrival'

function generateWaypoints(_spawnairplane, _entrypoint1, _landingpoint1, waypointType)
               
   local waypoints = {}
                   _spawnairplane = trigger.misc.getZone('airspawnzone1')
                   _spawnairplanepos = {}
                   _spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
                   _spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
                   
                   _entrypoint1 = trigger.misc.getZone('entrypoint1')
                   _entrypoint1pos = {}
                   _entrypoint1pos.x = _entrypoint1.point.x + math.random(_entrypoint1.radius * -1, _entrypoint1.radius)
                   _entrypoint1pos.z = _entrypoint1.point.z + math.random(_entrypoint1.radius * -1, _entrypoint1.radius)

                   _landingpoint1 = trigger.misc.getZone('landingpoint')
                   _landingpoint1pos = {}
                   _landingpoint1pos.x = _landingpoint1.point.x + math.random(_landingpoint1.radius * -1, _landingpoint1.radius)
                   _landingpoint1pos.z = _landingpoint1.point.z + math.random(_landingpoint1.radius * -1, _landingpoint1.radius)
                    
       local startpoint1 = {
                           
                                   ["alt"] = 6000,
                                   ["type"] = "Turning Point",
                                   ["action"] = "Turning Point",
                                   ["alt_type"] = "RADIO",
                                   ["formation_template"] = "",
                                   ["ETA"] = 0,
                                   ["y"] = _spawnairplanepos.z,
                                   ["x"] = _spawnairplanepos.x,
                                   ["speed"] = 250,
                                   ["ETA_locked"] = false,
                                   ["task"] = 
                                           {
                                           ["id"] = "ComboTask",
                                               ["params"] = 
                                               {
                                                   ["tasks"] = 
                                                   {
                                                      
                                                   }, -- end of ["tasks"]
                                               }, -- end of ["params"]
                                           }, -- end of ["task"]
                                           ["speed_locked"] = true,
                           } -- end of [1]

                    

       local entrypoint1 = 
                               {
                               ["alt"] = 3000,
                               ["type"] = "Turning Point",
                               ["action"] = "Turning Point",
                               ["alt_type"] = "RADIO",
                               ["formation_template"] = "",
                               ["ETA"] = 0,
                               ["y"] = _entrypoint1pos.z,
                               ["x"] = _entrypoint1pos.x,
                               ["speed"] = 250,
                               ["ETA_locked"] = false,
                               ["task"] = 
                                   {
                                   ["id"] = "ComboTask",
                                       ["params"] = 
                                           {
                                           ["tasks"] = 
                                               {
                                                      
                                               }, -- end of ["tasks"]
                                           }, -- end of ["params"]
                                   }, -- end of ["task"]
                               ["speed_locked"] = true,            
                               }
                   
       local landingpoint1 = 
                               {
                               ["alt"] = 3000,
                               ["type"] = "LAND",
                               ["action"] = "Landing",
                               ["alt_type"] = "RADIO",
                               ["formation_template"] = "",
                               ["ETA"] = 0,
                               ["y"] = _landingpoint1pos.z,
                               ["x"] = _landingpoint1pos.x,
                               ["speed"] = 200,
                               ["ETA_locked"] = false,
                               ["task"] = 
                                   {
                                   ["id"] = "ComboTask",
                                       ["params"] = 
                                           {
                                           ["tasks"] = 
                                               {
                                                      
                                               }, -- end of ["tasks"]
                                           }, -- end of ["params"]
                                   }, -- end of ["task"]
                               ["speed_locked"] = true,            
                               }
                                               
           local takeoffpoint = 
                               {
                               ["alt"] = _alt,
                               ["type"] = "TakeOffParking",
                               ["action"] = "From Parking Area",
                               ["alt_type"] = "RADIO",
                               ["formation_template"] = "",
                               ["ETA"] = 0,
                               ["y"] = _landingpoint1pos.z,
                               ["x"] = _landingpoint1pos.x,
                               ["speed"] = 0,
                               ["ETA_locked"] = false,
                               ["task"] = 
                                   {
                                   ["id"] = "ComboTask",
                                       ["params"] = 
                                           {
                                           ["tasks"] = 
                                               {
                                                      
                                               }, -- end of ["tasks"]
                                           }, -- end of ["params"]
                                   }, -- end of ["task"]
                               ["speed_locked"] = true,            
                               }

                           
       if waypointType == 'arrival' 
       then
           waypoints[#waypoints+1] =  mist.fixedWing.buildWP(startpoint1, "Turning Point", 250, 3000, "RADIO")
           waypoints[#waypoints+1] =  mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
           waypoints[#waypoints+1] =  mist.fixedWing.buildWP(landingpoint1, "LAND", 250, 3000, "RADIO") --string type, number speed, number altitude, string altitudeType
           else if waypointType == 'departure'
               then
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(takeoffpoint, "TakeOffParking", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(startpoint1, "Turning Point", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(landingpoint1, "LAND", 250, 3000, "RADIO") --string type, number speed, number altitude, string altitudeType
           end
       end
                           
   return waypoints
end
   
   
flightplan = generateWaypoints(_spawnairplane, _entrypoint1, _landingpoint1, route)
local airtraffic1grp = Group.getByName(string.format(groupcounter)) 
mist.goRoute(airtraffic1grp, flightplan)

 

Each function function generateAirplane() and generateWaypoints(..) work on their own, but together they don`t. :helpsmilie:

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

In addition:

 

I tried to combine the functions in one script and the airplane spawns, but does not follow the waypoints of the mist.goRoute function.

 

If I place and airplane in the ME and use the 2nd function the airplane follows the waypoints.

 

How do I combine these 2 functions in one script, so the spawned aircraft follows the waypoints?

 

I tried it this way:

 

--Following trigger zones need to be placed in the ME:
--1: Zone called 'airspawnzone1', which defines the area in which planes will airspawn
--2: Zone called 'landingpoint', which includes the airport on which the planes will land
--3: Zone called 'entrypoint1', which defines the entry/exit point of the airfield the planes are set to land or takeoff

groupcounter = 0


function generateAirplanedata()

   randomnr1 = math.random(1,2) -- random for spawnpoints; 1=arrival, 2=depature
   randomnr2 = math.random(1,2) -- random for aircrafttype
   
   groupcounter = groupcounter + 1

   if randomnr2 == 1 
       then
           _aircrafttype = "C-17A"
       else
       if randomnr2 == 2
           then
           _aircrafttype = "Yak-40"

       end
   end
       

   
   if randomnr1 == 1
       then
           _spawnairplane = trigger.misc.getZone('airspawnzone1')
           _spawnairplanepos = {}
           _spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
           _spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
           _alt = 6000
           _speed = 250
           _waypointtype = "Turning Point"
           _waypointaction = "Turning Point"
           _airdromeId = nil
           route = 'arrival'
   else
       if randomnr1 == 2
           then
               _spawnairplane = trigger.misc.getZone('landingpoint')
               _spawnairplanepos = {}
               _spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
               _spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
               _alt = 88
               _speed = 0
               _waypointtype = "TakeOffParking"
               _waypointaction = "From Parking Area"
               _airdromeId = 24
               route = 'departure'
       end    
   end

           
           
   _airplanedata = {
                              ["modulation"] = 0,
                               ["tasks"] = 
                               {
                               }, -- end of ["tasks"]
                               ["task"] = "CAS",
                               ["uncontrolled"] = false,
                               ["route"] = 
                               {
                                   ["points"] = 
                                   {
                                       [1] = 
                                       {
                                           ["alt"] = _alt,
                                           ["type"] = _waypointtype,
                                           ["action"] = _waypointaction,
                                           ["alt_type"] = "BARO",
                                           ["formation_template"] = "",
                                           ["ETA"] = 0,
                                           ["airdromeId"] = _airdromeId,
                                           ["y"] = _spawnairplanepos.z,
                                           ["x"] = _spawnairplanepos.x,
                                           ["speed"] = _speed,
                                           ["ETA_locked"] = true,
                                           ["task"] = 
                                           {
                                               ["id"] = "ComboTask",
                                               ["params"] = 
                                               {
                                                   ["tasks"] = 
                                                   {
                                                      
                                                   }, -- end of ["tasks"]
                                               }, -- end of ["params"]
                                           }, -- end of ["task"]
                                           ["speed_locked"] = true,
                                       }, -- end of [1]
                                   }, -- end of ["points"]
                               }, -- end of ["route"]
                               ["groupId"] = 1,
                               ["hidden"] = false,
                               ["units"] = 
                               {
                                   [1] = 
                                   {
                                       ["alt"] = _alt,
                                       ["heading"] = 0,
                                       ["type"] = _aircrafttype,
                                       ["psi"] = 0,
                                       ["onboard_num"] = "10",
                                       ["parking"] = 19,
                                       ["y"] = _spawnairplanepos.z,
                                       ["x"] = _spawnairplanepos.x,
                                       ["name"] = string.format(groupcounter),
                                       ["payload"] = 
                                       {
                                       }, -- end of ["payload"]
                                       ["speed"] = _speed,
                                       ["unitId"] = string.format(groupcounter),
                                       ["alt_type"] = "BARO",
                                       ["skill"] = "High",
                                   }, -- end of [1]
                               }, -- end of ["units"]
                               ["y"] = _spawnairplanepos.z,
                               ["x"] = _spawnairplanepos.x,
                               ["name"] = string.format(groupcounter),
                               ["communication"] = true,
                               ["start_time"] = 0,
                               ["frequency"] = 124,
                   }
       trigger.action.outText("airplane data generated", 3)
       coalition.addGroup(country.id.USA, Group.Category.AIRPLANE, _airplanedata)
       genericairtraffic = Group.getByName(string.format(groupcounter))
       
end
generateAirplanedata()

function goRoute()
   function generateWaypoints(_spawnairplane, _entrypoint1, _landingpoint1, waypointType)
               
   local waypoints = {}
                   _spawnairplane = trigger.misc.getZone('airspawnzone1')
                   _spawnairplanepos = {}
                   _spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
                   _spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
                   
                   _entrypoint1 = trigger.misc.getZone('entrypoint1')
                   _entrypoint1pos = {}
                   _entrypoint1pos.x = _entrypoint1.point.x + math.random(_entrypoint1.radius * -1, _entrypoint1.radius)
                   _entrypoint1pos.z = _entrypoint1.point.z + math.random(_entrypoint1.radius * -1, _entrypoint1.radius)

                   _landingpoint1 = trigger.misc.getZone('landingpoint')
                   _landingpoint1pos = {}
                   _landingpoint1pos.x = _landingpoint1.point.x + math.random(_landingpoint1.radius * -1, _landingpoint1.radius)
                   _landingpoint1pos.z = _landingpoint1.point.z + math.random(_landingpoint1.radius * -1, _landingpoint1.radius)
                    
       local startpoint1 = {
                           
                                   ["alt"] = 6000,
                                   ["type"] = "Turning Point",
                                   ["action"] = "Turning Point",
                                   ["alt_type"] = "RADIO",
                                   ["formation_template"] = "",
                                   ["ETA"] = 0,
                                   ["y"] = _spawnairplanepos.z,
                                   ["x"] = _spawnairplanepos.x,
                                   ["speed"] = 250,
                                   ["ETA_locked"] = false,
                                   ["task"] = 
                                           {
                                           ["id"] = "ComboTask",
                                               ["params"] = 
                                               {
                                                   ["tasks"] = 
                                                   {
                                                      
                                                   }, -- end of ["tasks"]
                                               }, -- end of ["params"]
                                           }, -- end of ["task"]
                                           ["speed_locked"] = true,
                           } -- end of [1]

                    

       local entrypoint1 = 
                               {
                               ["alt"] = 3000,
                               ["type"] = "Turning Point",
                               ["action"] = "Turning Point",
                               ["alt_type"] = "RADIO",
                               ["formation_template"] = "",
                               ["ETA"] = 0,
                               ["y"] = _entrypoint1pos.z,
                               ["x"] = _entrypoint1pos.x,
                               ["speed"] = 250,
                               ["ETA_locked"] = false,
                               ["task"] = 
                                   {
                                   ["id"] = "ComboTask",
                                       ["params"] = 
                                           {
                                           ["tasks"] = 
                                               {
                                                      
                                               }, -- end of ["tasks"]
                                           }, -- end of ["params"]
                                   }, -- end of ["task"]
                               ["speed_locked"] = true,            
                               }
                   
       local landingpoint1 = 
                               {
                               ["alt"] = 3000,
                               ["type"] = "LAND",
                               ["action"] = "Landing",
                               ["alt_type"] = "RADIO",
                               ["formation_template"] = "",
                               ["ETA"] = 0,
                               ["y"] = _landingpoint1pos.z,
                               ["x"] = _landingpoint1pos.x,
                               ["speed"] = 200,
                               ["ETA_locked"] = false,
                               ["task"] = 
                                   {
                                   ["id"] = "ComboTask",
                                       ["params"] = 
                                           {
                                           ["tasks"] = 
                                               {
                                                      
                                               }, -- end of ["tasks"]
                                           }, -- end of ["params"]
                                   }, -- end of ["task"]
                               ["speed_locked"] = true,            
                               }
                                               
           local takeoffpoint = 
                               {
                               ["alt"] = _alt,
                               ["type"] = "TakeOffParking",
                               ["action"] = "From Parking Area",
                               ["alt_type"] = "RADIO",
                               ["formation_template"] = "",
                               ["ETA"] = 0,
                               ["y"] = _landingpoint1pos.z,
                               ["x"] = _landingpoint1pos.x,
                               ["speed"] = 0,
                               ["ETA_locked"] = false,
                               ["task"] = 
                                   {
                                   ["id"] = "ComboTask",
                                       ["params"] = 
                                           {
                                           ["tasks"] = 
                                               {
                                                      
                                               }, -- end of ["tasks"]
                                           }, -- end of ["params"]
                                   }, -- end of ["task"]
                               ["speed_locked"] = true,            
                               }

                           
       if waypointType == 'arrival' 
       then
           waypoints[#waypoints+1] =  mist.fixedWing.buildWP(startpoint1, "Turning Point", 250, 3000, "RADIO")
           waypoints[#waypoints+1] =  mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
           waypoints[#waypoints+1] =  mist.fixedWing.buildWP(landingpoint1, "LAND", 250, 3000, "RADIO") --string type, number speed, number altitude, string altitudeType
           else if waypointType == 'departure'
               then
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(takeoffpoint, "TakeOffParking", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(startpoint1, "Turning Point", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
               waypoints[#waypoints+1] =  mist.fixedWing.buildWP(landingpoint1, "LAND", 250, 3000, "RADIO") --string type, number speed, number altitude, string altitudeType
           end
       end
                           
   return waypoints
   end
   
   
   
flightplan = generateWaypoints(_spawnairplane, _entrypoint1, _landingpoint1, route)
--local genericairtraffic = Group.getByName(string.format(groupcounter)) 
mist.goRoute(genericairtraffic, flightplan)
end
goRoute()    


Edited by SNAFU

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

  • ED Team

Is it possible to set land.getHeight(vec2) as something other than the Vec2? As in I want the altitude to start at say 2000, then random anywhere between 2000 and say 4000 with the + math.random(4000). I know just putting a number in there fires off an error...

 

Basically:

 

land.getHeight(custom height of 2000) + math.random(4000)

 

Then my event happens between 2000 and 4000 agl?

 

It is working close to how I want it though :)

 

Sith, You can change the values however you want. mist.getRandPointInCircle generates a random coordinate from the center of a coordinate given to a random distance of radius. If you pass it a radius of 0 it just returns the center point. There is also the 3rd optional value to specify an inner radius which will generate a point somewhere between inner radius and the radius. Since it returns a vec2 you gotta run the land.getHeight() function so you can get the vec3 y coordinate that is at ground level. You can then manipulate that however you want. y = land.getHeight(vec2) + math.random(100) will create a random point between 0 and 100 agl at the randomly generated point from mist.getRandPointInCircle().

Edited by NineLine

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Sith just set the y value to math.random(2000, 4000) for ASL or add it to the land.getHeight for 2000-4000 AGL.

 

local vec3 = {

x = newpoint.x,

y = land.getHeight(newPoint) + math.random(2000,4000)

z = newpoint.y

}

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • ED Team

This worked like a charm Grimes, thanks for all the help and everyone else.

 

@Speed, with your Nuclear Missile example, are you using the Nuclear Missile defined in the sim (pretty sure I saw one defined some where at some point) or are you creating one from scratch? Just wondering now if I can take what I am using now "trigger.action.explosion" and refine it into an actual weapon from in the game instead of just a generic explosion.

 

Sith just set the y value to math.random(2000, 4000) for ASL or add it to the land.getHeight for 2000-4000 AGL.

 

local vec3 = {

x = newpoint.x,

y = land.getHeight(newPoint) + math.random(2000,4000)

z = newpoint.y

}

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

No, it's just a virtual object in the game, represented only in code, not with an actual 3D object. It owes its existence to a rapidly re-scheduled (using mist.scheduleFunction) function call that receives arguments from the previous scheduled function call. For fun, I make the virtual object's path be traced through the 3D world with occasional explosions and flares. That way, you can see it coming and dodge out of the way :D


Edited by Speed

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

  • ED Team
No, it's just a virtual object in the game, represented only in code, not with an actual 3D object. It owes its existence to a rapidly re-scheduled (using mist.scheduleFunction) function call that receives arguments from the previous scheduled function call. For fun, I make the virtual object's path be traced through the 3D world with occasional explosions and flares. That way, you can see it coming and dodge out of the way :D

 

 

Ok thanks Speed, I mostly was referring to instead of a generic explosion using the explosion caused by a specific weapon system defined in the sim already. Would also be nice to be able to randomize the explosion effect, but now I am probably just getting carried away :)

64Sig.png
Forum RulesMy YouTube • My Discord - NineLine#0440• **How to Report a Bug**

1146563203_makefg(6).png.82dab0a01be3a361522f3fff75916ba4.png  80141746_makefg(1).png.6fa028f2fe35222644e87c786da1fabb.png  28661714_makefg(2).png.b3816386a8f83b0cceab6cb43ae2477e.png  389390805_makefg(3).png.bca83a238dd2aaf235ea3ce2873b55bc.png  216757889_makefg(4).png.35cb826069cdae5c1a164a94deaff377.png  1359338181_makefg(5).png.e6135dea01fa097e5d841ee5fb3c2dc5.png

Link to comment
Share on other sites

Ok thanks Speed, I mostly was referring to instead of a generic explosion using the explosion caused by a specific weapon system defined in the sim already. Would also be nice to be able to randomize the explosion effect, but now I am probably just getting carried away :)

 

Get the weapon from a shot event event handler that adds the weapon to a table of "tracked weapons". Using a very rapidly-rescheduled function, track the alive/dead status of tracked weapons and their position with Object.isExist and Object.getPosition. When Object.isExist fails on a tracked weapon, then it has exploded in game. Set a trigger.action.explosion off at the last recorded position of the weapon.

 

Be warned though... there are bugs with weapon shot events and multiplayer clients for some types of shot weapons. Be sure to test any such code thoroughly in multiplayer.


Edited by Speed

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

  • 2 weeks later...

Messing around with the getMGRSString function today and can't get this to work (see in spoilers). Any tips? Thanks -

 

 

do

group = mist.makeUnitTable({'[g]TestGroup'})

end

 

do

local location = mist.getMGRSString{

units = {group},

acc = 3

}

mist.message.add{

text = location,

displayTime = 20,

msgFor = {coa = {'all'}}

}

end

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...