Jump to content

Link marker with vehicle


Lloyd Logan

Recommended Posts

Posted

Is there anyway to link a marker with a vehicle?

I mean, if i were to enter a marker, it would tell me 'something' of a certain vehicle?

Example : Player steps into the marker, and gets details of a certain car?

Posted
local markers = { } -- Define a table. 
local vehicle = createVehicle ( ) -- Create a vehicle. 
local marker = createMarker ( ) -- Create a marker. 
  
markers [ marker ] = vehicle -- Add marker to the table with the value of the vehicle element. 
  
addEventHandler ( "onMarkerHit", root, 
    function ( ) 
        local vehicle = markers [ source ] -- Get the vehicle element using the marker as index for the table. 
        if ( vehicle ) then -- If there is a vehicle... 
            -- Do your thing here 
        end 
    end 
) 

Is that what you meant?

Posted

You can also set the marker a parent of the vehicle, or the other way around. This way you can just get the child or parent and have the vehicle.

Posted
Quote

You can also set the marker a parent of the vehicle, or the other way around. This way you can just get the child or parent and have the vehicle.

That's what I was kinda looking for! So if I were to enter a marker, to get the name of a vehicle, would I set the parent vehicle to a marker other vice versa?

Posted
That's what I was kinda looking for! So if I were to enter a marker, to get the name of a vehicle, would I set the parent vehicle to a marker other vice versa?

It's easier to fetch if you set the vehicle the marker's parent. This way you can just call getElementParent -function to get the vehicle, the rest is obvious.

Posted
Solidsnake14 said:
I edited the code to add comments so you may understand it better.

Actually thanks for that! Because of myonlake post I never saw yours! This also helped, thanks!

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