Jump to content

Vehicle name in gridlist column in marker


Matevsz

Recommended Posts

How to do that when you drive a car in the marker appeared in the name of the car gridlist column?

InfoCar = createMarker(-2052.3999023438, 170.5, 27.799999237061, "cylinder", 4, 255, 0, 0, 0)

carsPanel = guiCreateWindow(10, (screenH - 372) / 2, 836, 372, "Car", false)
gridList = guiCreateGridList(10, 29, 669, 287, false, carsPanel)
column1 = guiGridListAddColumn(gridList, "Model", 0.3)
row = guiGridListAddRow(gridList)
nameCar = guiGridListSetItemText(gridList, 0, 1, "-", false, false)

 

Link to comment

You can use onClientMarkerHit to detect that.

-- Get the screen size (width and height)
screenW, screenH = guiGetScreenSize( )
InfoCar = createMarker(-2052.3999023438, 170.5, 27.799999237061, "cylinder", 4, 255, 0, 0, 0)

-- This is triggered when the InfoCar marker is hit
addEventHandler( 'onClientMarkerHit', InfoCar,
	function( hitPlayer, matchingDimension )
		-- If it was hit in the wrong dimension, or panel is already open, or the hitPlayer is not the localPlayer, we stop here
		if ( not matchingDimension ) or ( isElement( carsPanel ) ) or ( hitPlayer ~= localPlayer ) then
			return
		end

		carsPanel = guiCreateWindow(10, (screenH - 372) / 2, 836, 372, "Car", false)
		gridList = guiCreateGridList(10, 29, 669, 287, false, carsPanel)
		column1 = guiGridListAddColumn(gridList, "Model", 0.3)

		-- Create a new row into the grid list
		row = guiGridListAddRow(gridList)

		-- Get the current vehicle
		local vehicle = getPedOccupiedVehicle( localPlayer )

		-- Get the name of the vehicle, and use "-" by default
		local vehicleName = vehicle and getVehicleName( vehicle ) or "-"

		-- Set the text for the created row
		guiGridListSetItemText(gridList, row, 1, vehicleName, false, false)
	end
)

-- This is triggered when the InfoCar marker is left
addEventHandler( 'onClientMarkerLeave', InfoCar,
	function( leftPlayer, matchingDimension )
		-- If the leftPlayer matches our localPlayer, and dimension matches, and we have a panel open, we destroy the panel
		if ( leftPlayer == localPlayer ) and ( matchingDimension ) and ( isElement( carsPanel ) ) then
			destroyElement( carsPanel )
		end
	end
)

Tested and works fine.

Edited by myonlake
  • Like 1
Link to comment
1 hour ago, myonlake said:

You can use onClientMarkerHit to detect that.


-- Get the screen size (width and height)
screenW, screenH = guiGetScreenSize( )
InfoCar = createMarker(-2052.3999023438, 170.5, 27.799999237061, "cylinder", 4, 255, 0, 0, 0)

-- This is triggered when the InfoCar marker is hit
addEventHandler( 'onClientMarkerHit', InfoCar,
	function( hitPlayer, matchingDimension )
		-- If it was hit in the wrong dimension, or panel is already open, or the hitPlayer is not the localPlayer, we stop here
		if ( not matchingDimension ) or ( isElement( carsPanel ) ) or ( hitPlayer ~= localPlayer ) then
			return
		end

		carsPanel = guiCreateWindow(10, (screenH - 372) / 2, 836, 372, "Car", false)
		gridList = guiCreateGridList(10, 29, 669, 287, false, carsPanel)
		column1 = guiGridListAddColumn(gridList, "Model", 0.3)

		-- Create a new row into the grid list
		row = guiGridListAddRow(gridList)

		-- Get the current vehicle
		local vehicle = getPedOccupiedVehicle( localPlayer )

		-- Get the name of the vehicle, and use "-" by default
		local vehicleName = vehicle and getVehicleName( vehicle ) or "-"

		-- Set the text for the created row
		guiGridListSetItemText(gridList, row, 1, vehicleName, false, false)
	end
)

-- This is triggered when the InfoCar marker is left
addEventHandler( 'onClientMarkerLeave', InfoCar,
	function( leftPlayer, matchingDimension )
		-- If the leftPlayer matches our localPlayer, and dimension matches, and we have a panel open, we destroy the panel
		if ( leftPlayer == localPlayer ) and ( matchingDimension ) and ( isElement( carsPanel ) ) then
			destroyElement( carsPanel )
		end
	end
)

Tested and works fine.

Player must be in the car? 

nwbtb8.jpg

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