Jump to content

boneAttach gets Invisible on entering another interior/dimension


Zuher Laith

Recommended Posts

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 by Zuher Laith
Link to comment
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
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
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 by Zuher Laith
Link to comment
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

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 by quindo
  • Thanks 1
Link to comment

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...