Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: Dragon on March 26, 2012, 03:59:39 pm

Title: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 26, 2012, 03:59:39 pm
Most people here are familiar with Capship Command script from BP. It allows control over Karuna's turrets, draws brackets over their targets and comes with a handy rangefinder for long ships. The problem is, it only works for Karuna and, in R2, Custos.
I've wanted to adopt this script for other mods, but found it impractical, difficult and uncomfortable. So, I've asked my father, who's a Delphi programmer (He's not a member of this community, but he usually goes by "Tygrys" (Polish for Tiger), so let's call him that) if he could take a look at this script and modify it. Turned out he didn't knew LUA nor FS-specific scripting, but he did it anyway. :) I've helped him with some FS-specific parts, explaining how things works, and handled testing the whole thing. Anyway, here's the result:

Credits:
The_E: The original CSC script. Without him, I wouln't have even thought it's possible.
Tygrys: All modifications to the script. Almost all bits of code that weren't originally there were done by him.
m!m: Final cleanup and some small changes to the code.
Dragon: Testing and teaching Tygrys how FSO works. And the idea. :)

Usage:
At the very beggining of the script, you define the keys you want it to use.
Just edit the part after "ui_keyToggleFunctions". Defaults are arrow keys and 0.
Up-down cycles turret groups, left-right cycles modes.
Available modes are:
"Auto"-AI handles targetting.
"Track"-Turret fires at the current target.
"Lock"-Turret fires on a target locked by pressing "0" (by default).
"Offline"-Turret doesn't fire.

About 2/3 way down the script, you'll encouncer a section marked with "--config stuff start" comment. That's were you define mod-specific stuff.
There are comments in that section explaining what to do.

Near the end of the script, there are two lines, marked with a comment:
Code: [Select]
--The Shieldman and Betty script overrides
ShieldmanOverride = true
BettyOverride = true
The first one overrides shield manager script, the second one overrides the Betty (CAWS) script.
Set them to "false" if you don't want them to be overriden. Note, if you chose to set ShieldmanOverride to false, you must edit the key assignments, as they will clash (Shield Manager also uses arrow keys). Also, don't touch two similar lines at the very end of the script, which aren't marked with a comment. Those always need to be false.

The example configuration should be capable of acting as a drop-in replacement for WiH CSC script. I've tested it with The Blade Itself, among other missions.

Now, installation:
Copy this into csc-sct.tbm :
Code: [Select]
;The CSC script. No longer messy and unreadable. Allows effective control over capital ship turrets.

#Conditional Hooks

$Application: FS2_Open

$On Key Pressed: [[csc_KeyPressed.lua]]
$On Key Released: [[csc_KeyReleased.lua]]

$On Game Init:
[
ui_keyToggleFunctions = {}
InputStates = {}

ui_keyToggleFunctions["Up Arrow"]    = function(val) InputStates.up    = val end
ui_keyToggleFunctions["Down Arrow"]  = function(val) InputStates.down  = val end
ui_keyToggleFunctions["Left Arrow"]  = function(val) InputStates.left  = val end
ui_keyToggleFunctions["Right Arrow"] = function(val) InputStates.right = val end
ui_keyToggleFunctions["0"] = function(val) InputStates.zero = val end

function getTargetName(target)
local targetname
if target then
local targetship = mn.getObjectFromSignature(target:getSignature())
if targetship:isValid() then
if targetship:getBreedName() == "Ship" then
targetname = targetship.Name
end
else
targetname = "None"
end
else
targetname = "None"
end
return targetname
end

function getTargetClass(target)
local targetname
if target then
local targetship = mn.getObjectFromSignature(target:getSignature())
if targetship:isValid() then
if targetship:getBreedName() == "Ship" then
targetname = targetship.Class.Type.Name
end
else
targetname = "None"
end
else
targetname = "None"
end
return targetname
end

function setTurretColor(weapon)
gr.setColor(csc.turretColors[weapon][1], csc.turretColors[weapon][2], csc.turretColors[weapon][3])
end

function drawTurretUI()
local sel = csc.shipdef[csc.shipIdx].turretControl[csc.acnum]
local weapon

gr.drawString("", 5, gr.getScreenHeight() * 0.6)

for i = 1, #csc.shipdef[csc.shipIdx].turretControl, 1 do
weapon = csc.shipdef[csc.shipIdx].turretControl[i]
ba.print("CSC: ui: " .. weapon)
if sel == weapon then
gr.setColor(255, 255, 255)
else
setTurretColor(weapon)
end
gr.drawString(csc.turretDisplay[weapon] .. csc.turretMode[weapon][csc.turretStatus[weapon]])
setTurretColor(weapon)
for i = 1, #csc.turretGroup[weapon], 1 do
local targetname = getTargetName(csc.turretGroup[weapon][i].Target)
if not targetname then targetname = "None" end
if weapon == "pd" then
gr.drawString("  PD Turret: " .. targetname)
else
gr.drawString("  " .. csc.turretGroup[weapon][i].Name .. ": " .. targetname)
end
end
end

gr.setColor(255, 255, 255)
local targetname = getTargetName(csc.CurrentTarget)
local classname = getTargetClass(csc.CurrentTarget)
if not classname then classname = "None" end
if not targetname then targetname = "Invalid" end
gr.drawString("Current Target: " .. targetname .. " Class: " .. classname)
end

function fillturretlist(ship)
local turretnum = 1
ba.print("CSC: Entered fillturretlist\n")
csc.turrets = {}
for i = 1, 60, 1 do
if i < 10 then
turretname = "turret0" .. i
else
turretname = "turret" .. i
end

ba.print("CSC: Looking for turret: " .. turretname .. "\n")

if ship[turretname]:isValid() then
csc.turrets[turretnum] = ship[turretname]
ba.print("CSC: Found Turret.\n")
turretnum = turretnum + 1
end
end
end

function groupTurrets()
ba.print("CSC: Entered GroupTurrets\n")

for i = 1, #csc.turrets, 1 do
if csc.turrets[i].PrimaryBanks[1].WeaponClass:isValid() or csc.turrets[i].SecondaryBanks[1].WeaponClass:isValid() then
for j = 1, #csc.weapondef, 1 do
if string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, csc.weapondef[j].weapon) then
csc.turretGroup[csc.weapondef[j].turret][#csc.turretGroup[csc.weapondef[j].turret] + 1] = csc.turrets[i]
ba.print("CSC: Found " .. csc.weapondef[j].weapon .. ". Turret Number: " .. i .. " weaponnum: " .. #csc.turretGroup[csc.weapondef[j].turret] .. "\n")
end
end
end
end

csc.initComplete = true
end

function drawTargetBraces(weapon)
setTurretColor(weapon)
for i = 1, #csc.turretGroup[weapon], 1 do
target = csc.turretGroup[weapon][i].Target
if target:isValid() then
gr.drawTargetingBrackets(target, true, csc.turretColors[weapon][4])
end
end
end

function doInput()
MissionTime = mn.getMissionTime()

if OldMissionTime ~= MissionTime and MissionTime ~= 0 then

if InputStates.up and not csc.inputstates.keyup then
csc.acnum = csc.acnum - 1
if csc.acnum == 0 then
csc.acnum = #csc.shipdef[csc.shipIdx].turretControl
end
csc.inputstates.keyup = true
elseif not InputStates.up then
csc.inputstates.keyup = false
end

if InputStates.down and not csc.inputstates.keydown then
csc.acnum = csc.acnum + 1
if csc.acnum == #csc.shipdef[csc.shipIdx].turretControl + 1 then
csc.acnum = 1
end
csc.inputstates.keydown = true
elseif not InputStates.down then
csc.inputstates.keydown = false
end

local weapon = csc.shipdef[csc.shipIdx].turretControl[csc.acnum]
if InputStates.left and not csc.inputstates.keyleft then
if csc.turretStatus[weapon] <= 1 then
csc.turretStatus[weapon] = #csc.turretMode[weapon]
else
csc.turretStatus[weapon] = csc.turretStatus[weapon] - 1
end

csc.inputstates.keyleft = true
elseif not InputStates.left then
csc.inputstates.keyleft = false
end

if InputStates.right and not csc.inputstates.keyright then

if csc.turretStatus[weapon] >= #csc.turretMode[weapon] then
csc.turretStatus[weapon] = 1
else
csc.turretStatus[weapon] = csc.turretStatus[weapon] + 1
end

csc.inputstates.keyright = true
elseif not InputStates.right then
csc.inputstates.keyright = false
end

if InputStates.zero or io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
csc.CurrentTarget = csc.plrship.Target
csc.inputstates.zero = true
elseif not InputStates.zero or not io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
csc.inputstates.zero = false
end
OldMissionTime = MissionTime
end
end

function doTurretMode()
local weapon
for j = 1, #csc.shipdef[csc.shipIdx].turretControl, 1 do
weapon = csc.shipdef[csc.shipIdx].turretControl[j]

if csc.turretStatus[weapon] == 1 then
for i = 1, #csc.turretGroup[weapon] do
csc.turretGroup[weapon][i]:targetingOverride(false)
end
elseif csc.turretStatus[weapon] == 2 then
for i = 1, #csc.turretGroup[weapon] do
csc.turretGroup[weapon][i].Target = csc.plrship.Target
end
elseif csc.turretStatus[weapon] == 3 then
if csc.CurrentTarget then
if csc.CurrentTarget:isValid() then
for i = 1, #csc.turretGroup[weapon] do
csc.turretGroup[weapon][i].Target = csc.CurrentTarget
end
end
end
elseif csc.turretStatus[weapon] == 4 then
for i = 1, #csc.turretGroup[weapon] do
csc.turretGroup[weapon][i]:targetingOverride(true)
end
end
end
end

function drawRangeDisplay()
local turposCount = #csc.shipdef[csc.shipIdx].turretRange
if turposCount > 0 then
csc.range = nil
csc.range = {}
csc.range.Shipname = {}
csc.range.Range = {}
local plrship = hv.Player

local turpos = {}

for j = 1, turposCount, 1 do
  turpos[j] = (plrship.Position + plrship[csc.shipdef[csc.shipIdx].turretRange[j]].Position)
end 

items = 1
for i = 1, #mn.Ships do
local tempship = mn.Ships[i]
local class = getTargetClass(tempship)
if class ~= "Fighter" and class ~= "Bomber" then
if tempship ~= csc.plrship then
local temp = tempship.Position
local tempsum = 0
for j = 1, turposCount, 1 do
  tempsum = tempsum + math.sqrt( (temp[1] - turpos[j][1])^2 + (temp[2] - turpos[j][2])^2 + (temp[3] - turpos[j][3])^2 )
end 
csc.range.Shipname[items] = tempship.Name
csc.range.Range[items] = math.floor( tempsum / turposCount)
items = items + 1
end
end
end

gr.setColor(255,255,255)
gr.drawString("Range:", gr.getScreenWidth() * 0.17, gr.getScreenHeight() * 0.78)
for i = 1, #csc.range.Shipname do
if csc.range.Range[i] < 1000 then
local c = math.floor((csc.range.Range[i] / 4)) + 5
gr.setColor(255, c, c)
gr.drawString("  " .. csc.range.Shipname[i] .. ": " .. csc.range.Range[i])
gr.setColor(255, 255, 255)
else
gr.drawString("  " .. csc.range.Shipname[i] .. ": " .. csc.range.Range[i])
end
end
end
end

function turretInit(weapon, display, r, g, b, p)
csc.turretGroup[weapon] = {}
csc.turretMode[weapon] = {"Automatic", "Track", "Lock", "Offline"}
csc.turretStatus[weapon] = 1
csc.turretColors[weapon] = {r, g, b, p}
csc.turretDisplay[weapon] = display
ba.print("CSC: Turret init " .. weapon .. "\n")
end;

function weaponInit(weapon, turret)
local i = #csc.weapondef + 1
csc.weapondef[i] = {}
csc.weapondef[i].weapon = weapon
csc.weapondef[i].turret = turret
ba.print("CSC: Weapon init " .. weapon .. "\n")
end

function defineTurrets()
csc.turretGroup = {}
csc.turretStatus = {}
csc.turretColors = {}
csc.turretMode = {}
csc.turretDisplay = {}
-- config stuff start
-- turret group, UI display, R, G, B, Brace padding

turretInit("pd", "point defense turrets: ", 61, 93, 255, 8)
turretInit("flak", "flak turrets: ", 61, 93, 255, 8)
turretInit("md", "mass drivers: ", 255, 93, 48, 11)
turretInit("gauss", "gauss cannons: ", 255, 187, 53, 14)
turretInit("torpedo", "apocalypse torpedoes: ", 255, 255, 53, 17)
turretInit("missile", "missile launchers: ", 255, 255, 53, 17)
turretInit("gattler", "gattler: ", 255, 187, 53, 14)
turretInit("rapier", "rapier: ", 255, 187, 53, 14)
end

function defineWeapons()
csc.weapondef = {}

--weaponClassName -> turret group

weaponInit("Point Defense Turret", "pd")
weaponInit("PD Turret#Player", "pd")
weaponInit("Burst Flak", "flak")
weaponInit("Mass Driver", "md")
weaponInit("Gauss Cannon", "gauss")
weaponInit("Apocalypse", "torpedo")
weaponInit("Warhammer", "missile")
weaponInit("Gattler", "gattler")
weaponInit("Rapier", "rapier")
end

function defineShips()
csc.shipdef = {}

local
--Karuna
--Entry number - don't forget to change while copypasting this one
i = 1
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "UEFg Karuna#Player"
--turrets showing target braces
csc.shipdef[i].turretTargets={"pd", "flak", "md", "gauss", "torpedo"}
--turrets aviable in UI
csc.shipdef[i].turretControl={"md", "gauss", "torpedo"}
--turrets to calculate target range
csc.shipdef[i].turretRange={"turret01", "turret02", "turret03", "turret04"}
-- possible turret weapon groups:
-- {"pd", "flak", "md", "gauss", "torpedo", "gattler", "missile"}

--Custos
i = 2
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "UEC Custos#Player"
csc.shipdef[i].turretTargets={"pd", "missile"}
csc.shipdef[i].turretControl={"pd", "missile"}
csc.shipdef[i].turretRange={}
end
-- config stuff end

function cscInit()
csc = {}
if not csc.initComplete then
defineShips()
defineWeapons()
ba.print("CSC: init \n")

if not csc.plrship then
csc.plrship = hv.Player

csc.disable = true

if csc.plrship:getBreedName() == "Ship" then
csc.shipIdx = 0
for i = 1, #csc.shipdef, 1 do
if csc.plrship.Class.Name == csc.shipdef[i].shipClassName then
csc.shipIdx = i
csc.disable = false
ba.print("CSC: Ship found " .. csc.shipdef[i].shipClassName)
end
end
end

if not csc.disable and not csc.turrets then
defineTurrets()
csc.active = {"*", " ", " "}
csc.acnum = 1
csc.inputstates = {}

inputlocked = false

fillturretlist(csc.plrship)
groupTurrets()
--The Shieldman and Betty script overrides
ShieldmanOverride = true
BettyOverride = true
end
end
end
end
]

$On Gameplay Start:
[
if (csc) then
ba.warning("There was already a CSC table present when initing the CSC script!")
end

cscInit()
]

$State: GS_STATE_GAME_PLAY
$On Frame:
[
cscMissionTime = mn.getMissionTime()

if cscMissionTime ~= 0 then
if csc then
if not csc.disable and csc.initComplete then
doInput()
doTurretMode()
for j = 1, #csc.shipdef[csc.shipIdx].turretTargets, 1 do
drawTargetBraces(csc.shipdef[csc.shipIdx].turretTargets[j])
end
end
end
end
]

$On HUD Draw:
[
if csc then
if not csc.disable and csc.initComplete then
drawRangeDisplay()
drawTurretUI()
end
end
]

$On Mission End:
[
csc = nil
ShieldmanOverride = false
BettyOverride = false
]

#End

This goes to csc_KeyPressed.lua , in data\scripts folder. Note that the name might be case-sensitive:
:
Code: [Select]
local key = hv.Key
local func = ui_keyToggleFunctions[key]
if func then
func(true)
end
This goes to csc_KeyReleased.lua , also in data\scripts.
Code: [Select]
local key = hv.Key
local func = ui_keyToggleFunctions[key]
if func then
func(false)
end

End notes:
This is an alpha release, tested by just one person on a few missions. There might be bugs, odd behavior and so on. It should run a bit faster than the original CSC script, but I can't guarantee that. It might work or not work in multiplayer, as I haven't tested it there either. Also not tested with beams, but it should work OK, as it doesn't tackle actual firing process, just targeting.
Another thing is, while this script is ready for use, it's far from comfortable. I would like to make it to use an external configuration file instead of doing everything in the script, but neither I nor Tygrys know how to do that. I though that it should be simple, but m!m told me it isn't. So, I hope that either somebody will come along with time and knownledge needed to do it, or that people will be OK with editing the script to configure their capships.

Anyway, the script is now free to use for all the HLP, in any mod, anytime. For anything with any sort of turrets.
Enjoy.  :)
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: General Battuta on March 26, 2012, 04:08:41 pm
thanks for, uh, discussing this with the team
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: bigchunk1 on March 26, 2012, 04:17:23 pm
I think Droid803 figured out a way to generalise capship command as well.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 26, 2012, 04:52:57 pm
thanks for, uh, discussing this with the team
The CSC script is public anyway, and The_E once said I'm free to edit/let other people edit this script. Granted, it's been a long time, but I've been working on (well, trying to) doing this since then.
Ah, and of course, many thanks to all people who worked on TBI. It was my primary testing mission for this new version of script.
And Droid's solution includes adding ships to the old script, which is a very long, boring and difficult to debug. And it doesn't support turrets with weird names. This one does.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Droid803 on March 26, 2012, 06:20:10 pm
No, mine was super easy to debug actually (it worked the first time, no bugs lol), and didn't take very long at all. You just had no idea what I did. :P
Because I just "replaced" the Karuna with the ship I wanted to use, and just edited the turret references etc, appropriately.

I "generalized" it for any one ship you want.

You shouldn't be using "turrets with weird names" anyway.

How does your implementation group turrets. I don't see a way to 'automatically" do it, you'd have to group them for each ship anyway...
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 26, 2012, 06:43:41 pm
"Turrets with weird names" mean as much as that there's an "a" at the end. In my implemetation to group turrets, you specify the weapon type (once) and the group it belongs to (also once). And that's it. You can also have any number of ship you want by copypasting 4 lines (instead of 40), any number of groups by copypasting one line, and any number of weapons by copypasting another line. Now, try adding all capships in Wing Commander Saga by using your method. Suddenly not so good, eh? Not to mention Tygrys made the script run faster by skipping a ton of redundant calculations.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Droid803 on March 29, 2012, 05:54:14 pm
if you're going to use that stupid logic, two can play at that game! I don't give half a **** about Wing Commander! I wouldn't even implement it for one ship in that, not if you paid me. I don't even have WCS downloaded and I won't, because the way the devs behaved makes it a product I don't want to support. That aside, in my implementation I just edit about 10 lines and voila it works for the one ship I wanted it to work for, don't need to rewrite the whole thing or anything. Suddenly a lot better than what you had to go through to get it to work for a single ship, don't you think? I got it all done in five minutes too!

I don't really care for having it for multiple ships because in what I'm using it for nobody is going to be flying any other capship. Funny, I think that's kind of what the original was written for too, and what it works fine for.

You want to have it for every ship, I couldn't give less of a **** about that I just wanted it to work for my one ship so I could finish that part of the campaign and move on...
I've completed like 10+ missions since then, plus a number of models, while attending university full time to boot. What I did has a totally different purpose from what you're trying to do, don't compare them.

Yes, my solution isn't "elegant", nor does it "generalize" to every ship. I never aimed to do that. You people just decided that I did. :P I just got it to work on a ship that wasn't a Karuna and went WHOPPEE I'M DONE HERE.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 29, 2012, 06:21:58 pm
Well, if you just wanted to repurpose the old script for another mod, then why didn't you say so in your first post?
What I've done was meant to be useful for anyone who'd like to create his own capship mod. WC, Star Trek, FS, whatever. Not to mention to improve performance a bit. Yours had a different, much less ambitious purpose.
Anyway, since we're done with this pointless argument, could somebody test this version in multiplayer, on a beam-armed ship? I've heard that BP Multi has a mission with one player commanding a Deimos, so this could be a good testbed.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: The E on March 30, 2012, 02:09:43 am
Why have the ShieldMan and Betty overrides been placed in the $On Mission End Hook? That's quite possibly the most wrong place they could be in, as this guarantees that Betty and Shieldman will be disabled for the next mission, not the one currently running. To clarify, setting those to true means that the two scripts will _not_ run, and since the scripting environment is not cleared after a mission ends, setting them to false at mission end is the correct thing to do.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 30, 2012, 03:14:10 am
Oh, rats.
I must have been switched that one when I was trying to make Betty work for capships. This segment wasn't really touched, so I'll fix it in second.
EDIT: And done. Changed the overrides, instructions for them, and added a comment above those which actually control Betty and Shieldman in the current mission. Should be fine now.
Thanks, The_E. I haven't really tested this script in a campaign, so I haven't spotted this one.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Deadly in a Shadow on March 30, 2012, 11:59:07 am
That's strange.

I set everything up, but everytime when I start a mission, I get a message:

LUA ERROR:[string "csc-sct.tbm - on game init"]:45: attempt ot index field "? (nil value)
the same error follows, just with 62 instead of 45.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 30, 2012, 12:13:28 pm
What are you using it for? What did you change?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Deadly in a Shadow on March 30, 2012, 12:15:37 pm
What are you using it for? What did you change?
I've only changed the stuff in the config stuff part. I want to use it for the ZGF Archon.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 30, 2012, 12:23:03 pm
Could you post the modified section? I'm going to test it with the ship in question.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Deadly in a Shadow on March 30, 2012, 12:25:21 pm
Here it is.
Code: [Select]
-- config stuff start
-- turret group, UI display, R, G, B, Brace padding

turretInit("plasma", "Plasma Guns: ", 61, 93, 255, 8)
turretInit("Photon", "Photon Cannons: ", 61, 93, 255, 8)
turretInit("Beam", "Beam cannons: ", 255, 93, 48, 11)
turretInit("Homing Lasers", "HL: ", 255, 255, 53, 17)
end

function defineWeapons()
csc.weapondef = {}

--weaponClassName -> turret group

weaponInit("Heavy Plasma cap", "Plasma")
weaponInit("Zy photon cap", "Photon")
weaponInit("Zybeam", "Beamk")
weaponInit("Homing laser huge", "HL")
end

function defineShips()
csc.shipdef = {}

local i = 1

--Archon
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "ZGF Archon#player"
--turrets showing target braces
csc.shipdef[i].turretTargets={"Plasma", "Photon", "Beam", "HL"}
--turrets aviable in UI
csc.shipdef[i].turretControl={"Plasma", "Beam", "HL"}
--turrets to calculate target range
csc.shipdef[i].turretRange={"turret01", "turret02", "turret03", "turret04"}
-- possible turret weapon groups:
-- {"Plasma", "Photon", "Beam", "HL"}
end
-- config stuff end
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 30, 2012, 05:05:56 pm
I'll take a closer look at it tommorow. In the meantime, check cases of all your edits. LUA is case-sensitive in some important places. In other words, wrong case might be the case. *ba-dum-dish* (http://instantrimshot.com/index.php?sound=rimshot)  :)
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: m!m on March 31, 2012, 01:42:59 am
I don't think that that's the problem as that would have caused a more useful error message. It more likely that the weapon index from line 66 is out of bounds and causes the specified error when you try to index the nil value, that would explain the cryptic error message as LUA can't find a "real" name for the value.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on March 31, 2012, 02:45:33 am
OK, I've managed to confirm it with WoD2 files (and it turned out that wrong case is not the case :)).
I'm going to talk to Tygrys about it.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Deadly in a Shadow on March 31, 2012, 04:08:30 am
Ok, thanks for the info. :yes:

