Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Stagger Fire Weapon Group Controller
- -- Use Local Weapon Controllers as usual for targeting, but set their Max_Firerate to 0
- -- SET THESE FOR USE
- weapon_slot = 1 -- assign firing pieces to slot,
- interval = 0.500 -- in seconds; use multiples of 0.025s since 1 physics frame = 0.025s
- mainframe_index = 0 -- 0 for first mainframe placed, 1 for second, etc...
- -- DON'T CHANGE ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
- -- initialize global variables
- next_weapon = 0
- weapon_count = 0
- last_fired_time = 0
- initialize = true
- weapon_ID = {}
- function Update(I)
- if (initialize == true) then
- local_weapon_count = I:GetWeaponCount()
- for w = 0,local_weapon_count do
- if (I:GetWeaponInfo(w)['Valid'] == true) then
- weapon_info = I:GetWeaponInfo(w)
- if (weapon_info['WeaponType'] < 4 and weapon_info['WeaponSlot'] == weapon_slot) then
- weapon_ID[weapon_count] = {-1, w}
- weapon_count = weapon_count + 1
- end
- end
- end
- turrets = I:GetAllSubConstructs()
- for t = 1,#turrets do
- ScanTurret(I, turrets[t])
- end
- initialize = false
- end
- if (I:GetAIFiringMode(mainframe_index) == 'On' and #weapon_ID > 0) then
- if (I:GetNumberOfTargets(mainframe_index) > 0) then
- if (I:GetGameTime() - last_fired_time >= interval) then
- if (weapon_ID[next_weapon][1] == -1) then
- if (I:FireWeapon(weapon_ID[next_weapon][2],weapon_slot)) then
- last_fired_time = I:GetGameTime()
- next_weapon = (next_weapon + 1) % weapon_count
- else
- FireAnything(I)
- end
- else
- if (I:FireWeaponOnSubConstruct(weapon_ID[next_weapon][1],weapon_ID[next_weapon][2],weapon_slot)) then
- last_fired_time = I:GetGameTime()
- next_weapon = (next_weapon + 1) % weapon_count
- else
- FireAnything(I)
- end
- end
- end
- end
- end
- if (#weapon_ID == 0) then
- I:Log("No Weapons Found!")
- end
- end
- function FireAnything(I)
- for i=0,#weapon_ID do
- if (weapon_ID[i][1] == -1) then
- if (I:FireWeapon(weapon_ID[i][2],weapon_slot)) then
- last_fired_time = I:GetGameTime()
- break
- end
- else
- if (I:FireWeaponOnSubConstruct(weapon_ID[i][1],weapon_ID[i][2],weapon_slot)) then
- last_fired_time = I:GetGameTime()
- break
- end
- end
- end
- end
- function ScanTurret(I, turret_ID)
- local_weapon_count = I:GetWeaponCountOnSubConstruct(turret_ID)
- for w = 0,local_weapon_count do
- if (I:GetWeaponInfoOnSubConstruct(turret_ID, w)['Valid'] == true) then
- weapon_info = I:GetWeaponInfoOnSubConstruct(turret_ID, w)
- if (weapon_info['WeaponType'] < 4 and weapon_info['WeaponSlot'] == weapon_slot) then
- weapon_ID[weapon_count] = {turret_ID, w}
- weapon_count = weapon_count + 1
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement