Maurize Posted March 17, 2018 Share Posted March 17, 2018 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) else outputChatBox("object found with no id", source) end else outputChatBox("no object found", source) end end) 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 comment
Maurize Posted March 17, 2018 Author Share Posted March 17, 2018 Update: 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 end Link to comment
Maurize Posted March 18, 2018 Author Share Posted March 18, 2018 However it seems like that any element which is attached to another will lose it's element data on move. (maybe it's because the "element" data remains at the default location) Link to comment
_DrXenon Posted March 18, 2018 Share Posted March 18, 2018 Hmm that's wierd if it is true. If your problem is only with the lost data.. then just get the data before the attaching and give it back to it after the attaching I guess? Link to comment
idarrr Posted March 18, 2018 Share Posted March 18, 2018 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 end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now