Jump to content

MIssion Scripting Tools (Mist)- enhancing mission scripting Lua


Recommended Posts

It seems like there's no way, though, to copy one deactivated instance of an aircraft within a small radius of a designated point, at a given altitude distinct from the deactivated group's altitude. My change allows that. Doesn't have to make it into the main release, but it doubled the possibilities for me in my shooting range mission.

 

Alright, that makes sense. Gonna make a slight alteration to make sure AI can't spawn in the ground accidentally. I think I'll have a minimum clearance of 10-20 meters required for a point above the ground and if they spawn underground or the value is 0, they will spawn at 200m AGL. I think I'll adding that change to 3.6 along with a few other new functions.

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

  • 2 weeks later...

I have some questions regarding zonesByName and I guess general lua syntax. Looking at Mist it appears that the below code will give me a list of red airbases for which there is also a zone of the same name in the mission. I believe zonesByName returns a table of data items about the zone and if the zone doesn't exist it would return an empty table. I believe that the condition as stated below implies a check that the table is not empty and evaluates to true when the zone exists and therefore adds the entry to table redAF.

 

First question, have I understood correctly?

 

 

 

local redAFids = {} --XX8

local redAF = {}

redAFids = coalition.getAirbases(1) --XX8 get list of red airbases

for i = 1, #redAFids do

if mist.DBs.zonesByName[redAFids:getName()] then --XX9 only add airbase if trigger zone present too

redAF = {name=redAFids:getName()} --XX8 build name list

end

end

 

 

 

Second question, just after this I have the following attempt to trap the error when the mission maker doesn't have at least one airfield and therefore one zone with the same name as the airfield. Doing a mist tableshow on table redAF seems to indicate my logic above is ok but I see the error warning below in the log. Why? I thought #redAF would have the number of entries in redAF and this seems to be > 1.

 

 

 

if #redAF < 1 then --XX8 check at least one red base placed in editor

env.warning("There are no red bases chosen, aborting.", false)

end

 

 

 

3rd question, is there a better way to check for a zones existence?

 

Thanks,

Stonehouse

Link to comment
Share on other sites

I thought #redAF would have the number of entries in redAF and this seems to be > 1.

 

In Lua, #table returns the number of elements in a list. Because Lua uses tables for everything, by convention, lists are tables that only have sequential integer keys starting at 1. Internally, the # operator works like the following Lua function:

function listLength(ls)
   local length = 0
   local i = 1
   while ls[i] do
       length = length + 1
       i = i + 1
   end
   return length
end

Your redAF table violates the "sequential integer keys starting at 1" assumption.

Try replacing this line:

redAF[i] = {name=redAFids[i]:getName()} --XX8 build name list

with this:

