Advertisement
Guest User

FTD Stagger Fire Multiple Turrets

a guest
Feb 26th, 2020
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. -- Stagger Fire Turret Controller
  2. -- Use Local Weapon Controllers as usual for targeting, but set their Max_Firerate to 0
  3.  
  4. -- SET THESE FOR USE
  5. turret_ID = {1, 2, 3} -- 1 for first turret placed, 2 for second, etc...
  6. interval = 0.250      -- 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.     for i= 1,#turret_ID do
  20.       local_weapon_count = I:GetWeaponCountOnSubConstruct(turret_ID[i])
  21.       for w = 0,local_weapon_count do
  22.         if (I:GetWeaponInfoOnSubConstruct(turret_ID[i], w)['Valid'] == true) then
  23.           if (I:GetWeaponInfoOnSubConstruct(turret_ID[i], w)['WeaponType'] == 0) then
  24.             weapon_ID[weapon_count] = {turret_ID[i], w}
  25.             weapon_count = weapon_count + 1
  26.           end
  27.         end
  28.       end
  29.     end
  30.     initialize = false
  31.   end
  32.  
  33.   if (I:GetAIFiringMode(mainframe_index) == 'On') then
  34.     if (I:GetNumberOfTargets(mainframe_index) > 0) then
  35.       if (I:GetGameTime() - last_fired_time >= interval) then
  36.         if (I:FireWeaponOnSubConstruct(weapon_ID[next_weapon][1],weapon_ID[next_weapon][2],0)) then
  37.           last_fired_time = I:GetGameTime()
  38.           next_weapon = (next_weapon + 1) % weapon_count
  39.         else
  40.           for i=0,#weapon_ID do
  41.             if (I:FireWeaponOnSubConstruct(weapon_ID[i][1],weapon_ID[i][2],0)) then
  42.               last_fired_time = I:GetGameTime()
  43.               break
  44.             end
  45.           end
  46.         end
  47.       end
  48.     end
  49.   end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement