MrxCopterDrop
Module: mrxcopterdrop.lua
Overview
The MrxCopterDrop module is responsible for managing the delivery of cargo using helicopters. It handles the spawning of both the helicopter and the cargo, deploying the winch to attach the cargo, and ensuring the delivery process completes successfully.
Unlike the catalog-driven MrxSupportDelivery family, this is a standalone, function-call helper: a mission script calls MrxCopterDrop.Create(sFaction, sCargo, nDesX, nDesY, nDesZ, ...) with explicit coordinates and gets back the spawned heli/cargo GUIDs. It runs the same winch-and-drop sequence but has no designator, no cost/recruit gating, and no per-instance object — it borrows only GoHome from MrxSupport.
Inheritance
- Inherits from:
none — base/utility module - Imports:
MrxSupport
Instance pattern
This is a stateless manager/utility module — no OnActivate/Awake/tInstance/setmetatable anywhere in the file. It does carry a handful of module-level globals rather than a per-uGuid table:
nAltitude=25is read insideCreate, as the default height offset passed toPg.FindPointFromCamera(nSpawnDistance, nAltitude, 10)and in thenTargetY < nDesY + nAltitudecomparison, both only when the caller doesn’t supplynTargetXexplicitly.sDeliveryVehicle="UH1 Transport (PMC) (Driver)",sCargoToDeliver="box", anduCargoToDeliver(resolved once at load time viaPg.GetGuidByName(sCargoToDeliver)) are not referenced by any function body in this file —Createtakes its ownsCargo/sFactionarguments instead, so these three look like unused leftover defaults/dead config.Createbuilds a localtCopterDatatable mapping faction codes (AL,CH,GR,OC,PR,VZ,VZH,VZHF,VZF) to helicopter template names, falling back to"Ka29b (Driver)"if the faction isn’t found.
Functions
Create(sFaction, sCargo, nDesX, nDesY, nDesZ, bCareless, nTargetX, nTargetY, nTargetZ)
Spawns a helicopter and cargo for delivery. It checks if the current client is the server, retrieves GUIDs for the cargo and helicopter templates based on the faction, spawns the objects at appropriate positions, and sets up events to handle the winch deployment and cargo attachment.
_DeployWinch(uHeli, uCargo, nDesX, nDesY, nDesZ, bCareless)
Called when the helicopter is awake. It deploys the winch on the helicopter and sets up a timer event to wait for the cargo to become active before proceeding with further delivery steps.
_WaitCallback(uHeli, uCargo, nDesX, nDesY, nDesZ, bCareless)
Called after the cargo becomes active. It aligns the cargo’s yaw with the helicopter’s, attaches the cargo to the winch, and issues Ai.Deliver(driver, nDesX, nDesY, nDesZ, 0.5, bCareless). The drop height is hardcoded to 0.5 here (unlike MrxSupportDelivery, which stores it as self.nCargoDropHeight) — there’s no parameter to change it without editing this line.
DeliveryComplete(uHeli)
Called when the delivery is complete. It detaches the cargo from the winch and calls a function from MrxSupport to return the helicopter home.
Confirmed in source: this function does self = {} with no local keyword, which assigns to the global self rather than creating a function-local table. It then passes that table to MrxSupport.GoHome(self, uHeli). Functionally this still works (an empty table is a valid throwaway first argument for GoHome), but it pollutes the global namespace with a self that any other file’s top-level code could read or clobber — likely a copy-paste artifact from a method body (where self would normally arrive as an implicit parameter) rather than deliberate design.
Events
- Listens for
Event.ObjectHibernationto deploy the winch when the helicopter becomes active. - Listens for
Event.TimerRelativeto wait for the cargo to become active before proceeding with further delivery steps. - Listens for
Event.ObjectWinchedto detach the cargo from the winch after the delivery is complete.
Notes for modders
- Ensure that the server is handling the creation of helicopter and cargo objects to maintain consistency across multiplayer sessions.
- Customize the faction and cargo types by modifying the local
tCopterDatatable insideCreate. The module-levelsDeliveryVehicle/sCargoToDeliver/uCargoToDeliverglobals are dead — not read by any function in this file — so editing them has no effect.nAltitude(25), by contrast, is live: it’s the default vertical offsetCreateuses viaPg.FindPointFromCamerawhen the caller omitsnTargetX, so changing it does change drop-point selection. - Be aware that network synchronization (
Net.IsClient()) may affect the behavior in multiplayer environments —Createreturns immediately with no value on the client. - The
_DeployWinchand_WaitCallbackfunctions are internal helpers and should not be called directly by modders.