EDIT: Oh, found a typo in my entry. It's beam not beamk :D
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 09, 2012, 01:46:29 pm
OK, sorry for not replying for so long, Tygrys' has quite a lot of work on his hands right now.
Anyway, I've found the problem, and it turns out the code isn't bugged at all. The issue is with the config, namely the line:
Code: [Select]
csc.shipdef[i].turretRange={"turret01", "turret02", "turret03", "turret04"} Zy Archon has no such turrets. There are gunturret-00, gunturret-01, etc. Since the script can't find the turrets to check distance from (this part is for the rangefinder), it crashes.
Correct this (if you're not big on having a rangefinder, you can leave the turret list blank), and you should be good to go.
Also, avoid removing stuff from the script. If it doesn't find a weapon, a ship or whatever it'll skip it. Any number of entries can be added, but removing them isn't tested.
I'll PM you a working version of your config.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: k7g on April 13, 2013, 09:36:31 pm
Hello guys,

I've started using this script in a test mission, but every time i attempt to execute the mission (from the briefing/load-out area), the games crashes and gives me this error:

Also this is done with the Default GTCv Deimos.
Code: [Select]
LUA ERROR: [string "csc-sct.tbm - On Game Init"]:45: attempt to index field '?' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name: (null)
Name of: (null)
Function type: (null)
Defined on: 0
Upvalues: 0

Source: (null)
Short source:
Current line: 0
- Function line: 0
------------------------------------------------------------------


------------------------------------------------------------------

stack traceback:
[C]: ?
[string "csc-sct.tbm - On Game Init"]:45: in function 'setTurretColor'
[string "csc-sct.tbm - On Game Init"]:60: in function 'drawTurretUI'
[string "csc-sct.tbm - On HUD Draw"]:4: in main chunk
------------------------------------------------------------------

------------------------------------------------------------------

can anyone explain this one :confused:.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 21, 2013, 03:22:51 pm
Could you post how the config section in the script looks like? Sorry for slow response, but I'm not used to the new forum layout and overlooked the scripting board.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: k7g on April 25, 2013, 01:50:28 am
Could you post how the config section in the script looks like? Sorry for slow response, but I'm not used to the new forum layout and overlooked the scripting board.

Here is the Configurable part of the file that u asked for, changed it to only use "SGreen" beam cannons.

Code: [Select]
-- config stuff start

-- turret group, UI display, R, G, B, Brace padding
turretInit("BC", "Beam cannons: ", 255, 187, 53, 14)

end

function defineWeapons()
csc.weapondef = {}

--weaponClassName -> turret group
weaponInit("SGreen", "BC")

end

function defineShips()
csc.shipdef = {}

local
--Karuna
--Entry number - don't forget to change while copypasting this one
i = 1
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "GTCv DeimosPlayer"

--turrets showing target braces
csc.shipdef[i].turretTargets={"BC"}

--turrets aviable in UI
csc.shipdef[i].turretControl={"BC"}

--turrets to calculate target range
csc.shipdef[i].turretRange={}

-- possible turret weapon groups:
-- {"BC"}

end
-- config stuff end
Maybe it was something i added/deleted by accident?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 25, 2013, 02:45:38 am
Is your ship class called GTCv DeimosPlayer or GTCv Deimos#Player? Also, if this doesn't work, try re-copying the script (to make sure you copied it right) and adding a new config section for the Deimos rather than replacing the Karuna one. Removing sections is nearly untested.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: k7g on April 25, 2013, 03:29:53 am
its is called GTCv DeimosPlayer.

But i get the script to run in game (just removed the a SEXP command  :doubt:) without issues, but when i set the turrets to lock mode or offline mode, the turrets still fire (with the beam-free-all SEXP) as if they are still set to automatic mode or will not fire at all (with the SEXP command and the turrets 'tracking' range reduced to1, to stop AI from firing it...) as if they are in locked mode. I even set the 'fire' button to the spacebar and still nothing is firing or stopping the turrets.

Also, removing the Karuna does not throw any errors to what i can tell. I'll refresh the file and do as u say and see what happens to it. I'll keep u posted

Update:
Ok, i refreshed the file, and added the Deimos in without removing the Karuna. The turrets seem to respond to the offline mode but when u change it to back to lock mode, they begin firing themselves and they do not turn them selves off when put into offline mode again (they keeping they're target), nor will they respond to player fire orders.

PS: After going AFK for awhile, i just realized that my thinking of the script was out :lol:. By pressing "0" its not meant to fire them its meant to lock them onto ur target, and lock mode is for that action *face palm*, and the turrets are meant to fire at one target until its is destroyed or another one is selected *face palm*. I was not thinking at the time, was to busy trying to get it to work a way it was not meant too :lol:
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 25, 2013, 01:06:56 pm
So, I guess it works? Great to know. I wanted to do a "command" mode, which would fire on trigger press, but Tygrys said it would be too complicated for him to do at the time. Besides, it should be possible to implement with some crafty modding and SEXPs.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: General Battuta on April 25, 2013, 01:27:41 pm
It's actually surprisingly difficult. Fire-turret is one of those dream SEXPs we've wanted for a while, but it will require some work.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 25, 2013, 01:45:43 pm
Actually, my current idea is just to give a capship both turrets and primaries/secondaries, using gunpoint normals and autoaim to simulate turrets. This has both limitations and benefits. For example, it limits component space and forces secondaries to have ammo, on the other hand allows you to have ammo-limited weapons and allows you to manage that ammo. AI doesn't take kindly to that kind of setup though, FS definitely could use improvement in this area. That said, I think most of us can live without such a "command" mode. The script works well enough most things.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: BlasterNT on April 26, 2013, 01:18:20 pm
It's actually surprisingly difficult. Fire-turret is one of those dream SEXPs we've wanted for a while, but it will require some work.

Scripting has subsystem.fireWeapon though. 

Actually, my current idea is just to give a capship both turrets and primaries/secondaries, using gunpoint normals and autoaim to simulate turrets. This has both limitations and benefits. For example, it limits component space and forces secondaries to have ammo, on the other hand allows you to have ammo-limited weapons and allows you to manage that ammo. AI doesn't take kindly to that kind of setup though, FS definitely could use improvement in this area. That said, I think most of us can live without such a "command" mode. The script works well enough most things.

That would only work for single-parts, no?  Which I guess most main guns are anyway.  Correct me if I'm wrong, but don't turrets already support ammo limits?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 26, 2013, 02:08:35 pm
No, or at least they don't seem to. Limited ammo on turrets seemed to be in since retail, but IIRC, it never actually worked.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: BlasterNT on April 26, 2013, 02:17:28 pm
Hmm, interesting.  Well, if you wanted to make it player limited (which seems to be the best option, for AI's sake), it would be fairly simple to keep track in scripting, and also create a simple hud gauge to display what's left. 
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on April 27, 2013, 04:16:06 am
However, I'd also like AI to have limited ammo, because I don't like when it when it obviously cheats. Also, it'd be very useful with the RTS script. Maybe it's the way to do it. If the RTS script could control weapon usage of AI ships, ammo management could be a nice gameplay mechanic.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: k7g on May 01, 2013, 10:14:30 pm
Hay dragon,

due to i love this script so much  :P, i started editting the script abit (the non-configable areas  :nervous:), and i came up with this:

Modified turret Init function:
Code: [Select]
function turretInit(weapon, display, r, g, b, p, status)
csc.turretGroup[weapon] = {}
csc.turretMode[weapon] = {"Automatic", "Track", "Lock", "Offline"}
csc.turretStatus[weapon] = status
csc.turretColors[weapon] = {r, g, b, p}
csc.turretDisplay[weapon] = display
ba.print("CSC: Turret init " .. weapon .. "\n")
end;

And the modified turret init section with the new variable:
Code: [Select]
turretInit("pd", "point defense turrets: ", 61, 93, 255, 8, 4)
what this does, if u have not guessed already, it allows u to set the default status of a turret group when u start a mission. And the script still works 100%!  :lol:

so now u can have ur flak and AA-beams on auto; ur main beams on lock/offline; and ur turrets on track, all at once!

i would love it u would add this addition to ur script, to make it more user friendly and customizable.  :pimp:
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on May 02, 2013, 06:26:23 am
I'll give it a try. Did you post everything you changed? Also, could you tell me into which line (by number) this goes?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: BlasterNT on May 02, 2013, 09:54:09 am
presumably you replace the existing turretinit function (search for function turretinit), and the call for that function [search for turretinit("pd" ]
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on May 02, 2013, 10:05:10 am
Well, I guess so. I'll soon give it a try.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: k7g on May 05, 2013, 08:40:46 pm
hay dragon,

firstly, sry i was not clear on my previous post about the modifications, my bad  :banghead:.

secondly, i have saved the files into a .VP file for easy download/install. I have also include a modified deimos (just a view point and flag changes) and a GTD Segomo (based on the Inferno SOD Segomo, with a few extra turret/weapons) + a test mission for them to test they're weapons (the Segomo is fun to use in it  ;7), also it contains new weapons (they are there to allow the cap ships to be used in multi-player due to primary/secondary check...).

But before i uploaded to u, i'm asking for permission to upload it, so u can grab a copy and post it in your main thread if u wish.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on May 06, 2013, 04:38:59 am
I'd be glad to check it out. Note, however, that I'm going to be rather busy next week, don't worry if you don't get a quick response.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: k7g on May 06, 2013, 07:05:12 pm
thats ok dragon, i'll upload the file on this post for u, and hopefully i can get started in learning lua so i can make my own script called C-ACS (Capital-Advanced Control System). Just allows control more control over a capital ship (such as repair systems  ;7, and alert levels etc.). Of course this will not replace your csc script, it will be made to go long side of it  :p

[attachment deleted by ninja]
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: procdrone on December 28, 2013, 12:22:59 pm
Hello.

I know there been some time as the topic is here, but I recently found myself to Freespace modding and wanted to integrate this command system into my WIP mod.

So, I'm getting problems with setting this one up, tried couple of things, none shown any change really...

Here is the part of my code for ship:

Code: [Select]
-- config stuff start
-- turret group, UI display, R, G, B, Brace padding

turretInit("lt", "Laser Turrets: ", 61, 93, 255, 8)
turretInit("aff", "Anti-Fighter Beams: ", 61, 93, 255, 8)
turretInit("flak", "Flak Cannons: ", 255, 93, 48, 11)
turretInit("beams", "Beam Cannons: ", 255, 187, 53, 14)
turretInit("missile", "Missiles: ", 255, 187, 53, 14)
end

function defineWeapons()
csc.weapondef = {}

--weaponClassName -> turret group

weaponInit("Terran Huge Turret", "lt")
weaponInit("AAAf", "aff")
weaponInit("Standard Flak", "flak")
weaponInit("Heavy Flak", "flak")
weaponInit("TerSlash", "beams")
weaponInit("Piranha", "missile")
end

function defineShips()
csc.shipdef = {}

local
--Arpyia
--Entry number - don't forget to change while copypasting this one
i = 1
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "GTVFg Arpyia#Player"
--turrets showing target braces
csc.shipdef[i].turretTargets={"lt", "aff", "flak", "beams", "missile"}
--turrets aviable in UI
csc.shipdef[i].turretControl={"lt", "aff", "flak", "beams", "missile"}
--turrets to calculate target range
csc.shipdef[i].turretRange={"turret01", "turret02", "turret03", "turret04", "turret05",  "turret06", "turret07",  "turret08",  "turret09", "turret10", "turret11", "turret12", "turret13", "turret14", "turret15", "turret16", "turret17", "turret18", "turret19", "turret20", "turret21", "turret22", "turret23", "turret024"}
-- possible turret weapon groups:
-- {"lt", "aff", "flak", "beams", "missile"}


end
-- config stuff end

My problem is, that, only beams and flak turrets fire anyhow, rest i silent, nothing i do turns them on... Im able to change target for beam weapons, but I'm unable to turn them off, also, it seems that flak's follow the targeting of their own, and do not respond to my commands and, also cannot be turned off by the "off-line" state.

Is there a problem in my customization there?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on December 28, 2013, 01:39:34 pm
Try adding stuff instead of replacing. It seems that replacing causes problems sometimes. My father intended this to work like that, probably because he once worked with Freelancer. It appears that this script was written like it was meant to have a "supported ships list" that would be added to, eventually supporting just about every ship out there. Obviously, due to how FS modding works, such approach is unfeasible, but with FL-like setup, this is the default approach.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: procdrone on December 28, 2013, 06:23:31 pm
Thank you Dragon, I'll check this solution out, and give you possible feedback on what happened, and if it worked the way I wanted :) (It's to late for doing this now :) )
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: procdrone on December 29, 2013, 11:53:22 am
Alright, i managed to test out your adivce, it helped, partialy, but somehow it helped.

Here is the fragments for ship tables and the configurable script itself:

Code: [Select]
#Ship Classes


$Name: GTVFg Arpyia#Player
$Short name: TaaCor
$Species: Terran
+Tech Description:
XSTR("RNI systems and Ahketon Corporation collaborated to produce Arpyia-class frigate based on demands from the GTVA security council requesting a tactical rapid-response craft with carrier capability. Taking notes from the design of the successful Deimos-class corvette, the first Arpyia class elegantly integrates a a large fighterbay into well-rounded frame. The first Arpyia class vessel launched six years after the Capella incident.", -1)
$end_multi_text
$POF file: arpyia.pof
$Detail distance: (0, 1350, 8000)
$Show damage: YES
$Density: 1
$Damp: 0.2
$Rotdamp: 2.0
$Max Velocity: 0.0, 0.0, 28.0
$Rotation time: 140.0, 140.0, 100.0
$Rear Velocity: 0.0
$Forward accel: 8.0
$Forward decel: 4.0
$Slide accel: 0.0
$Slide decel: 0.0
$Expl inner rad: 150.0
$Expl outer rad: 750.0
$Expl damage: 200.0
$Expl blast: 11000.0
$Expl Propagates: YES ;; If set to Yes, then when the ship dies, the explosion propagates through it.
$Shockwave Speed: 400.0 ;; speed shockwave expands at, 0 means no shockwave
$Shockwave Count: 3
$Default PBanks: ()
$Default SBanks: ()
$SBank Capacity: ()
$Shields: 0
$Power Output: 200.0
$Max Oclk Speed: 60.0
$Max Weapon Eng: 200.0
$Hitpoints: 100000
$Flags: ( "big damage" "corvette" "in tech database" "player_ship" )
$AI Class: Captain
$Afterburner: NO
$Countermeasures: 0
$Scan time: 2000
$EngineSnd: 128 ;; Engine sound of ship
$Closeup_pos: 0.0, 0.0, -1000
$Closeup_zoom: 0.5
$Score: 1100
$Subsystem: turret01,0.625, 2.0
$Default PBanks: ( "TerSlash" )
$Subsystem: turret02,0.625, 2.0
$Default PBanks: ( "TerSlash" )
$Subsystem: turret03,0.625, 2.0
$Default PBanks: ( "TerSlash" )
$Subsystem: turret04,0.625, 2.0
$Default PBanks: ( "TerSlash" )
$Subsystem: turret05,0.833,1.0
$Default PBanks: ( "AAAf" )
$Subsystem: turret06,0.833,1.0
$Default PBanks: ( "AAAf" )
$Subsystem: turret07,0.833,1.0
$Default PBanks: ( "AAAf" )
$Subsystem: turret08,0.833,1.0
$Default PBanks: ( "AAAf" )
$Subsystem: turret09,0.833,1.0
$Default PBanks: ( "AAAf" )
$Subsystem: turret10,0.833,1.0
$Default PBanks: ( "Standard Flak" )
$Subsystem: turret11,0.833,1.0
$Default PBanks: ( "Standard Flak" )
$Subsystem: turret12,0.833,1.0
$Default PBanks: ( "TerSlash" )
$Subsystem: turret13,0.833,1.0
$Default PBanks: ( "Standard Flak" )
$Subsystem: turret14,1.875, 3.0
$Default PBanks: ( "Heavy Flak" )
$Subsystem: turret15,1.875, 3.0
$Default PBanks: ( "Heavy Flak" )
$Subsystem: turret16,0.833,1.0
$Default PBanks: ( "Piranha" )
$Subsystem: turret17,0.833,1.0
$Default PBanks: ( "Piranha" )
$Subsystem: turret18,0.833,1.0
$Default PBanks: ( "Piranha" )
$Subsystem: turret19,0.833,1.0
$Default PBanks: ( "Piranha" )
$Subsystem: turret20,0.833,1.0
$Default PBanks: ( "Piranha" )
$Subsystem: turret21,0.833,1.0
$Default PBanks: ( "Piranha" )

$Subsystem: turret22,1.875, 3.0
$Default PBanks: ( "Terran Huge Turret" )
$Turret Reset Delay: 1000
$Flags: ( "reset when idle" )
$animation: triggered
$type: initial
+relative_angle: 70, 0, 0

$Subsystem: turret23,1.875, 3.0
$Default PBanks: ( "Terran Huge Turret" )
$Turret Reset Delay: 1000
$Flags: ( "reset when idle" )
$animation: triggered
$type: initial
+relative_angle: 70, 0, 0

$Subsystem: turret24,1.875, 3.0
$Default PBanks: ( "Terran Huge Turret" )
$Turret Reset Delay: 1000
$Flags: ( "reset when idle" )
$animation: triggered
$type: initial
+relative_angle: 70, 0, 0

$Subsystem: fighterbay, 5,0.0
$Subsystem: radar, 5,0.0
$Subsystem: sensors, 5,0.0
$Subsystem: navigation, 5,0.0
$Subsystem: communications, 5,0.0
$Subsystem: weapons, 5,0.0
$Subsystem: engine1, 5,0.0
$Subsystem: engine2, 5,0.0
$Subsystem: engine3, 5,0.0
$Subsystem: engine4, 5,0.0
$Subsystem: engine5, 5,0.0
$Subsystem: engine6, 5,0.0
#End

Code: [Select]
-- config stuff start
-- turret group, UI display, R, G, B, Brace padding

turretInit("pd", "Point Defense Turrets: ", 61, 93, 255, 8)
turretInit("flak", "Flak Turrets: ", 61, 93, 255, 8)
turretInit("md", "mass drivers: ", 255, 93, 48, 11)
turretInit("gauss", "gauss cannons: ", 255, 187, 53, 14)
turretInit("torpedo", "apocalypse torpedoes: ", 255, 255, 53, 17)
turretInit("missile", "Missile Launchers: ", 255, 255, 53, 17)
turretInit("gattler", "gattler: ", 255, 187, 53, 14)
turretInit("rapier", "rapier: ", 255, 187, 53, 14)
turretInit("beams", "Beam Cannons: ", 255, 187, 53, 14)
turretInit("lasers", "Lasers: ", 255, 187, 53, 14)
turretInit("aaaf", "Anti-Fighter Beams: ", 255, 187, 53, 14)

end

function defineWeapons()
csc.weapondef = {}

--weaponClassName -> turret group

weaponInit("Point Defense Turret", "pd")
weaponInit("Standard Flak", "flak")
weaponInit("Heavy Flak", "flak")
weaponInit("PD Turret#Player", "pd")
weaponInit("Burst Flak", "flak")
weaponInit("Mass Driver", "md")
weaponInit("Gauss Cannon", "gauss")
weaponInit("Apocalypse", "torpedo")
weaponInit("Warhammer", "missile")
weaponInit("Gattler", "gattler")
weaponInit("Rapier", "rapier")
weaponInit("TerSlash", "beams")
weaponInit("AAAf", "aaaf")
weaponInit("Piranha", "missile")
weaponInit("Terran Huge Turret", "lasers")

end

function defineShips()
csc.shipdef = {}

local
--Karuna
--Entry number - don't forget to change while copypasting this one
i = 1
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "UEFg Karuna#Player"
--turrets showing target braces
csc.shipdef[i].turretTargets={"pd", "flak", "md", "gauss", "torpedo"}
--turrets aviable in UI
csc.shipdef[i].turretControl={"md", "gauss", "torpedo"}
--turrets to calculate target range
csc.shipdef[i].turretRange={"turret01", "turret02", "turret03", "turret04"}
-- possible turret weapon groups:
-- {"pd", "flak", "md", "gauss", "torpedo", "gattler", "missile"}

--Custos
i = 2
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "UEC Custos#Player"
csc.shipdef[i].turretTargets={"pd", "missile"}
csc.shipdef[i].turretControl={"pd", "missile"}
csc.shipdef[i].turretRange={}


--Arpyia
--Entry number - don't forget to change while copypasting this one
i = 3
csc.shipdef[i] = {}
csc.shipdef[i].shipClassName = "GTVFg Arpyia#Player"
--turrets showing target braces
csc.shipdef[i].turretTargets={"beams", "flak", "lasers", "aaaf", "missile"}
--turrets aviable in UI
csc.shipdef[i].turretControl={"beams", "flak", "lasers", "aaaf", "missile"}
--turrets to calculate target range
csc.shipdef[i].turretRange={"turret01", "turret02", "turret03", "turret04", "turret05", "turret06", "turret07", "turret08", "turret09", "turret10", "turret11", "turret12", "turret13", "turret14", "turret15", "turret16", "turret17", "turret18", "turret19", "turret20", "turret21", "turret22", "turret23", "turret24"}
-- possible turret weapon groups:
-- {"beams", "flak", "lasers", "aaaf", "missile"}

end
-- config stuff end


So here is what came up:

All my weapons turrets now fire on the specified target (or in automatic on their own), but, they cannot be turned off (with the Off-line state), and continue to fire on target.
I also found out that missiles won't fire, no matter what state, changing state changes the target, but still no missiles are launched.

There are maybe something that I must put up in mission on the ship like turret lock's, or other stuff up in events or anything? (Right now I'm only using the "All beams free on mission start" in mission specs).
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: General Battuta on December 29, 2013, 01:32:48 pm
Diff your script against the capship command script shipped with BP2: Tenebra (used in bp2-20 'One Future'). I know that script successfully handles missiles, at least.
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: procdrone on December 29, 2013, 02:07:16 pm
Truly, that missiles are least of my worries, I need the turrets to respond on off-line status, I will check out that script you told, however... maybe with missiles the turret's will work too as they should, who knows?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: procdrone on December 29, 2013, 02:17:53 pm
After looking into the original CSC script that goes like this

Code: [Select]
;The CSC script. Messy and unreadable, but functional enough to allow effective control over capital ship turrets.

#Conditional Hooks

$Application: FS2_Open

$On Key Pressed: [[csc_KeyPressed.lua]]
$On Key Released: [[csc_KeyReleased.lua]]

$On Game Init:
[
ui_keyToggleFunctions = {}
InputStates = {}

ui_keyToggleFunctions["Up Arrow"]    = function(val) InputStates.up    = val end
ui_keyToggleFunctions["Down Arrow"]  = function(val) InputStates.down  = val end
ui_keyToggleFunctions["Left Arrow"]  = function(val) InputStates.left  = val end
ui_keyToggleFunctions["Right Arrow"] = function(val) InputStates.right = val end
ui_keyToggleFunctions["0"] = function(val) InputStates.zero = val end

function getTargetName(target)
local targetname
if target then
local targetship = mn.getObjectFromSignature(target:getSignature())
if targetship:isValid() then
if targetship:getBreedName() == "Ship" then
targetname = targetship.Name
end
else
targetname = "None"
end
else
targetname = "None"
end
return targetname
end

function getTargetClass(target)
local targetname
if target then
local targetship = mn.getObjectFromSignature(target:getSignature())
if targetship:isValid() then
if targetship:getBreedName() == "Ship" then
targetname = targetship.Class.Type.Name
end
else
targetname = "None"
end
else
targetname = "None"
end
return targetname
end

function drawTurretUIKaruna()
--Mass drivers
if csc.acnum == 1 then
gr.setColor(255, 255, 255)
else
gr.setColor(255, 93, 48)
end
gr.drawString("Mass drivers: " .. csc.mdmode[csc.mdstatus], 5, gr.getScreenHeight() * 0.6)
gr.setColor(255, 93, 48)
for i = 1, #csc.mdguns, 1 do
local targetname = getTargetName(csc.mdguns[i].Target)
if not targetname then targetname = "None" end
gr.drawString("  " .. csc.mdguns[i].Name .. ": " .. targetname)
end

--Gauss cannons
if csc.acnum == 2 then
gr.setColor(255, 255, 255)
else
gr.setColor(255, 187, 53)
end
gr.drawString("Gauss Cannons: " .. csc.railgunmode[csc.rgstatus])
gr.setColor(255, 187, 53)
for i = 1, #csc.railguns, 1 do
local targetname = getTargetName(csc.railguns[i].Target)
if not targetname then targetname = "None" end
gr.drawString("  " .. csc.railguns[i].Name .. ": " .. targetname)
end

--Apocalypse
if csc.acnum == 3 then
gr.setColor(255, 255, 255)
else
gr.setColor(255, 255, 53)
end
gr.drawString("Apocalypse Torpedoes: " .. csc.apocalypsemode[csc.apostatus])
gr.setColor(255, 255, 53)
for i = 1, #csc.apocalypse, 1 do
local targetname = getTargetName(csc.apocalypse[i].Target)
if not targetname then targetname = "None" end
gr.drawString("  " .. csc.apocalypse[i].Name .. ": " .. targetname)
end

gr.setColor(255, 255, 255)
local targetname = getTargetName(csc.CurrentTarget)
local classname = getTargetClass(csc.CurrentTarget)
if not classname then classname = "None" end
if not targetname then targetname = "Invalid" end
gr.drawString("Current Target: " .. targetname .. " Class: " .. classname)
end

function fillturretlist(ship)
local turretnum = 1
ba.print("CSC: Entered fillturretlist\n")
csc.turrets = {}
for i = 1, 60, 1 do
if i < 10 then
turretname = "turret0" .. i
else
turretname = "turret" .. i
end

ba.print("CSC: Looking for turret: " .. turretname .. "\n")

if ship[turretname]:isValid() then
csc.turrets[turretnum] = ship[turretname]
ba.print("CSC: Found Turret.\n")
turretnum = turretnum + 1
end
end
end

function groupTurrets()

local pdnum = 1
local flaknum = 1
local railgunnum = 1
local mdnum = 1
local aponum = 1
local gatnum = 1
local rapnum = 1
local misnum = 1

ba.print("CSC: Entered GroupTurrets\n")

for i = 1, #csc.turrets, 1 do
if csc.turrets[i].PrimaryBanks[1].WeaponClass:isValid() or csc.turrets[i].SecondaryBanks[1].WeaponClass:isValid() then
if string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "Point Defense Turret") then
csc.pdTurrets[pdnum] = csc.turrets[i]
ba.print("CSC: Found PD Turret. Turret Number: " .. i .. " pdnum: " .. pdnum .. "\n")
pdnum = pdnum + 1
elseif string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "PD Turret#Player") then
csc.pdTurrets[pdnum] = csc.turrets[i]
ba.print("CSC: Found PD Turret. Turret Number: " .. i .. " pdnum: " .. pdnum .. "\n")
pdnum = pdnum + 1
elseif string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "Burst Flak") then
csc.flakTurrets[flaknum] = csc.turrets[i]
ba.print("CSC: Found Flak Turret. Turret Number: " .. i .. " flaknum: " .. flaknum .. "\n")
flaknum = flaknum + 1
elseif string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "Gauss Cannon") then
csc.railguns[railgunnum] = csc.turrets[i]
ba.print("CSC: Found Gauss Cannon. Turret Number: " .. i .. " railgunnum: " .. railgunnum .. "\n")
railgunnum = railgunnum + 1
elseif string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "Mass Driver") then
csc.mdguns[mdnum] = csc.turrets[i]
ba.print("CSC: Found Mass Driver. Turret Number: " .. i .. " mdnum: " .. mdnum .. "\n")
mdnum = mdnum + 1
elseif string.find(csc.turrets[i].SecondaryBanks[1].WeaponClass.Name, "Apocalypse") then
csc.apocalypse[aponum] = csc.turrets[i]
ba.print("CSC: Found Apocalypse. Turret Number: " .. i .. " aponum: " .. aponum .. "\n")
aponum = aponum + 1
elseif string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "Gattler") then
csc.gattler[gatnum] = csc.turrets[i]
ba.print("CSC: Found Gattler. Turret Number: " .. i .. " gatnum: " .. gatnum .. "\n")
gatnum = gatnum + 1
elseif string.find(csc.turrets[i].PrimaryBanks[1].WeaponClass.Name, "Rapier") then
csc.rapier[rapnum] = csc.turrets[i]
ba.print("CSC: Found Rapier. Turret Number: " .. i .. " rapnum: " .. rapnum .. "\n")
rapnum = rapnum + 1
elseif string.find(csc.turrets[i].SecondaryBanks[1].WeaponClass.Name, "Warhammer") then
csc.missile[misnum] = csc.turrets[i]
ba.print("CSC: Found Missiles. Turret Number: " .. i .. " misnum: " .. misnum .. "\n")
misnum = misnum + 1
end
end
end

