Jump to content

MIssion Scripting Tools (Mist)- enhancing mission scripting Lua


Recommended Posts

The simulator function takes a vec2 coordinate and will return a number based on what type of terrain it is. It returns 1 through 5 based on the index of the following table. 1 = land, 2 = shallow water (not sure if that actually is implemented) 3 = water, 4 = road, 5 = runway.

 

 land.SurfaceType = {
  LAND,
  SHALLOW_WATER,
  WATER,
  ROAD,
  RUNWAY
}

 

So you would generate a new point and then check it to make sure it is type "1" for land, and if it is use that coordinate. If its not, generate a new point.

 if land.getSurfaceType(coord) == 1 then 

 

Mist 2.1 will have this: mist.isTerrainValid(coord, terrainTypes) :) Not 100% sure if we will integrate it into mist.getRandPointInCircle

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

Good idea. Although it'll likely be something like mist.message.sound. Not sure if I could add it to mist.message.add because that runs 10 times a second so its less than ideal for sound files. Also CA complicates things. I'll see what I can come up with.

 

-edit

To explain the CA issue a little more. The message function basically runs twice, once for CA and again for clients. This is a dirty workaround for the CA clients which are essentially "groupless" and therefore trigger.action.outTextToGroup simply cant be used to filter the message to specific clients. The function basically overwrites the CA message instantly with the message for players in aircraft.

 

So basically there are 3 solutions for sound.

1. Stagger messages. CA messages will be heard by all that belong to the coalition.

2. CA won't be an option to receive audio messages for anything except coalition level messages

3. No Audio for CA


Edited by Grimes

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

:thumbup:

 

Thanks to Grimes for getting me sorted with LUA, I should have a nice little script to share by the end of the week!

 

Specifically aimed towards UH-1H Huey pilots and mission designers.

 

:pilotfly:

 

I've been working on a script for my mission, Asset Extraction, so that I can add the Huey as a user controlled aircraft and have it replace the existing UH-60 Blackhawks for the actual extraction part of the mission.

 

Here's a little demonstration of how far I've gotten using Lua, addGroup and MIST.

 

 

The two CSAR infantry units that spawn "from" the Blackhawk are completely dynamic based on the position of the helicopter, they dynamically figure out a path from that point to the asset, do the obligatory mission pause for [insert time here] and then dynamically figure out a path back to the helicopter before moving back for extraction.

 

Oh, and they can tell what helicopter is the current "rescue helicopter" (meaning first helicopter to touch down in their extraction zone) and navigate to it... if there are any. If no helicopters exist in the extraction zone (if, for example, you decided to take off and keep an eye on the surroundings from a nice high vantage point) they will report that their mission has been completed and they are waiting for you to land nearby so that they can hitch a ride.

 

Pretty neat stuff, I think!

 

:music_whistling:

 

Once I've tested it a bit more and worked out any bugs I might find, I'll post the Lua code to paste bin and link it here so that anyone who is interested can use it. My first foray into Lua programming so I'll have to apologize if the code is messy or not as concise as a veteran might be able to accomplish.

 

I'm shooting to have this ready for release by the end of the week or early next week as well as an updated version of my DCS: World mission (which will once again support all DCS modules except Combined Arms).

 

:joystick:


Edited by Psyrixx
  • Like 1

Robert Sogomonian | Psyrixx

website| e-mail | blog | youtube | twitter

Link to comment
Share on other sites

Good idea. Although it'll likely be something like mist.message.sound. Not sure if I could add it to mist.message.add because that runs 10 times a second so its less than ideal for sound files. Also CA complicates things. I'll see what I can come up with.

 

[...]

 

Thanks, I hope you can think of something :thumbup:

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Here's a proof of concept from the pilot's seat of a client controlled UH-1H Huey with my LUA in action. A few kinks to work out, but:

 

http://www.youtube.com/watch?v=eLlUmvSMbHo&hd=1

 

  • The extraction team spawns dynamically based on where I land
  • The extraction team successfully navigates to the unit being extracted
  • The extraction team navigates to my new location once I've landed again

 

I just need to play around with some of the logic and coordinate spacing, I think, to make them function the way that I want. Also, they were supposed to let me know that they were done and ready to be picked up, so I'll have to figure out why that didn't trigger as well.

 

But hey, it works!

 

:pilotfly:

 

Hopefully I'll have an awesome code example of how to achieve this as well as an updated mission file by Friday (or next Monday at the latest).

 

:thumbup:

Robert Sogomonian | Psyrixx

website| e-mail | blog | youtube | twitter

Link to comment
Share on other sites

  • ED Team
Here's a proof of concept from the pilot's seat of a client controlled UH-1H Huey with my LUA in action. A few kinks to work out, but:

 

http://www.youtube.com/watch?v=eLlUmvSMbHo&hd=1

 

  • The extraction team spawns dynamically based on where I land
  • The extraction team successfully navigates to the unit being extracted
  • The extraction team navigates to my new location once I've landed again

 

