Jump to content

MIssion Scripting Tools (Mist)- enhancing mission scripting Lua


Recommended Posts

Yep, that worked a treat. Good to know that first point in the route table is not actually the initial point, at least on spawning. All is working as expected, even with On Road option. Many thanks again, drinks on me next time!

[sIGPIC]OK[/sIGPIC]

Link to comment
Share on other sites

When you use mist.respawnGroup it doesn't change the name of the newly respawned group, it keeps all of the original information.

 

So mist.respawnGroup('NalAir1') should work.

 

Alternatively you can store the groups name while it is alive in a global variable or a local variable that is outside of the local scope which it is used.

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

problem is the group is randomly chosen from 4 different groups at which time I assign it the variable RedAir1Grp. I have no idea which group it is. it could be NalAir1, GudAir1, SukAir1 or AdlAir1. When I pass the variable to the group.destroy(RedAir1Grp) - RedAir1Grp being the variable it works and only kills the group that was randomly picked but the respawn does not.


Edited by Montrose
Link to comment
Share on other sites

You can use RedAir1Grp:getName() before you destroy it.

 

local usedGroup = RedAir1Grp:getName()

RedAir1Grp:destroy()

mist.respawnGroup(usedGroup, true)

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

Hello there Grimes, suddenly, I get this message. I don't recall doing anything special, just desanitize the io library to export the DBs. Now I get this message and honestly I don't know how to debug it.

Mind you, the group is still spawned after this message pops up 'n' times where 'n' is exactly the number of units in the group. Also, I have this message once when I quit the mission, if that helps.

Capture.JPG.3cd0a8fbcb41a1700569685de7a6256a.JPG

[sIGPIC]OK[/sIGPIC]

Link to comment
Share on other sites

Hello there !

 

I wondered, is it possible to create a script to do the following thing:

 

when coming back to the tarawa in my harrier, I use a radio menu and then I have a message (text on screen) that indicates me the course and speed of the ship.

 

If I could I would do it myself, but I have absolutely zero skill regarding lua and programm language in general

Link to comment
Share on other sites

Hello there Grimes, suddenly, I get this message. I don't recall doing anything special, just desanitize the io library to export the DBs. Now I get this message and honestly I don't know how to debug it.

Mind you, the group is still spawned after this message pops up 'n' times where 'n' is exactly the number of units in the group. Also, I have this message once when I quit the mission, if that helps.

 

Might need the mission to test that one. Seems like the event handler might still be active and reacting to the mission end event.

 

Hello there !

 

I wondered, is it possible to create a script to do the following thing:

 

when coming back to the tarawa in my harrier, I use a radio menu and then I have a message (text on screen) that indicates me the course and speed of the ship.

 

If I could I would do it myself, but I have absolutely zero skill regarding lua and programm language in general

 

Ok. So I guess you gotta break it down for whats used.

 

You need to get the unit object via Unit.getByName() and then getVelocity and getPosition. Then put it into a message that gets displayed with trigger.action.outText()

 

Mist can simplify it.

 

