Advertisement
Guest User

FTD Stagger Fire Weapon Slot

a guest
Apr 6th, 2020
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. -- Stagger Fire Weapon Group Controller
  2. -- Use Local Weapon Controllers as usual for targeting, but set their Max_Firerate to 0
  3.  
  4. -- SET THESE FOR USE
  5. weapon_slot = 1       -- assign firing pieces to slot,
  6. interval = 0.500      -- in seconds; use multiples of 0.025s since 1 physics frame = 0.025s
  7. mainframe_index = 0   -- 0 for first mainframe placed, 1 for second, etc...
  8.  
  9. -- DON'T CHANGE ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
  10. -- initialize global variables
  11. next_weapon = 0
  12. weapon_count = 0
  13. last_fired_time = 0
  14. initialize = true
  15. weapon_ID = {}
  16.  
  17. function Update(I)
  18.   if (initialize == true) then
  19.    
  20.     local_weapon_count = I:GetWeaponCount()
  21.     for w = 0,local_weapon_count do
  22.       if (I:GetWeaponInfo(w)['Valid'] == true) then
  23.         weapon_info = I:GetWeaponInfo(w)
  24.         if (weapon_info['WeaponType'] < 4 and weapon_info['WeaponSlot'] == weapon_slot) then
  25.           weapon_ID[weapon_count] = {-1, w}
  26.           weapon_count = weapon_count + 1
  27.         end
  28.       end
  29.     end
  30.  
  31.     turrets = I:GetAllSubConstructs()
  32.     for t = 1,#turrets do
  33.       ScanTurret(I, turrets[t])
  34.     end
  35.    
  36.     initialize = false
  37.   end
  38.  
  39.   if (I:GetAIFiringMode(mainframe_index) == 'On' and #weapon_ID > 0) then
  40.     if (I:GetNumberOfTargets(mainframe_index) > 0) then
  41.       if (I:GetGameTime() - last_fired_time >= interval) then
  42.         if (weapon_ID[next_weapon][1] == -1) then
  43.           if (I:FireWeapon(weapon_ID[next_weapon][2],weapon_slot)) then
  44.             last_fired_time = I:GetGameTime()
  45.             next_weapon = (next_weapon + 1) % weapon_count
  46.           else
  47.             FireAnything(I)
  48.           end
  49.         else
  50.           if (I:FireWeaponOnSubConstruct(weapon_ID[next_weapon][1],weapon_ID[next_weapon][2],weapon_slot)) then
  51.             last_fired_time = I:GetGameTime()
  52.             next_weapon = (next_weapon + 1) % weapon_count
  53.           else
  54.             FireAnything(I)
  55.           end
  56.         end
  57.       end
  58.     end
  59.   end
  60.  
  61.   if (#weapon_ID == 0) then
  62.     I:Log("No Weapons Found!")
  63.   end
  64. end
  65.  
  66. function FireAnything(I)
  67.   for i=0,#weapon_ID do
  68.     if (weapon_ID[i][1] == -1) then
  69.       if (I:FireWeapon(weapon_ID[i][2],weapon_slot)) then
  70.         last_fired_time = I:GetGameTime()
  71.         break
  72.       end
  73.     else
  74.       if (I:FireWeaponOnSubConstruct(weapon_ID[i][1],weapon_ID[i][2],weapon_slot)) then
  75.         last_fired_time = I:GetGameTime()
  76.         break
  77.       end
  78.     end
  79.   end
  80. end
  81.  
  82. function ScanTurret(I, turret_ID)
  83.   local_weapon_count = I:GetWeaponCountOnSubConstruct(turret_ID)
  84.   for w = 0,local_weapon_count do
  85.     if (I:GetWeaponInfoOnSubConstruct(turret_ID, w)['Valid'] == true) then
  86.       weapon_info = I:GetWeaponInfoOnSubConstruct(turret_ID, w)
  87.       if (weapon_info['WeaponType'] < 4 and weapon_info['WeaponSlot'] == weapon_slot) then
  88.         weapon_ID[weapon_count] = {turret_ID, w}
  89.         weapon_count = weapon_count + 1
  90.       end
  91.     end
  92.   end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement