Zuher Laith Posted November 3, 2017 Author Share Posted November 3, 2017 (edited) 11 minutes ago, quindo said: Looks like it fails to refresh, maybe something wrong with event triggering, can you check what shows in debugscript when you change this yes, this is the result: Quote [23:00:16] INFO: Sanity check: userdata: 00000074 - 0 - 0 - 0 - 1 [23:00:16] INFO: Number of attached objects: 0 this happens when teleporting to another dimension & the element is attached. Edited November 3, 2017 by Zuher Laith Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 Okay, so it detects properly that the dimension changed, but it doesn't treat attached object as this player child object. It should be assigned as child element when you attach it to the bone, pretty weird. Link to comment
Captain Cody Posted November 3, 2017 Share Posted November 3, 2017 function BoneDimensions() local dimension = getElementDimension(localPlayer) local interior = getElementInterior(localPlayer) for i,v in pairs(getAttachedElements(localPlayer)) do setElementDimension(v,dimension) setElementInterior(v,interior) end end setTimer ( BoneDimensions, 1000, 0) -- Client sided. Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 Bone attach doesn't use attachElement, so it wont work, it updates position on every frame Link to comment
Zuher Laith Posted November 3, 2017 Author Share Posted November 3, 2017 45 minutes ago, quindo said: Okay, so it detects properly that the dimension changed, but it doesn't treat attached object as this player child object. It should be assigned as child element when you attach it to the bone, pretty weird. true, but do you have any ideas ? Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 local playerAttachedElements = {} function updatePlayerAttachedElements(lastInt, lastDim, curInt, curDim) local attachedObjects = getElementChildren ( source, "object") if playerAttachedElements[source] then for _,elem in pairs(playerAttachedElements[source]) do setElementDimension( elem, curDim ) setElementInterior( elem, curInt ) end end end addEventHandler( "onPlayerDimIntChange", root, updatePlayerAttachedElements ) function AttachElementToBone(element, player, ...) if isElement(element) and isElement(player) then if not playerAttachedElements[player] then playerAttachedElements[player] = {} end table.insert(playerAttachedElements[player],element) end return exports.bone_attach:attachElementToBone(element, player, ...) end Link to comment
Zuher Laith Posted November 3, 2017 Author Share Posted November 3, 2017 @quindo it worked but not so perfect, on attaching If I was in a dim other than 0 Its invisible, it gets visible when I go to 0, and It works normally If I teleport to another dim . Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 function AttachElementToBone(element, player, ...) local dim = getElementDimension( player ) local int = getElementInterior( player ) setElementDimension( element, dim ) setElementInterior( element, int ) if isElement(element) and isElement(player) then if not playerAttachedElements[player] then playerAttachedElements[player] = {} end table.insert(playerAttachedElements[player],element) end return exports.bone_attach:attachElementToBone(element, player, ...) end Remember that if you want to remove attached object later on, you need to also remove it from playerAttachedElements table for it to work correctly. Link to comment
Zuher Laith Posted November 3, 2017 Author Share Posted November 3, 2017 (edited) 38 minutes ago, quindo said: Remember that if you want to remove attached object later on, you need to also remove it from playerAttachedElements table for it to work correctly. it works so far, but I'm getting one warning on dim change while the element is attached .. it does the job but Its a warning .. function updatePlayerAttachedElements(lastInt, lastDim, curInt, curDim) local attachedObjects = getElementChildren ( source, "object") if playerAttachedElements[source] then for _,elem in pairs(playerAttachedElements[source]) do setElementDimension( elem, curDim ) -- here setElementInterior( elem, curInt ) -- and here end end end addEventHandler( "onPlayerDimIntChange", root, updatePlayerAttachedElements ) ---- Warnings ---- [00:46:41] WARNING: vend\server.lua:56: Bad argument @ 'setElementDimension' [Expected element at argument 1] [00:46:41] WARNING: vend\server.lua:57: Bad argument @ 'setElementInterior'[Expected element at argument 1] Edited November 3, 2017 by Zuher Laith Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 That's what i meant, if you attach element, and later detach it, it will still be in the playerAttachedElements[player] table, you will have to write function that removes it from table when you remove the element. Link to comment
Zuher Laith Posted November 3, 2017 Author Share Posted November 3, 2017 35 minutes ago, quindo said: That's what i meant, if you attach element, and later detach it, it will still be in the playerAttachedElements[player] table, you will have to write function that removes it from table when you remove the element. Can I just use this to remove the table ? table.remove (playerAttachedElements) Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 (edited) Not really, here's completely not optimised way that could work: function RemoveElementFromAttachedTable(element, player) if player then for ind,elem in ipairs(playerAttachedElements[player]) do if elem == element then table.remove(playerAttachedElements[player], ind) return end end else for _,player in pairs(playerAttachedElements) do for ind,elem in ipairs(playerAttachedElements[player]) do if elem == element then table.remove(playerAttachedElements[player], ind) return end end end end end When you're detaching the element, but before destroying the element, call this function. It will be fast if you pass both arguments (element and player), but it will also work if you pass only element, by looking over all players and elements attached to them in the table and deleting it from the first place where it finds that element. I suggest passing both element and player, because it will be much faster. Edited November 3, 2017 by quindo 1 Link to comment
Zuher Laith Posted November 4, 2017 Author Share Posted November 4, 2017 @quindo It works perfectly, Its great ! Although Its long but it does the job better than thisThank you so much for your help ! Link to comment
Captain Cody Posted November 4, 2017 Share Posted November 4, 2017 (edited) Oh sorry forgot I use my own system that attaches the element less delay when in vehicles Edited November 4, 2017 by CodyJ(L) 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