Crate
Module: crate.lua
Overview
The Crate module represents a winchable crate object in the game world. It manages the crate’s blip marker on the minimap and handles its winching state.
Inheritance
- Inherits from: none — base/utility module
- Imports: none
Instance pattern
Not the Inheritable/rich-instance pattern, and not a class-factory either — confirmed from source: a plain module-level table, tGuids[uGuid] = tGuids[uGuid] or {}, with no Create/Delete/setmetatable anywhere. Each activated crate gets a small sub-table entry in tGuids, not a full instance object with inherited methods. It tracks:
tGuids[uGuid].Marker: The GUID of the blip marker added to the minimap.tGuids[uGuid].Winched: An event handle for the crate’s winching state.
Functions
OnActivate(uGuid)
Called when the crate instance is spawned/activated. Initializes the crate’s state and sets up an event listener for its hibernation state.
Awake(uGuid)
Handles the crate’s awakening from hibernation. If the crate is not winched, it adds a blip marker to the minimap. If the crate is winched, it removes any existing blip marker.
OnDeactivate(uGuid)
Called when the crate instance is being torn down (despawned/unloaded). Removes any existing blip marker and deletes all associated events.
OnDeath(uGuid)
Called when the underlying object of the crate dies. Deactivates the crate instance by calling OnDeactivate.
Events
- Listens for:
Event.ObjectHibernationto handle the crate’s awakening. - Listens for:
Event.ObjectWinchedto update the blip marker based on the crate’s winching state.
Module constants & tunables
- Blip texture:
sTexture = "pickup_crate_2"(the one module-level constant; swap to re-skin the minimap blip). - Full blip call (in
Awake):Marker.AddBlip(uGuid, "pickup_crate_2", 48, 255, 255, 255, 255, 0.5, 16, 20)— size48, colour255,255,255,255(opaque white RGBA), then0.5, 16, 20(the remainingMarker.AddBlipparams — e.g. scale/range values). See Marker for the full signature.
Notes for modders
- The crate uses a blip marker with texture
"pickup_crate_2"and size48, drawn opaque white. - When the crate is winched (
Object.IsWinched(uGuid)), its blip marker is removed from the minimap; the blip returns when it is un-winched, becauseAwakere-runs on eachEvent.ObjectWinched. OnActivate/Awake/OnDeactivate/OnDeathare engine-invoked — you don’t call them yourself. The only real skin lever here issTexture; everything else is bare bookkeeping.