Hard Light Productions Forums
Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: killface on August 26, 2008, 05:30:45 pm
-
Is it possible to use a SEXP or a table edit to limit the ammunition in a cap ship turret? I would love cap ship turrets that run out of ammo.
-
Lock them after x seconds. :p
-
Well, there is always that. :p Any way to ACTUALLY limit ammunition on turrets?
-
Yeah, there's a way. You have to give all of the weapons a cargo size in the table, and then give the turret pbank ammo or sbank ammo. Note that how much ammo a turret has can be modified in any mission.
-
Hmmm, I knew about the cargo size thing, but the pbank / sbank ammo is new to me. What about this: is it possible to define a SEXP that can check for a turret's ammunition level? Basically I want a capital ship to have to warp out once its turrets are depleted or near-depleted.
-
Untested, aside from checking for any real big syntax errors.
turretsLow-sct.tbm
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
tL_ammoThreshold = 0.2 --How low ammo has to be to be 'low'
tL_subsystemThreshold = 0.8 --How many subsystems need low ammo for ship to be 'low'
function turretsLow(shipName)
local ship = mn.Ships[shipName]
--If ship doesn't exist or is dead,
--it doesn't need ammo
if not ship:isValid() then
return 0
end
local numSubsystems = #ship
local numLowSubsystems = 0
for i=1,numSubsystems do
local subsystem = ship[i]
local primariesLow = false
--Primaries
local numBanks = #subsystem.PrimaryBanks
for j=1,numBanks do
local bank = subsystem.PrimaryBanks[j]
if (bank.AmmoLeft / bank.AmmoMax) <= tL_ammoThreshold then
primariesLow = true
break
end
end
if primariesLow then
numLowSubsystems = numLowSubsystems+1
else
--Secondaries
local numBanks = #subsystem.SecondaryBanks
for j=1,numBanks do
local bank = subsystem.SecondaryBanks[j]
if (bank.AmmoLeft / bank.AmmoMax) <= tL_ammoThreshold then
numLowSubsystems = numLowSubsystems+1
break
end
end
end
--Do we have enough low subsystems now that the ship is low on ammo?
if (numLowSubsystems/numSubsystems) >= tL_subsystemThreshold then
return 1
end
end
return 0
end
]
#End
In FRED:
-- when
--- =
---- script-eval-num "turretsLow("GTD Vindicator")"
---- 1
--- ai-warp-out
---- "GTD Vindicator"
EDIT: I don't know how Lua will handle things if AmmoMax is <= 0, so that would probably need to be updated if some of the turrets on a ship don't have ammo-limited guns.
EDIT 2: Forgot to index by 1 rather than 0. Fixed in the example.