Jump to content

Understanding ME : scripting functions


CougarFFW04

Recommended Posts

Hi everybody,

 

 

Could someone point me the right place to find an exhaustive list of the "functions" associated with the ME functionalities ?

 

 

I would like to use them in lua scripts and I was sucessful to find some of them (for exemple the setUserFlag, ouText, getTime,... from the scripting function in https://wiki.hoggitworld.com/view/Hoggit_DCS_World_Wiki) but unable to find some other (like "Part of Group in Zone", "Random", "Group Activate",...).

 

 

I am also wondering how to interact with a specific unit ? Lets' immagine that I spawn a group of 4 M200. how do I refer to them in a script ?

 

 

Thanks

Link to comment
Share on other sites

You can access groups/units through the getByName function-

https://wiki.hoggitworld.com/view/DCS_func_getByName

 

I.E. local planes=group.getByName('M2000s') where "M2000s" is the name of the group in the Mission Editor.

 

Not sure about the other stuff; I tend to only venture into .lua world when there's something that can't be done easily (or at all) in the GUI...things tend to be a bit more finicky over time in .lua land.

 

I know MOOSE and MiST have group in zone functions built in as well as the option to use polygonal zones.

Link to comment
Share on other sites

I know MOOSE and MiST have group in zone functions built in as well as the option to use polygonal zones.

 

I'm not very good with Mist, but here's what Moose has for zone tests and polygon zones.

The State Military (MAG 13)

 

[sIGPIC][/sIGPIC]



 

SHEEP WE-01

AV-8B BuNo 164553

VMA-214

Col J. “Poe” Rasmussen

http://www.statelyfe.com

 

Specs: Gigabyte Z390 Pro Wifi; i9-9900K; EVGA 2080 Ti Black; 32GB Corsair Vengeance LPX DDR4; Samsung 970 EVO Series M.2 SSD; WIN10; ASUS VG248QE; CV-1 and Index



Modules: A-10C; AV8B; CA; FC3; F-5; F-14; F-18; F-86; HAWK; L-39; P-51; UH1H; NTTR; Normandy; Persian Gulf

Link to comment
Share on other sites

A lot of the mission editor functionality is available in the scripting engine by doing the same basic code that the triggers would be running internally. Additionally there are built in lua functions available.

 

Random for example would utilize math.random()

 

A strict interpretation of how it works in the editor is basically like this:

 

local function triggerRandom(x)
   if math.random(100) < x then
       return true
   end
end

 

Part of group in zone is more complicated but fairly straight forward. The complicated aspect of it is the math involved.

 

local function partOfGroupInZone(groupName, zoneName, req)
   local units = Group.getByName(groupName):getUnits()
   local zone = trigger.misc.getZone(zoneName)
   local unitsInZone = 0
   local neededInZone = req or 0
   for i = 1, #units do
       local unit_pos = Unit.getPosition(units[i]).p
       if (((unit_pos.x - zone.x)^2 + (unit_pos.z - zone.z)^2)^0.5 <= zone.radius) then
           unitsInZone = unitsInZone + 1
       end
   end 
   if unitsInZone > neededInZone then
       return true
   end
   return false
end

 

An important lesson to take from this is that you have to account for any errors that might occur. For example with the partOfGroupInZone function I created up there assumes that the group object is still accessible. If Group.etByName() returned nil, then the function would create an error when trying to run getUnits().

 

mist, moose, atme, ctld, etc. each focus on providing some functionality or ease of use. Instead of having to rewrite a given functionality each time it just gets loaded into an accessible function call and its up to you to decide whether or not to use it, or even how to use it.

 

The mist function getUnitsInZones() can be fed any combination of units. I could fairly easily find a list of all M1 Abrams for example and see how many are in a given zone. Can check the distance in 2d or 3d, the latter of which is useful for an aircraft flying over the threat range of an IR sam for instance.

 

 

Point is there are pretty much no trigger conditions available verbatim in the scripting engine, but most of the conditions can be created. The power of the scripting engine comes from that ability to create your own conditions and actions that are much more complex and capable than what it takes to do something with 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

Hi Guys,

 

Thanks for comments.

 

A lot of the mission editor functionality is available in the scripting engine by doing the same basic code that the triggers would be running internally. Additionally there are built in lua functions available.

 

Clear.

 

Point is there are pretty much no trigger conditions available verbatim in the scripting engine, but most of the conditions can be created. The power of the scripting engine comes from that ability to create your own conditions and actions that are much more complex and capable than what it takes to do something with triggers.

 

I just wanted to avoid building the wheel again and again... :book:

As some "functions" are available, I was assuming that ALL were available and that I didn't search the right place... It sounds that I was wrong.

 

Thanks Guys :thumbup:

Link to comment
Share on other sites

I just wanted to avoid building the wheel again and again... :book:

As some "functions" are available, I was assuming that ALL were available and that I didn't search the right place... It sounds that I was wrong.

 

Thanks Guys :thumbup:

 

What I meant was that you have to create the condition instead of clicking on a GUI to create it. Its the difference of clicking at least 10 times to open the trigger menu through modifying the action vs having to type out "if timer.getTime() > 50 then doCode() end".

 

The only conditions that are available in the mission editor but not the scripting engine are signalFlareInZone, Player score/mission score related, and the X: Cockpit conditions. I still use triggers a lot to test out really simple and basic things, or to run simple scripting functions. For anything complex that I decide to make I will likely do it as much as possible with lua. Its simply easier for me to test and debug that way.

 

 

For the sake of example I had a mission that I made over several months with triggers, it ultimately had around 700 triggers in it. It was probably to complex for triggers and it wasn't reliable and triggers broke the logic easily. I rewrote it with lau in around two weeks. To add a new task went from modifying 5 triggers for each individual task, some of which had multiple conditions and actions. With the lua version I just name the group a certain way and the script takes care of most of the work. Plus I can load that same file up in a new mission on different maps, place all the targets I want and name them accordingly, add all the sound files, and it would work without issue.

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

Hi Grimes,

 

 

I am with You.

Scripting facility is really a awesome DCS ME feature.

I have still to a lot of things to learn as i started with DCS editor/script just a few weeks ago but like it a lot :thumbup:

 

 

Happy missions :joystick: :D and happy flying :pilotfly:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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