Jump to content

Is it possible?


mgdmgd

Recommended Posts

On 3/24/2017 at 13:55, NeXuS™ said:

Ohh, just in the air?

For the server side. Later on, you can use the customNames table to set their custom name back after respawn.


customNames = {}

addCommandHandler("customname", function(thePlayer, cmdName, customName)
	local cVeh = getPedOccupiedVehicle(thePlayer)
	setElementData(cVeh, "customName", customName)
	customNames[cVeh] = customName
end)

For the client side.


addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1) then
				local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
				if cX and cY then
					dxDrawText(getElementData(k, "customName"), cX, cY)
				end
			end
		end
	end		
end)

This one should work just fine. Not tested tho. Give me a feedback of it. Still working on the texture one.

It didn't work bro :/

Link to comment

There was an error in the client-side script. An end was missing.

addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1) then
					local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
					if cX and cY then
						dxDrawText(getElementData(k, "customName"), cX, cY)
					end
				end
			end
		end
	end		
end)

 

Link to comment
1 minute ago, NeXuS™ said:

There was an error in the client-side script. An end was missing.


addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1) then
					local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
					if cX and cY then
						dxDrawText(getElementData(k, "customName"), cX, cY)
					end
				end
			end
		end
	end		
end)

 

Hope it works now :D But i was wondering, how can i make the names save even if the cars respawn?

Link to comment

If it is respawned, the element data is still saved. The problem starts if your car got destroyed. You'll have to save the cars in a database, else how do you know which car needs a customname?

Edited by NeXuS™
Link to comment
On 3/29/2017 at 13:17, NeXuS™ said:

Yeah, that's all you'll have to do. If you need further help with that one too, feel free to ask.

Okay so i am facing another problem :( It appears for me but doesn't appear for other players and once i get out of the car it disappears :( can you help me with that?

Link to comment

I think it's because the player's model is blocking the isLineOfSightClear function. Try this one.

addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, localPlayer) then
					local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
					if cX and cY then
						dxDrawText(getElementData(k, "customName"), cX, cY)
					end
				end
			end
		end
	end		
end)

 

Edited by NeXuS™
Link to comment
14 minutes ago, NeXuS™ said:

I think it's because the player's model is blocking the isLineOfSightClear function. Try this one.


addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, localPlayer) then
					local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
					if cX and cY then
						dxDrawText(getElementData(k, "customName"), cX, cY)
					end
				end
			end
		end
	end		
end)

 

The text appears and disappears now but it shows for all but disappears a lot, and can somehow it be at the end of the car? like here

http://prntscr.com/er5xw2

Link to comment

Just calculate the position.
You can attach an element to the car and set it's collision to false, and then create the text on that object. Whatever you want. 

The script itself works totally fine for me wo/ any disappearing. Do you have any errors in debugscript mode?

Link to comment
addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				local ignoredElement = getPedOccupiedVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) or localPlayer
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, ignoredElement) then
					local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
					if cX and cY then
						dxDrawText(getElementData(k, "customName"), cX, cY)
					end
				end
			end
		end
	end		
end)

 

Link to comment
10 minutes ago, NeXuS™ said:

addEventHandler("onClientRender", getRootElement(), function()
	local pX, pY, pZ = getElementPosition(localPlayer)
	for i, k in ipairs(getElementsByType("vehicle")) do
		if getElementData(k, "customName") then
			local cX, cY, cZ = getElementPosition(k)
			if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then
				local ignoredElement = getPedOccupiedVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) or localPlayer
				if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, ignoredElement) then
					local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1)
					if cX and cY then
						dxDrawText(getElementData(k, "customName"), cX, cY)
					end
				end
			end
		end
	end		
end)

 

Thank you!!

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