Author Topic: Turret ammunition limit?  (Read 1586 times)

0 Members and 1 Guest are viewing this topic.

Turret ammunition limit?

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.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Turret ammunition limit?
Lock them after x seconds. :p
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: Turret ammunition limit?

Well, there is always that.   :p   Any way to ACTUALLY limit ammunition on turrets?

 

Offline blowfish

  • 211
  • Join the cult of KILL MY ROUTER!!!!!!!!!!1
Re: Turret ammunition limit?
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.

 
Re: Turret ammunition limit?

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.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Turret ammunition limit?
Untested, aside from checking for any real big syntax errors.

turretsLow-sct.tbm
Code: [Select]
#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.
« Last Edit: August 28, 2008, 04:10:26 am by WMCoolmon »
-C