Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Craft Docking Control Script
2017-06-18, 11:44 PM
Post: #1
Craft Docking Control Script
Based on the drone docking script by Albino, with some tinkering I came up with a smooth, clean and fully functional script without the logic traps that could prevent Albino's from working correctly. Perfect for drone and carrier based aircraft and eliminates many of the ACBs that would be needed to provide the same functionality.

Code:
-- Craft docking control script.

-- The purpose of this script is to replace the many ACBs you would otherwise require for your craft to dock with a companion craft under various situations.
-- The script will allow the craft to dock when no enemies are detected, or when ammo, fuel or health are low and only requires a LUA box and 2 ACBs.

-- Setup:
-- Place two ACBs somewhere on the craft you want to dock with a companion craft, and a LUA box with this script.
-- Set one ACB to "Dock With Mothership" and use "set custom controller inputs" to assign the input to the "up" key.
-- Set the other ACB to "Undock From Mothership" and use "set custom controller inputs" to assign the input to the "down" key.
-- NOTE: You may want to set a short delay on the undock ACB to allow time for repairs.
-- Select this craft on one of the docking station on the companion craft.
-- NOTE: Only one docking station retains it's selection when the craft is pulled out of play.

-- Set if the craft will dock when no enemies are detected. (Set to "true" to dock when no enemies are detected otherwise set to "false".)
ReturnWhenIdle = true

-- Set if the craft will dock when ammo is low. (Set to "true" to dock when ammo is low, otherwise set to "false".)
ReturnForAmmo = true
-- Set the decimal fraction at which the craft will dock if ammo reaches or drops below this level. (Set between 0 and 0.9)
AmmoToReturn = .1

-- Set if the craft will dock when fuel is low. (Set to "true" to dock when ammo is low, otherwise set to "false".)
ReturnForFuel = true
-- Set the decimal fraction at which the craft will dock if fuel reaches or drops below this level. (Set between 0 and 0.9)
FuelToReturn = .1

-- Set if the craft will dock when health is low. (Set to "true" to dock when ammo is low, otherwise set to "false".)
ReturnForHealth = true
-- Set the decimal fraction at which the craft will dock if health reaches or drops below this level. (Set between 0 and 0.9)
HealthToReturn = .9

function ShouldDock(I)
  if ReturnWhenIdle and I:GetNumberOfTargets(0) == 0 then
    I:Log('Docking because idle.')
    return true
  elseif ReturnForAmmo and I:GetAmmoFraction() <= AmmoToReturn then
    I:Log('Docking for ammo.')
    return true
  elseif ReturnForFuel == true and I:GetFuelFraction() <= FuelToReturn then
    I:Log('Docking for fuel.')
    return true
  elseif ReturnForHealth and I:GetHealthFraction() <= HealthToReturn then
    I:Log('Docking for repairs.')
    return true
  else
    return false
  end
end

function Update(I)

  if I:GetNumberOfMainframes() > 0 then
    if ShouldDock(I) then
      I:Log('Engage dock.')
      I:RequestComplexControllerStimulus(11)
    else
      I:Log('Release dock.')
      I:RequestComplexControllerStimulus(12)
    end
  end
end
Find all posts by this user
Quote this message in a reply
2017-06-20, 11:17 PM
Post: #2
RE: Craft Docking Control Script
Cool.

Knowledge is knowing a tomato is a fruit wisdom is not putting it in a fruit salad - anonymous

Don't believe everything you think - anounymous
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)