I just need to play around with some of the logic and coordinate spacing, I think, to make them function the way that I want. Also, they were supposed to let me know that they were done and ready to be picked up, so I'll have to figure out why that didn't trigger as well.

 

But hey, it works!

 

:pilotfly:

 

Hopefully I'll have an awesome code example of how to achieve this as well as an updated mission file by Friday (or next Monday at the latest).

 

:thumbup:

 

I have a mission already done that I would love to convert to this... so much better than the old way... cant wait to see your finished example.

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

I'll be posting the code to PasteBin once it is working the way that I want and you'll be free to use it however you want. Hopefully it helps you with your conversion!

 

While I'm here, is there any easier way to be debugging Lua with DCS? Are there IDE or debuggers that I can hook into the game to monitor variables and such or is old-school "echo this variable value in the program" the only way to go?

Robert Sogomonian | Psyrixx

website| e-mail | blog | youtube | twitter

Link to comment
Share on other sites

I'll be posting the code to PasteBin once it is working the way that I want and you'll be free to use it however you want. Hopefully it helps you with your conversion!

 

While I'm here, is there any easier way to be debugging Lua with DCS? Are there IDE or debuggers that I can hook into the game to monitor variables and such or is old-school "echo this variable value in the program" the only way to go?

 

Well, the only efficient way to debug Lua in DCS would be without the actual sim running because if you need to start the sim, you loose a lot of time because DCS needs to load every time you want to test.

 

However, without running DCS it seems to be a bit hard. You would have to simulate a bunch of things like all the units and their movements, all the events and so on.

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Yep, I guess I was mostly curious about the potential for setting up a sort of debugger listener that could plug in to the DCS process (don't mind having to re-load it each time) as it would be invaluable to see a live output of what's being called, flag values, trigger states, have an error log that isn't just a cryptic popup window, etc.

 

I've never worked with Lua before so I just don't know what's possible with it and have no idea what currently exists for mission designers in this sense is the main reason I'm asking. Currently I just output variable values to a outText('') function and have that refresh every second.

Robert Sogomonian | Psyrixx

website| e-mail | blog | youtube | twitter

Link to comment
Share on other sites

I've never worked with Lua before so I just don't know what's possible with it and have no idea what currently exists for mission designers in this sense is the main reason I'm asking. Currently I just output variable values to a outText('') function and have that refresh every second.

 

mist.message.add and the serialize functions are useful for this sort of thing. I also used excessive print statements to see what assorted values are an object currently has. It would be neigh impossible to emulate how the scripting engine works outside of the simulator.

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

 

Works pretty well, if I do say so myself. :thumbup:

 

  • Group dynamically spawns at User's location
  • Group spawns on the side of the Huey closest to the objective that they're moving towards
  • Group dynamically navigates to set point (friendly asset in this case)
  • Group waits for set amount of time while other objectives are managed
  • Group checks to see if User is on the ground, if not they call in for pick-up
  • Group dynamically navigates back to User's aircraft location (in case they've moved)
  • Group sets trigger and deactivates to simulate being picked up

 

  • Works for multiple aircraft (in Multiplayer, one user can drop off units and another can pick them up upon mission completion if necessary [first player dead, occupied, RTB, etc])

 

Currently the units must spawn pretty far away from the drop off helicopter since the hit boxes are so large on the UH-1H any closer and the units get "stuck" and cannot navigate until the helicopter is airborne again but hopefully in the future that will be optimized and units will look even more realistic in their spawn and deactivation distances.

 

I'll post the code on Friday along with an updated version of my mission that allows for user-controlled extraction!

 

:joystick:

Robert Sogomonian | Psyrixx

website| e-mail | blog | youtube | twitter

Link to comment
Share on other sites

I try to get a randomly assigned landing zone via mist.DBS.zonesByName, but the script seems to stop working. Background is I want to give the pilot an update on how close or far it is to the LZ every couple of seconds and/or shoot a flare at the LZ location. I attached the test mission. The relevant part of the code is:

 

 flag1Value = trigger.misc.getUserFlag("1")
 flag2Value = trigger.misc.getUserFlag("2")
 message = message .. "Flag 1 value: " .. flag1Value .. " flag 2 value: " .. flag2Value .. "\n"
 if flag1Value > 0 then
   LZ = "LZ" .. flag1Value
   message = message .. "flag1 value bigger 0, LZ is " .. LZ
   -- trigger.action.signalFlare(LZ, 2, "0", 270)
   zone = mist.DBS.zonesByName[LZ]
   message = message .. "Zone: " .. zone
 end
 trigger.action.outText(message, 10)
 mist.scheduleFunction(main, {}, timer.getTime() + 10)

 

The script seems to die w/o error at the DBS.zonesByName call. Any help appreciated, my first steps in Lua and MIST.

uh1-maikopp-lua.miz

Link to comment
Share on other sites

The script seems to die w/o error at the DBS.zonesByName call. Any help appreciated, my first steps in Lua and MIST.

 

