Announcement

Collapse
No announcement yet.

Help with function getAmmo

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with function getAmmo

    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.

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

    Code:
    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'.

    Code:
    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: Scripting Wiki, Something...
    Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

    Comment


      #3
      thanks for that great reply grimes, it has some really usefull info in there
      Click here for tutorials for using Virpil Hardware and Software


      Click here for Virpil Flight equipment dimensions and pictures.
      .

      Comment

      Working...
      X