majqq

elementData equivalent?

Recommended Posts

Hey, as title says. Is there any good equivalent to the thing above? I would need to get colshape userdata - colshape attached to vehicle. elementData would be easiest way, but i am not happy to use it. I'm looking for good alternative. I prefer to use tables + manual sync instead.

It's not a problem to get this when player hit colshape, the real problem begins when i need to get this when player is inside of car. This is temporary solution, which imo isn't good.

-- server side example

addCommandHandler("data", function(plr, command)
	local vehicle = getPedOccupiedVehicle(plr)
	if not vehicle then outputChatBox("You need to be in vehicle to get data.", plr) return end
	local parent = getElementAttachedTo(vehicle)
	outputChatBox(tostring(parent), plr)
end)

I was thinking about setElementParent/getElementParent. And i found this topic.

 

Just want to know if this function can do the work.

 

 

Share this post


Link to post
6 hours ago, majqq said:

Hey, as title says. Is there any good equivalent to the thing above? I would need to get colshape userdata - colshape attached to vehicle. elementData would be easiest way, but i am not happy to use it. I'm looking for good alternative. I prefer to use tables + manual sync instead.

It's not a problem to get this when player hit colshape, the real problem begins when i need to get this when player is inside of car. This is temporary solution, which imo isn't good.


-- server side example

addCommandHandler("data", function(plr, command)
	local vehicle = getPedOccupiedVehicle(plr)
	if not vehicle then outputChatBox("You need to be in vehicle to get data.", plr) return end
	local parent = getElementAttachedTo(vehicle)
	outputChatBox(tostring(parent), plr)
end)

I was thinking about setElementParent/getElementParent. And i found this topic.

 

Just want to know if this function can do the work.

 

 

 

Quote

setElementParent/getElementParent

Yes those will work just fine.

 

But keep in mind that other resources might also add other children. So it's better to be a little bit more specific.

local colshapes = getElementChildren ( vehicle, "colshape" ) 
local colshape = colshapes[1]


-- is the colshape not a direct child? Use:

local colshapes = getElementsByType ( "colshape", vehicle ) 
local colshape = colshapes[1]

 

 

  • Like 1

Share this post


Link to post
1 hour ago, IIYAMA said:

 

Yes those will work just fine.

 

But keep in mind that other resources might also add other children. So it's better to be a little bit more specific.


local colshapes = getElementChildren ( vehicle, "colshape" ) 
local colshape = colshapes[1]


-- is the colshape not a direct child? Use:

local colshapes = getElementsByType ( "colshape", vehicle ) 
local colshape = colshapes[1]

 

 

Thank you.

In case i would need to get vehicle which is related with this colshape it should be like this?

local parent = getElementParent(vehicle) -- returns colshape userdata
local child = getElementChild(parent, 0) -- returns vehicle userdata?

 

  • Like 1

Share this post


Link to post
13 minutes ago, majqq said:

Thank you.

In case i would need to get vehicle which is related with this colshape it should be like this?


local parent = getElementParent(vehicle) -- returns colshape userdata
local child = getElementChild(parent, 0) -- returns vehicle userdata?

 

yup!

  • Like 1

Share this post


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.