Jump to content

Recommended Posts

Posted

Hi!

 

So I need some help with getAmmo. Or I need some help with picking out info from tables rather.

 

I don’t know how to format a function that if say an F-16 has no Mavericks then from a getAmmo table. I could use a nudge in the right direction here.

Posted

Its fairly straight forward in that you have to iterate the table. Suppose most of the choice is down to how you want to determine if there are mavs or not. There are basically two main ways go about doing it, searching the string of the typename or display name, and using other values in the desc sub-table to figure out the approximate use of a given weapon.

 

The first is quite simple. Make a table list of the type name or display names, iterate through ammo table, if that entry exists then do whatever it is you want to do for a given check...

 

local mav = {['AGM-65D'] =0, ['AGM-65H'] = 0}
local totMavs = 0
local ammo = Unit.getAmmo(whatever)
if ammo and #ammo > 0 then
   for i = 1, # ammo do
        if mav[ammo[i].desc.displayName] then 
               mav[ammo[i].desc.displayName] = ammo[i].count
               totMavs = totMavs  + ammo[i].count
        end 

   end

end 

That will populate your mav table with however many missiles it has and add to a totMavs number value.

 

A slightly different way would be to search for part of a string value, this is most useful if you want to broadly categorize a certain type of missile. Could even break it down to being more generalized by searching for just 'AGM'.

 

local totMavs = 0
local ammo = Unit.getAmmo(whatever)
if ammo and #ammo > 0 then
   for i = 1, # ammo do
        if string.find(ammo[i].desc.displayName, 'AGM-65') then 
               totMavs = totMavs  + ammo[i].count
        end 

   end
end 

 

The other option is more of a generalization for if you had certain rules for AI based on the weapons they have without making a full itemized list of every single weapon. For reference: https://wiki.hoggitworld.com/view/DCS_Class_Weapon

 

desc.category = 1 -- it is a missile

desc.missileCategory = 6 -- it is an a2g weapon

desc.rangeMaxAltMax = whatever -- gives you an idea of max range

desc.rangeMaxAltMin = whatever2 -- lets you know its not a super long range weapon

desc.guidance = 1 or 6 -- its an ir or tv seeker, so lock range is also limited by that. tv limited by light conditions

desc.box = {} - gives an idea of the physical size of the weapon

desc.warhead -- gives an idea of how much boom boom it can do.

 

With that information at hand you can iterate through and get a rough idea of the type of weapons an aircraft has on board and their use.

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

  • Recently Browsing   0 members

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