FreeSpace Releases > Scripting Releases

Highlight or hotkey individual turret

(1/11) > >>

General Battuta:
Can we do this? I feel like someone might've written a script and I missed it.

I want players to be able to press F9 and have a particular turret on a Deimos targeted. Ideally I'd like them to be able to press F9 and cycle through four turrets on this Deimos, but all of them would be highlighted with gray brackets.

MatthTheGeek:
This would give a huuuuuuugely useful tool for FREDers. Instead of actually requiring people to go open the pof and look what turret carries what.

Nighteyes:

--- Quote from: General Battuta on September 22, 2012, 02:09:48 pm --- Deimos Basestar

--- End quote ---
needless to say, something like this would be awesome

mjn.mixael:
+1

m!m:
Here's a script for this:

--- Code: (turretHotkey-sct.tbm) ---#Conditional Hooks

$Application: FS2_Open
$On Gameplay Start:
[
turretHotkeys = {}
turretHotkeys.key = "F9"

turretHotkeys.ship = nil
turretHotkeys.subsystemNames = {}
turretHotkeys.lastIndex = 0

function turretHotkeys:keyPressed(key)
    if (key == self.key) then
        if (self.ship ~= nil and self.ship:isValid()) then
            local nextIndex = self.lastIndex + 1

            if (nextIndex > #self.subsystemNames) then
                nextIndex = 1
            end

            local subsys = self.ship[self.subsystemNames[nextIndex]]

            if (subsys:isValid()) then
                hv.Player.Target = self.ship
                hv.Player.TargetSubsystem = subsys
            end

            self.lastIndex = nextIndex
        end
    end
end

function thkKey(key)
    if (type(key) ~= "string") then
        ba.warning("Invalid argument type for thkKey. Need a string, got " .. type(key) .. ".")
        return
    end

    turretHotkeys.key = key
end

function thkShip(name)
    if (name == nil) then
        turretHotkeys.ship = nil
    else
        if (type(name) ~= "string") then
            ba.warning("Invalid argument type for thkShip. Need a string, got " .. type(name) .. ".")
            return
        end

        local ship = mn.Ships[name]

        if (not ship:isValid()) then
            ba.warning("No ship with name \"" .. name .. "\" could be found in the current mission.")
            return
        end

        turretHotkeys.ship = ship
    end
end

function thkAdd(name)
    if (type(name) ~= "string") then
        ba.warning("Invalid argument type for thkAdd. Need a string, got " .. type(name) .. ".")
        return
    end

    if (turretHotkeys.ship == nil or not turretHotkeys.ship:isValid()) then
        ba.warning("Invalid ship in turret hotkey state. You need to specify a ship before adding subsystems")
        return
    end

    if (turretHotkeys.ship[name]:isValid()) then
        table.insert(turretHotkeys.subsystemNames, name)
    end
end

function thkRemove(name)
    if (type(name) ~= "string") then
        ba.warning("Invalid argument type for thkRemove. Need a string, got " .. type(name) .. ".")
        return
    end

    local index = 1
    local done = false

    while (not done) do
        for i = index, #turretHotkeys.subsystemNames do
            if (turretHotkeys.subsystemNames[i] == name) then
                table.remove(turretHotkeys.subsystemNames, i)
                index = i
                break
            end
        end

        done = true
    end
end

function thkClear()
    turretHotkeys.subsystemNames = {}
end
]

$State: GS_STATE_GAME_PLAY
$On Key Pressed:
[
turretHotkeys:keyPressed(hv.Key)
]

#End

--- End code ---

To enable it in a mission execute the script-eval SEXP with the argument thkShip('<name>') and add the desired subsystems with thkAdd('<subsys name>').
You can also remove a subsystem with thkRemove('<name>') when it has been added before. If you want to clear this list then call thkClear() and to completely disable it at some point call thkShip() without any name.
You can also change the key that has to be pressed with thkKey('<key>'), the default key if F9.

Navigation

[0] Message Index

[#] Next page

Go to full version