The dcs.log contains valuable hints to why a script dies. In your case it reads:

00762.067 UNKNOWN MissionScripting::initialize: mist.scheduleFunction, error in scheduled function: [string "C:\Users\St3v3f\AppData\Local\Temp\DCS\/~mi..."]:96: attempt to index field 'DBS' (a nil value)

 

Go to line 96 and replace DBS with DBs

 

After that, it will die with:

00865.217 UNKNOWN MissionScripting::initialize: mist.scheduleFunction, error in scheduled function: [string "C:\Users\St3v3f\AppData\Local\Temp\DCS\/~mi..."]:97: attempt to concatenate global 'zone' (a table value)

 

zonesByName returns a table, not a string. So to get the zone's name, just append .name to zone in line 97

  • Like 2

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

I haven't read the entire thread, but did search for "initialize" and only found one item that wasn't relevant --

 

In the ME, I loaded the Mistv1_1.lua in the "Initialize Script" (not sure if that is exact name) field at the bottom of the Trigger Menu, created one trigger to happen 5 seconds into mission (the demo script provided), and sure enough, I started getting data displayed on the screen after 5 seconds. Is this the "preferred" way to start Mist now, as opposed to creating a trigger at Mission Start with a "Do Script" action?

Link to comment
Share on other sites

Thanks, St3v3f. So where in the script is this new zone given a 'name' so that I can refer to it in subsequent scripts?

 

You can't create a zone that would be recognized with the trigger.misc.getZone() function. You can create a variable that is scripting only which could be referenced within the script in the same way as St3v3f described...

 

local myZone = {

point = Vec3,

radius = Distance

}

 

local unitPos = Unit.getByName('unit1'):getPosition().p

 

 

if math.sqrt(((myZone.point.x + unitPos.x)^2) + ((myZone.point.z + unitPos.z)^2)) < myZone.radius then

print('Unit is inside the zone')

end

 

 

BBQ, you can use it however you want to as long as Mist is loaded before the first script that requires Mist is ran. Typically I use either mission start or initialize to start Mist.

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

SO while the screenshot does make me giggle, is there something I am missing in my code to prevent this for spawning a group? :doh:

 

local pos = trigger.misc.getZone('WP2')
local ranpos = {}

ranpos.x = pos.point.x + math.random(pos.radius * -1, pos.radius)
ranpos.z = pos.point.z + math.random(pos.radius * -1, pos.radius)

local data = {
["visible"] = true,
["groupId"] = 54 ,
["tasks"] = 
{
}, -- end of ["tasks"]
["hidden"] = false,
["units"] = 
{
 [1] = 
 {
  ["y"] = ranpos.z,
  ["type"] = "SA-18 Igla-S manpad",
  ["name"] = "MANPAD1" ,
  ["unitId"] = 54 ,
  ["heading"] = 0,
  ["playerCanDrive"] = true,
  ["skill"] = "Random",
  ["x"] = ranpos.x,
 }, -- end of [1]
 [2] = 
 {
  ["y"] = ranpos.z,
  ["type"] = "Ural-4320-31",
  ["name"] = "MANPAD2" ,
  ["unitId"] = 55 ,
  ["heading"] = 0,
  ["playerCanDrive"] = true,
  ["skill"] = "Random",
  ["x"] = ranpos.x,
 }, -- end of [2]
 [3] = 
 {
  ["y"] = ranpos.z,
  ["type"] = "SA-18 Igla-S manpad",
  ["name"] = "MANPAD3" ,
  ["unitId"] = 56 ,
  ["heading"] = 0,
  ["playerCanDrive"] = true,
  ["skill"] = "Random",
  ["x"] = ranpos.x,
 }, -- end of [3]
}, -- end of ["units"]
--["y"] = 650342.85714286,
--["x"] = -292285.71428571,
["name"] = "WP2-AAA" ,
--["start_time"] = 0,
--["task"] = "Ground Nothing",
} -- end of [1]

coalition.addGroup(country.id.RUSSIA, Group.Category.GROUND, data)

2123614571_dcs2013-05-1114-20-58-21.thumb.jpg.6cffad65ac1e874a1228daca630c7ee5.jpg

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

The X and Y coordinate of each unit is identical. Change it to something like...

 

 [2] = 
 {
  ["y"] = ranpos.z -5,
  ["type"] = "Ural-4320-31",
  ["name"] = "MANPAD2" ,
  ["unitId"] = 55 ,
  ["heading"] = 0,
  ["playerCanDrive"] = true,
  ["skill"] = "Random",
  ["x"] = ranpos.x -5,
 }, -- end of [2]
 [3] = 
 {
  ["y"] = ranpos.z+ 5,
  ["type"] = "SA-18 Igla-S manpad",
  ["name"] = "MANPAD3" ,
  ["unitId"] = 56 ,
  ["heading"] = 0,
  ["playerCanDrive"] = true,
  ["skill"] = "Random",
  ["x"] = ranpos.x + 5,
 }, -- end of [3]

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

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...