Jump to content

AttachElements seems to break the position of the component


Recommended Posts

Hello forums!

to the current script: I created a boat (vehicle) and attached a pirateship to it. On the pirateship there are some doors attached.

I'm using following function to interact with the objects:

addEvent("onPlayerInteraction", true)
addEventHandler("onPlayerInteraction", server.root, function()
  local nearest = getNearest(source, "object", 5) -- is working
  if (nearest) then
    outputChatBox("object found", source)
    local id = getElementData(nearest, "action")
    if (id) then
      local action = server.actions[id]
      action(source, nearest)

      outputChatBox("object found with id"..id, source)
      outputChatBox("object found with no id", source)
    outputChatBox("no object found", source)


If the ship is created (and not moved) everything works fine.

As soon as the ship is moved the function outputs "no object found".

Is this a known bug or am I'm missing something?

Link to post


The creation of the elements could be useful for finding a solution

  local ship = createObject(8493, x, y, z)
  server.ships[id].ship = ship


  local doorEntrance = createObject(3093, x, y, z)
  attachElements(doorEntrance, ship, -1.2, -30.3, -9.9, 0, 0, 270)


  local action = #server.actions + 1
  server.actions[action] = enterBoat
  setElementData(doorEntrance, "action", action)
  setElementData(doorEntrance, "parent", id)
function enterBoat(player, element)
  local id = getElementData(element, "parent")
  teleportPlayer(player, true, 3, -4, 1000.6, 90, id) -- simple set position with camera effects


Link to post

I think the door position doesn't follow the ship object. If getNearest() used to find nearest object, maybe try something like this

local attachedTo = getElementAttachedTo(doorObject)
local x, y, z = getElementPosition(doorObject)
if attachedTo then
  x, y, z = getElementPosition(attachedTo)
  -- and do some calculation about the offset position


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...