Skip to content
This page was translated from German using AI. If anything is unclear, the German version applies.

For developers: Reading attachments

This page is aimed at server developers. It shows how another script detects whether an entity is an ELS attachment, which vehicle it belongs to and which attachments a vehicle carries. A typical example is a vehicle lift: it should only lift the vehicle; the attachments are attached to it and move along.

State bagEntityMeaning
isElsPlusAttachmentthe attachmenttrue: this entity is an ELS attachment
elsAttachmentsthe carrier vehicleList of attachments, each entry with netId

You find the root vehicle via GetEntityAttachedTo: attachments are attached to the vehicle; with nested attachments you walk up the chain until the entity is no longer an attachment.

-- Is the entity an ELS attachment?
local function isElsAttachment(ent)
return ent ~= 0 and DoesEntityExist(ent) and Entity(ent).state.isElsPlusAttachment == true
end
-- Find the root vehicle (walks up the attachment chain in case an attachment is attached to another attachment)
local function elsRootVehicle(ent)
while isElsAttachment(ent) do
local parent = GetEntityAttachedTo(ent)
if parent == 0 then break end
ent = parent
end
return ent
end
-- All attachments of a vehicle as entities
local function elsAttachmentEntities(vehicle)
local list = {}
for _, a in ipairs(Entity(vehicle).state.elsAttachments or {}) do
if a.netId and NetworkDoesNetworkIdExist(a.netId) then
local e = NetworkGetEntityFromNetworkId(a.netId)
if e ~= 0 then list[#list + 1] = e end
end
end
return list
end
local veh = elsRootVehicle(targetEntity)
if isElsAttachment(targetEntity) then
-- the target was an attachment: lift the vehicle underneath instead
end
-- attachments do not need to be moved individually, they are attached to the vehicle and move along
  • Check DoesEntityExist and NetworkDoesNetworkIdExist: an attachment may only just be spawning or, far away, not be streamed yet.
  • The state bags are meant for reading only. You change, place or delete attachments in the ELS editor, not via state bags.
  • More state bags and exports: Server dev / extending.