csc.initComplete = true
end

function drawTargets(turrets, r, g, b, padding)
gr.setColor(r, g, b)
for i = 1, #turrets, 1 do
target = turrets[i].Target
if target:isValid() then
gr.drawTargetingBrackets(target, true, padding)
end
end
end

function doInput()
MissionTime = mn.getMissionTime()

if OldMissionTime ~= MissionTime and MissionTime ~= 0 then
if InputStates.up and not csc.inputstates.keyup then
csc.acnum = csc.acnum - 1
if csc.ship == "Karuna" then
if csc.acnum == 0 then
csc.acnum = 3
end
elseif csc.ship == "Custos" then
if csc.acnum == 0 then
csc.acnum = 2
end
end
csc.inputstates.keyup = true
elseif not InputStates.up then
csc.inputstates.keyup = false
end

if InputStates.down and not csc.inputstates.keydown then
csc.acnum = csc.acnum + 1
if csc.ship == "Karuna" then
if csc.acnum == 4 then
csc.acnum = 1
end
elseif csc.ship == "Custos" then
if csc.acnum == 3 then
csc.acnum = 1
end
end
csc.inputstates.keydown = true
elseif not InputStates.down then
csc.inputstates.keydown = false
end

if InputStates.left and not csc.inputstates.keyleft then
if csc.ship == "Karuna" then
if csc.acnum == 1 then
csc.mdstatus = csc.mdstatus - 1
if csc.mdstatus == 0 then
csc.mdstatus = 4
end
end
if csc.acnum == 2 then
csc.rgstatus = csc.rgstatus - 1
if csc.rgstatus == 0 then
csc.rgstatus = 4
end
end
if csc.acnum == 3 then
csc.apostatus = csc.apostatus - 1
if csc.apostatus == 0 then
csc.apostatus = 4
end
end
elseif csc.ship == "Custos" then
if csc.acnum == 1 then
csc.pdstatus = csc.pdstatus - 1
if csc.pdstatus == 0 then
csc.pdstatus = 4
end
end
if csc.acnum == 2 then
csc.missilestatus = csc.missilestatus - 1
if csc.missilestatus == 0 then
csc.missilestatus = 4
end
end
end
csc.inputstates.keyleft = true
elseif not InputStates.left then
csc.inputstates.keyleft = false
end