local function displayHeading()
 local u = Unit.getByName('tarawa')
 if u then
   local msg = {}
   msg[#msg+1] = 'Tarawa is heading: '
   msg[#msg+1] = mist.getHeading(u, true)
   msg[#msg+1] = ' at '
   msg[#msg+1] = mist.vec.mag(u:getVelocity()) * 1.94384
   msg[#msg+1] = ' knots'
   trigger.action.outText(table.concat(msg), 30)
 end
end 

 

Now this doesn't format the numbers at all. So there is a very real chance it displays 124.34529462 or something like that for the heading.

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

Might need the mission to test that one. Seems like the event handler might still be active and reacting to the mission end event.

 

That was it basically. I was debugging it and left this snippet as a placeholder :

 

playCommand = {}
world.addEventHandler(playCommand)

 

Not sure if lua see empty tables as nil ones but it actually fired at every event. Very annoying. All is good now. I really hate it when I can't properly debug a file.

Thanks again.

[sIGPIC]OK[/sIGPIC]

Link to comment
Share on other sites

 

 

 

Ok. So I guess you gotta break it down for whats used.

 

You need to get the unit object via Unit.getByName() and then getVelocity and getPosition. Then put it into a message that gets displayed with trigger.action.outText()

 

Mist can simplify it.

 

local function displayHeading()
 local u = Unit.getByName('tarawa')
 if u then
   local msg = {}
   msg[#msg+1] = 'Tarawa is heading: '
   msg[#msg+1] = mist.getHeading(u, true)
   msg[#msg+1] = ' at '
   msg[#msg+1] = mist.vec.mag(u:getVelocity()) * 1.94384
   msg[#msg+1] = ' knots'
   trigger.action.outText(table.concat(msg), 30)
 end
end 

Now this doesn't format the numbers at all. So there is a very real chance it displays 124.34529462 or something like that for the heading.

 

Thanks for the script, but I have a question, how do you make it work in the mission editor ? I tried to make it work but nothing happened. I did the following in triggers:

 

-1) when time >10 seconds execute script file mist and create a radio menu for my group (marker 1)

 

2) everytime marker 1 is true, do script, and I paste what you gave me in the ME script window

Link to comment
Share on other sites

Theres a couple different ways to do it.

 

If you want to use a trigger with a flag, you can remove the line declaring it a function and also the corresponding end statement. So comment out the first and last line, then setting the flag will work just fine. Just remember that you will also need to set the flag to false if you wanted the command to work again.

 

Alternatively you can just add the following below it in the code and set it up to run once at any time.

 

missionCommands.addCommand("Get Heading', nil, displayHeading)

 

This will add a F10 radio menu that directly calls the displayHeading function when you select it.

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

Theres a couple different ways to do it.

 

If you want to use a trigger with a flag, you can remove the line declaring it a function and also the corresponding end statement. So comment out the first and last line, then setting the flag will work just fine. Just remember that you will also need to set the flag to false if you wanted the command to work again.

 

Alternatively you can just add the following below it in the code and set it up to run once at any time.

 

missionCommands.addCommand("Get Heading', nil, displayHeading)

 

This will add a F10 radio menu that directly calls the displayHeading function when you select it.

 

Thank you for your answer, it seems to work !

One more question, I have the message displayed with the infos, but ship course looks to be in radians instead of degrees, how to make the conversion within the script ?

 

***EDIT*** I just found it, thanks for your help Grimes, it works !!! :-D

 

attachment.php?attachmentid=193235&stc=1&d=1535879588

Screen_180902_110350.thumb.png.39e60bc3293e7eb1b7c420f6b857daa2.png


Edited by flo57100
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

mist file

 

hallo, can someone help me.. i am looking for the newest version of the mist file and ctld someone can send it to me or make a link ???? ThX :helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie::helpsmilie:

:joystick::pilotfly::music_whistling:

Link to comment
Share on other sites

Yeah I've been somewhat lazy/distracted with other stuff. I was working on a 4.4 release but never released it. You can grab it from the development branch.

 

Since I'm making missions again I might add some stuff and push a release.

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

  • 1 month later...

Hi Grimes,

Not sure why this stuff is not working anymore. See the snippet below

 

local zonesClone = mist.utils.deepCopy(mist.DBs.zonesByName)
env.info('mistDBZone size = ' .. #mist.DBs.zonesByName)
env.info('cloneZone size = ' .. #zonesClone)

 

Both of them return 0. I am loading mist at time 1 second and this script at 10 seconds after. When I dump DB's I see all zones in the dump file. Funny stuff is that in another script I made they work just fine.

[sIGPIC]OK[/sIGPIC]

Link to comment
Share on other sites

#table has limitations in lua. It only works if items are indexed numerically. It will return a correct value on the mist.DBs.zonesByNum table but not mist.DBs.zonesByName.

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