redAF[#redAF+1] = {name=redAFids[i]:getName()} --XX8 build name list

Link to comment
Share on other sites

  • 2 weeks later...

The airbase suggestion worked thanks Ian.

 

@Grimes,

While testing the CAP GCI script I have noticed the bearing returned from mist.getBRString is pretty much always 6-7 degrees different from the one given. Looking through the mist code for 3.5.37 I can see that eventually getBRString calls mist.utilas.getDIR which calls mist.getNorthCorrection to add a component to the bearing.

 

I am guessing that the deviation between getBRString and the map tool is due to the magnetic deviation? Doing searches seems to indicate there have been past problems with this in DCS. The thing is getNorthCorrection doesn't seem to exist anymore in Mist so I figure it ends up adding zero. I found an old v1.1 of mist and tried to copy the getNorthCorrection function back into to mist3.5.37 but is doesn't seem to work. Is it a case of an old bug getting fixed so you deprecated the getNorthCorrection function but somewhere along the line the bug has come back? Can the getNorthCorrection get reinstated into Mist in a working form so the bearing given match the map or is it harder than that?

 

Thanks,

Stoney

Link to comment
Share on other sites

mist.getNorthCorrection hasn't been removed...

 

Speed wrote the function, but my understanding of it is that the further away from the maps origin you get, the greater a heading error could occur. Because the map is on Cartesian coordinate system, while the headings point to the "real" magnetic north because a lot of physics in the sim actually does compute curvature of the earth.

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

<sigh> sorry just getting blind and stupid in my old age. Sorry. Apologies I must just have done something wrong when I searched for it.

 

So you would expect that sort of error then for a BRA given with the bullseye at Mozdok and the target of the BRA around Nalchik?

 

The return from the BRString is like 244 and the bearing with the map tool is approx. 250ish

Link to comment
Share on other sites

The attached screenshot should give an idea of what is going on.

 

All hail the glory of working in multiple coordinate systems. :music_whistling:

north_corrections.thumb.jpg.d3bfc122e7d03e505dcaf8ba8c9f8b02.jpg

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

LOL ok I see what you mean. From your pic it would appear that the map tool gives the un-North-corrected bearing while the mist function gives the corrected one.

 

Could we get a new switch on those type of functions to choose whether we want it to match the map tool? or does that cause too much grief then because the aircraft systems mostly use the corrected version and people not looking at the map then get the wrong bearing from the message?

Link to comment
Share on other sites

Link to comment
Share on other sites

I once had the same idea and started working on script.

 

I dropped the idea again and never tested the script, but this is what I had so far. The script functions should be complete, but as I said... it is not tested and must be tweaked for sure. Anyhow...

 

--by snafu
--requires MIST
A10Creservedseattable = {}
A10Creservedseattable[1] = { unitname = 'test1'} --unitname of the A10C shall only be taken by certain playernames listed in A10Cplayertable
A10Creservedseattable[2] = { unitname = 'test2'}
A10Creservedseattable[3] = { unitname = 'test3'}
A10Creservedseattable[4] = { unitname = 'test4'}
A10Creservedseattable[5] = { unitname = 'test5'}
A10Creservedseattable[6] = { unitname = 'test6'}
A10Creservedseattable[7] = { unitname = 'test7'}
A10Creservedseattable[8] = { unitname = 'test8'}

A10Cplayertable = {}
A10Cplayertable[1] = { name = 'player1'} --player name, who shall be allowed to use A10C
A10Cplayertable[2] = { name = 'player2'}
A10Cplayertable[3] = { name = 'player3'}
A10Cplayertable[4] = { name = 'player4'}
A10Cplayertable[5] = { name = 'player5'}
A10Cplayertable[6] = { name = 'player6'}
A10Cplayertable[7] = { name = 'player7'}
A10Cplayertable[8] = { name = 'player8'}

function checkallreservedA10C()

   for index, unitData in pairs(mist.DBs.aliveUnits) 
   do    
       if unitData.category ~= nil and (unitData.category == "plane")
       then
           if unitData.unitName ~= nil 
           then
               local currentaircraftunitname = unitData.unitName
               if Unit.getByName(currentaircraftunitname) ~= nil
               then
                   local currentaircraftunit = Unit.getByName(currentaircraftunitname)
                   if Unit.getPlayerName(currentaircraftunit) ~= nil
                   then
                       for i=1,#A10Creservedseattable
                       do
                           if currentaircraftunitname == A10Creservedseattable[i].unitname
                           then
                               currentplayerclearedforac = false
                               for j=1,#A10Cplayertable
                               do
                                   
                                   local currentplayername = Unit.getPlayerName(currentaircraftunit)
                                   if currentplayerclearedforac == false and currentplayername == A10Cplayertable[j].name
                                   then
                                       currentplayerclearedforac =true
                                       
                                   end
                               end
                               
                               if currentplayerclearedforac == false
                               then
                                   local currentplayergroup = Unit.getGroup(currentaircraftunit)
                                   local currentplayergroupID = Group.getID(currentplayergroup)
                                   trigger.action.outTextForGroup(currentplayergroupID,"1st Warning! You are not cleared for this A/C.",10)
                                   timer.scheduleFunction(givewarning, currentaircraftunitname, timer.getTime() + 10)
                               end
                           end
                       end
                   end
               end
           end
       end
   end
return timer.getTime() + 40
end    
timer.scheduleFunction(checkallreservedA10C, nil, timer.getTime() + 3)

function givewarning(unitnametowarn)

   local currentaircraftunitname = unitnametowarn
   if Unit.getByName(currentaircraftunitname) == nil
   then
       return
   else
       local currentaircraftunit = Unit.getByName(currentaircraftunitname)
       if Unit.getGroup(currentaircraftunit) == nil
       then
           return
       else
           local currentplayergroup = Unit.getGroup(currentaircraftunit)
           local currentplayergroupID = Group.getID(currentplayergroup)
           trigger.action.outTextForGroup(currentplayergroupID,"2nd Warning! You are not cleared for this A/C. Choose another A/C",10)
           timer.scheduleFunction(removeAC, currentaircraftunitname, timer.getTime() + 10)
       end
   end
end

function removeAC(unitnametoremove)
   
   local currentaircraftunitname = unitnametoremove
   if Unit.getByName(currentaircraftunitname) == nil
   then
       return
   else
       local currentaircraftunit = Unit.getByName(currentaircraftunitname)
       if Unit.getGroup(currentaircraftunit) == nil
       then
           return
       else
           local currentplayergroup = Unit.getGroup(currentaircraftunit)
           local currentplayergroupID = Group.getID(currentplayergroup)
           trigger.action.outTextForGroup(currentplayergroupID,"Aircraft is removed!",10)
           currentplayergroup:destroy()
       end
   end

end

There you also see how to get the playername...

 

PS: Corrected the code above, so it should be ok now.


Edited by SNAFU

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

ok, first of all, BIG THANKS. now i only have to know how to adjust and use it to test this...would be needed for a wwii server, so for fw190s, p51s, and hopefully soon the 109.

also, this script only dedects the name of the player?so if another guy then just changed his name he would be able to join the aircraft right?

thx again

Link to comment
Share on other sites

LUA is quite simple and the script is quite simple, too... even I managed to handle it. :smilewink:

 

Here is a small how to implement a script file in a mission:

 

How to:

-0 Download MIST by Grimes/Speed on (http://forums.eagle.ru/showpost.php?p=1622305&postcount=3) and the MIST Manual

-1 Open Mission Editor (ME) and choose coalitions

-2 Open "Trigger Page" by pressing icon on the left side row of the ME

-3 Choose a lua file which shall be initialized at the start of the mission by opening file-menu in bottom line on the "Trigger Page" and initialize MIST by choosing the latest MIST*.LUA, you just downloaded

-4 Create a new Trigger by pressing: ONCE -> TIME IS MORE (5) -> MESSAGE TO ALL ("Test Script loaded", 10 sec) + DO SCRIPT FILE (reserveunits_v0.LUA)

-5 insert a plane and name the unit and group as listed in "A10Creservedseattable[1]..[8]", here "test1"

-6 modify the script and insert in "A10Cplayertable[1]..[8]" the player names (network setup), here 'player1', which shall be allow to use the unit listed in "A10Creservedseattable[1]..[8]"

-7 save mission and press green icon for testing

 

For editing the scrip-file, which you need to do, do insert the player names you want to reserve some units to, and to correct some errors, which will pop up, at mission start, I recommend you download Notepad++, which is for free and a better tool, than the default windows Notepad.

reserveunits_v0.lua

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

A10Creservedseattable[1] = { unitname = 'test1'}

Here replace 'test1' with the unitname of the unit, which shall be reserved for the players, with the names listed in

 

A10Cplayertable[1] = { name = 'player1" }

 

 

Replace 'player1' with 'DavidRed', if this is your online name. That is all you need to modify in the script... in theory.;)

[sIGPIC][/sIGPIC]

 

Unsere Facebook-Seite

Link to comment
Share on other sites

well i dont know the exact definition of UCID, but i think this is a unique number for each dcs player.with slmod for example you can ban players either by name or UCID.

 

anyway, a little more testing showed that when having the trigger set to once- then it will only work once.

on mission start-doesnt seem to work

switched condition-doesnt seem to work

coninuous action-seems to work, but i get only the first warning and then the plane is removed.and i have yet to test, if i then can join the plane successfully when another player already tried to spawn in it.yet i have only tested this alone.so either with the correct name or a fake name.

Link to comment
Share on other sites

  • 2 weeks later...

@Grimes,

 

Just tried the mist respawn with ramp & uncontrolled.

It seemed that it does not work that way, it just spawned them airborne and controlled.

 

Any chance you can have a look at MIST to add it on the next version?

Would be lots of work to get into the respawn script there for someone who doesn't know it to start with.

 

Here is the relevant from MIST I believe -

 

mist.getGroupData = function(gpName)
local found = false
local newData = {}
if mist.DBs.groupsByName[gpName] then
	newData = mist.utils.deepCopy(mist.DBs.groupsByName[gpName])
	found = true
end				

if found == false then
	for groupName, groupData in pairs(mist.DBs.groupsByName) do
		if mist.stringMatch(groupName, gpName) == true then
			newData = mist.utils.deepCopy(groupData)
			newData.groupName = groupName
			found = true
			break
		end
	end
end

local payloads
if newData.category == 'plane' or newData.category == 'helicopter' then
	payloads = mist.getGroupPayload(newData.groupName)
end
if found == true then
	newData.hidden = false -- maybe add this to DBs

	for unitNum, unitData in pairs(newData.units) do
		newData.units[unitNum] = {}
		
		newData.units[unitNum]["unitId"] = unitData.unitId
		--newData.units[unitNum]['point'] = unitData.point
		newData.units[unitNum]['x'] = unitData.point.x
		newData.units[unitNum]['y'] = unitData.point.y
		newData.units[unitNum]['alt'] = unitData.alt
		newData.units[unitNum]['alt_type'] = unitData.alt_type
		newData.units[unitNum]['speed'] = unitData.speed
		newData.units[unitNum]["type"] = unitData.type
		newData.units[unitNum]["skill"] = unitData.skill
		newData.units[unitNum]["unitName"] = unitData.unitName
		newData.units[unitNum]["heading"] = unitData.heading -- added to DBs
		newData.units[unitNum]["playerCanDrive"] = unitData.playerCanDrive -- added to DBs
		
		
		if newData.category == 'plane' or newData.category == 'helicopter' then
			newData.units[unitNum]["payload"] = payloads[unitNum]
			newData.units[unitNum]['livery_id'] = unitData.livery_id
			newData.units[unitNum]['onboard_num'] = unitData.onboard_num
			newData.units[unitNum]['callsign'] = unitData.callsign
		end
	end
	
	return newData	
else
	env.info(gpName .. ' not found in mist.getGroupData')
	return
end
end


Edited by xcom
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...