if InputStates.right and not csc.inputstates.keyright then
if csc.ship == "Karuna" then
if csc.acnum == 1 then
csc.mdstatus = csc.mdstatus + 1
if csc.mdstatus == 5 then
csc.mdstatus = 1
end
end
if csc.acnum == 2 then
csc.rgstatus = csc.rgstatus + 1
if csc.rgstatus == 5 then
csc.rgstatus = 1
end
end
if csc.acnum == 3 then
csc.apostatus = csc.apostatus + 1
if csc.apostatus == 5 then
csc.apostatus = 1
end
end
elseif csc.ship == "Custos" then
if csc.acnum == 1 then
csc.pdstatus = csc.pdstatus + 1
if csc.pdstatus == 5 then
csc.pdstatus = 1
end
end
if csc.acnum == 2 then
csc.missilestatus = csc.missilestatus + 1
if csc.missilestatus == 5 then
csc.missilestatus = 1
end
end
end
csc.inputstates.keyright = true
elseif not InputStates.right then
csc.inputstates.keyright = false
end

if InputStates.zero or io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
csc.CurrentTarget = csc.plrship.Target
csc.inputstates.zero = true
elseif not InputStates.zero or not io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
csc.inputstates.zero = false
end
OldMissionTime = MissionTime
end
end

