Based on Apache Seventh District Vice I tried some to simulate a boarding.
Got it working but not the message that should be generated so I short-cut that with a new Msgbox
Also added the original LuaInit file.
My question is how I can get in the function 'BoardAndCaptureSuspectVessel' a way that is has a xx% change of being a smuggler and switch side and for the most ships are clean and stay on original side?
Code: Select all
function GetFriendlyShipAndSuspectVesselData()
local selectedUnits, result = ScenEdit_SelectedUnits(), nil
if selectedUnits.contacts == nil or selectedUnits.units == nil then
ScenEdit_MsgBox('Select both a suspect vessel to board and a nearby friendly ship to perform this special action.',0)
return nil
elseif #selectedUnits.contacts == 1 and #selectedUnits.units == 1 then
local ship = ScenEdit_GetUnit({guid=selectedUnits.units[1].guid})
local vessel = ScenEdit_GetContact({side='United States',guid=selectedUnits.contacts[1].guid})
local vessel = ScenEdit_GetUnit({guid=vessel.actualunitid})
result = {ship=ship,vessel=vessel}
return result
else
ScenEdit_MsgBox('Too many units are selected.\n\nEnsure you have selected both a suspect vessel to board and a nearby friendly ship to perform this special action',0)
return nil
end
end
function FriendlyShipIsEligibleToBoard()
local selectedUnits, result = GetFriendlyShipAndSuspectVesselData(), false
if selectedUnits.ship.type == 'Ship' then
return true
else
ScenEdit_MsgBox('Unit must be a friendly ship to attempt this special action.',0)
return result
end
end
function FriendlyShipHasSpeedAdvantageOverSuspectVessel()
local selectedUnits = GetFriendlyShipAndSuspectVesselData()
if selectedUnits.ship.speed > selectedUnits.vessel.speed then
return true
else
ScenEdit_MsgBox('Friendly ship must be moving faster than the suspect vessel to board.\n\nIncrease speed or try with a faster ship.',0)
return false
end
end
Code: Select all
function CalculateRangeForFriendlyShipAndSuspectVessel()
local metresPerNMi, feetPerM = 1852, 3.28084
local selectedUnits = GetFriendlyShipAndSuspectVesselData()
local rangeMetres = Round(Tool_Range(selectedUnits.ship.guid, selectedUnits.vessel.guid) * metresPerNMi)
local rangeFeet = Round(rangeMetres * feetPerM)
return {feet=rangeFeet,metres=rangeMetres}
end
function FriendlyShipIsInBoardingRangeOfSuspectVessel()
local range = CalculateRangeForFriendlyShipAndSuspectVessel()
local maxBoardingRange, feetPerM = 610, 3.28084
local maxBoardingRangeFeet = Round(maxBoardingRange * feetPerM)
if range.metres < maxBoardingRange then
return true
else
ScenEdit_MsgBox('Ship must be within '..maxBoardingRange..'m / '..maxBoardingRangeFeet..'ft.\n\nCurrent range is '..range.metres..'m / '..range.feet..'ft.\n\nMove closer to the vessel.',0)
return false
end
end
function BoardAndCaptureSuspectVessel() -- can I make it to have a 10% change to switch side and 90% stay on same (nothing found)
local selectedUnits = GetFriendlyShipAndSuspectVesselData() -- all start at civilain side with x% change of being suspect and switch side?
ScenEdit_SetUnitSide({side=selectedUnits.vessel.side, name=selectedUnits.vessel.name, newside='Boarded'}) -- how to influence in advance which one if not the side, ?name??
ScenEdit_MsgBox('We captured the boarded ship and hand it over ......',0) -- Or pattern of life parameters?
end
function AttemptBoarding()
local selectedUnits = GetFriendlyShipAndSuspectVesselData()
if selectedUnits ~= nil then
if FriendlyShipIsEligibleToBoard() and
FriendlyShipHasSpeedAdvantageOverSuspectVessel() and
FriendlyShipIsInBoardingRangeOfSuspectVessel() then
BoardAndCaptureSuspectVessel()
end
end
end
AttemptBoarding()