function doTurretModeKaruna()
if csc.mdstatus == 1 then
for i = 1, #csc.mdguns do
csc.mdguns[i]:targetingOverride(false)
end
elseif csc.mdstatus == 2 then
for i = 1, #csc.mdguns do
csc.mdguns[i].Target = csc.plrship.Target
end
elseif csc.mdstatus == 3 then
if csc.CurrentTarget then
if csc.CurrentTarget:isValid() then
for i = 1, #csc.mdguns do
csc.mdguns[i].Target = csc.CurrentTarget
end
end
end
elseif csc.mdstatus == 4 then
for i = 1, #csc.mdguns do
csc.mdguns[i]:targetingOverride(true)
end
end

if csc.rgstatus == 1 then
for i = 1, #csc.railguns do
csc.railguns[i]:targetingOverride(false)
end
elseif csc.status == 2 then
for i = 1, #csc.railguns do
csc.railguns[i].Target = csc.plrship.Target
end
elseif csc.rgstatus == 3 then
if csc.CurrentTarget then
if csc.CurrentTarget:isValid() then
for i = 1, #csc.railguns do
csc.railguns[i].Target = csc.CurrentTarget
end
end
end
elseif csc.rgstatus == 4 then
for i = 1, #csc.railguns do
csc.railguns[i]:targetingOverride(true)
end
end

if csc.apostatus == 1 then
for i = 1, #csc.apocalypse do
csc.apocalypse[i]:targetingOverride(false)
end
elseif csc.apostatus == 2 then
for i = 1, #csc.apocalypse do
csc.apocalypse[i].Target = csc.plrship.Target
end
elseif csc.apostatus == 3 then
if csc.CurrentTarget then
if csc.CurrentTarget:isValid() then
for i = 1, #csc.apocalypse do
csc.apocalypse[i].Target = csc.CurrentTarget
end
end
end
elseif csc.apostatus == 4 then
for i = 1, #csc.apocalypse do
csc.apocalypse[i]:targetingOverride(true)
end
end
end

function drawRangeDisplayKaruna()
csc.range = nil
csc.range = {}
csc.range.Shipname = {}
csc.range.Range = {}
local plrship = hv.Player
if plrship:isValid() then
plrship = mn.getObjectFromSignature(csc.plr:getSignature())
end
local turpos1 = (plrship.Position + plrship["turret01"].Position)
local turpos2 = (plrship.Position + plrship["turret02"].Position)
local turpos3 = (plrship.Position + plrship["turret03"].Position)
local turpos4 = (plrship.Position + plrship["turret04"].Position)
items = 1
for i = 1, #mn.Ships do
local tempship = mn.Ships[i]
local class = getTargetClass(tempship)
if class ~= "Fighter" and class ~= "Bomber" then
if tempship ~= csc.plrship then
local temp = tempship.Position
local temprange1 = math.sqrt( (temp[1] - turpos1[1])^2 + (temp[2] - turpos1[2])^2 + (temp[3] - turpos1[3])^2 )
local temprange2 = math.sqrt( (temp[1] - turpos2[1])^2 + (temp[2] - turpos2[2])^2 + (temp[3] - turpos2[3])^2 )
local temprange3 = math.sqrt( (temp[1] - turpos3[1])^2 + (temp[2] - turpos3[2])^2 + (temp[3] - turpos3[3])^2 )
local temprange4 = math.sqrt( (temp[1] - turpos4[1])^2 + (temp[2] - turpos4[2])^2 + (temp[3] - turpos4[3])^2 )
csc.range.Shipname[items] = tempship.Name
csc.range.Range[items] = math.floor( (temprange1 + temprange2 + temprange3 + temprange4) / 4 )
items = items + 1
end
end
end
gr.setColor(255,255,255)
gr.drawString("Range:", gr.getScreenWidth() * 0.17, gr.getScreenHeight() * 0.78)
for i = 1, #csc.range.Shipname do
if csc.range.Range[i] < 1000 then
local c = math.floor((csc.range.Range[i] / 4)) + 5
gr.setColor(255, c, c)
gr.drawString("  " .. csc.range.Shipname[i] .. ": " .. csc.range.Range[i])
gr.setColor(255, 255, 255)
else
gr.drawString("  " .. csc.range.Shipname[i] .. ": " .. csc.range.Range[i])
end
end
end

function drawRangeDisplayCustos()
end

function drawTurretUICustos()
--Rapier
if csc.acnum == 1 then
gr.setColor(255, 255, 255)
else
gr.setColor(61, 93, 255)
end
gr.drawString("Point Defense turrets: " .. csc.pdmode[csc.pdstatus], 5, gr.getScreenHeight() * 0.6)
gr.setColor(61, 93, 255)
for i = 1, #csc.pdTurrets, 1 do
local targetname = getTargetName(csc.pdTurrets[i].Target)
if not targetname then targetname = "None" end
gr.drawString("  PD Turret: " .. targetname)
end

--Missiles
if csc.acnum == 2 then
gr.setColor(255, 255, 255)
else
gr.setColor(255, 255, 53)
end
gr.drawString("Missile Launchers: " .. csc.missilemode[csc.missilestatus])
gr.setColor(255, 255, 53)
for i = 1, #csc.missile, 1 do
local targetname = getTargetName(csc.missile[i].Target)
if not targetname then targetname = "None" end
gr.drawString("  " .. csc.missile[i].Name .. ": " .. targetname)
end

gr.setColor(255, 255, 255)
local targetname = getTargetName(csc.CurrentTarget)
local classname = getTargetClass(csc.CurrentTarget)
if not classname then classname = "None" end
if not targetname then targetname = "Invalid" end
gr.drawString("Current Target: " .. targetname .. " Class: " .. classname)
end

function doTurretModeCustos()
if csc.pdstatus == 1 then
for i = 1, #csc.pdTurrets do
csc.pdTurrets[i]:targetingOverride(false)
end
elseif csc.pdstatus == 2 then
for i = 1, #csc.pdTurrets do
csc.pdTurrets[i].Target = csc.plrship.Target
end
elseif csc.pdstatus == 3 then
if csc.CurrentTarget then
if csc.CurrentTarget:isValid() then
for i = 1, #csc.pdTurrets do
csc.pdTurrets[i].Target = csc.CurrentTarget
end
end
end
elseif csc.pdstatus == 4 then
for i = 1, #csc.pdTurrets do
csc.pdTurrets[i]:targetingOverride(true)
end
end

if csc.missilestatus == 1 then
for i = 1, #csc.missile do
csc.missile[i]:targetingOverride(false)
end
elseif csc.missilestatus == 2 then
for i = 1, #csc.missile do
csc.missile[i].Target = csc.plrship.Target
end
elseif csc.missilestatus == 3 then
if csc.CurrentTarget then
if csc.CurrentTarget:isValid() then
for i = 1, #csc.missile do
csc.missile[i].Target = csc.CurrentTarget
end
end
end
elseif csc.missilestatus == 4 then
for i = 1, #csc.missile do
csc.missile[i]:targetingOverride(true)
end
end
end

function cscInit()
csc = {}
if not csc.initComplete then
if not csc.plrship then
csc.plr = hv.Player
if csc.plr:isValid() then
csc.plrship = mn.getObjectFromSignature(csc.plr:getSignature())
end

if csc.plrship:getBreedName() == "Ship" then
if csc.plrship.Class.Name ~= "UEFg Karuna#Player" and csc.plrship.Class.Name ~= "UEC Custos-X" then
csc.disable = true
end
if csc.plrship.Class.Name == "UEFg Karuna#Player" then
csc.ship = "Karuna"
elseif csc.plrship.Class.Name == "UEC Custos-X" then
csc.ship = "Custos"
end
else
csc.disable = true
end

if not csc.disable then
if not csc.turrets then
csc.pdTurrets = {}
csc.pdmode = {"Automatic", "Track", "Lock", "Offline"}
csc.pdstatus = 1

csc.flakTurrets = {}

csc.railguns = {}
csc.railgunmode = {"Automatic", "Track", "Lock", "Offline"}
csc.rgstatus = 1

csc.mdguns = {}
csc.mdmode = {"Automatic", "Track", "Lock", "Offline"}
csc.mdstatus = 1

csc.apocalypse = {}
csc.apocalypsemode = {"Automatic", "Track", "Lock", "Offline"}
csc.apostatus = 1

csc.gattler = {}
csc.gattlermode = {"Automatic", "Track", "Lock", "Offline"}
csc.gattlerstatus = 1

csc.missile = {}
csc.missilemode = {"Automatic", "Track", "Lock", "Offline"}
csc.missilestatus = 1

csc.active = {"*", " ", " "}
csc.acnum = 1
csc.inputstates = {}

inputlocked = false

fillturretlist(csc.plrship)
groupTurrets()
ShieldmanOverride = true
BettyOverride = true
OldMissionTime = cscMissionTime
end
end
end
end
end
]

$State: GS_STATE_GAME_PLAY

$On Frame:
[
cscMissionTime = mn.getMissionTime()


if cscOldMissionTime ~= cscMissionTime and cscMissionTime ~= 0 then
if not csc then
cscInit()
end

if csc then
if not csc.disable and csc.initComplete then
doInput()
if csc.ship == "Karuna" then
doTurretModeKaruna()
drawTargets(csc.pdTurrets,   61, 93, 255,  8)
drawTargets(csc.flakTurrets, 61, 93, 255,  8)
drawTargets(csc.mdguns,     255, 93,  48, 11)
drawTargets(csc.railguns,   255, 187, 53, 14)
drawTargets(csc.apocalypse, 255, 255, 53, 17)
elseif csc.ship == "Custos" then
doTurretModeCustos()
drawTargets(csc.pdTurrets,   61, 93, 255,  8)
drawTargets(csc.missile, 255, 255, 53, 17)
end
end
end
cscOldMissionTime = cscMissionTime
end
]

$On HUD Draw:
[
if csc then
if not csc.disable and csc.initComplete then
if csc.ship == "Karuna" then
drawRangeDisplayKaruna()
drawTurretUIKaruna()
elseif csc.ship == "Custos" then
drawRangeDisplayCustos()
drawTurretUICustos()
end
end
end
]

$On State End:
[
csc = nil
ShieldmanOverride = false
BettyOverride = false
]

#End

I find myself pretty unable to edit it for cooperation with beams, or to do anything with it :D
I just hope that Dragon will come up with a solution :/
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: procdrone on December 29, 2013, 03:05:45 pm
I'm sorry for so multiple post on here, but I done some testing with the system, and I observed something.

I've changed the capital ship to something simpler, and I picked a simple Fenris, and coded it into the CSC.

The turret that has it's target never cease to fire, as long as it has it's range and its not destroyed.
On the other hand, if you are able to turn offline before turret get's any target, it won't open fire according to the offline state, and this is correct, but changing the status after the turret has it's target, brings no effect (switching between targets actually works, but shutting down the turrets don't)...
So it comes to the solution, that maybe the offline state is corrupted in the system itself? Can you and your father "Tygrys" look into this matter?
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: General Battuta on December 29, 2013, 06:12:50 pm
Have you tried 'Offline' with the Tenebra version of the script? (My suspicion is that it won't work either, but...)
Title: Re: [ALPHA RELEASE]: Configurable Capship Command
Post by: Dragon on December 29, 2013, 07:22:18 pm
RL keeps us both busy right now, but when we both have time, we'll look into that. It was last tested quite a few FSO versions ago, and only with mods. It worked fine when I last tested it.
That said, I don't know when I will have free time. I'm mostly modding KSP now, haven't actually started up FS for quite some time (though I did some modding/FREDing).