Jump to content

[HELP] custom zones and names


22small

Recommended Posts

Hey there,

 

I'm working on displaying custom street names and districts on my speedo, I'm working with nodes. I managed to get the street names to display on the nodes I want it to, now what I'm trying to do is get the district's to do the same. I tried doing the exact same thing as what was done with the street names, though this doesn't seem to work as now both won't appear on the speedometer. What did I do wrong?

 

local names =
{

	
	-- nodes, name and district
	{ { 1703957, 1703958 },  name = "Template Name", district = "District Template" },
}

for k, node in ipairs( names ) do
	for _, route in ipairs( node ) do
		if #route == 1 then
			local value = getNodeByID( vehicleNodes, route[1] )
			if value then
				if not value.streetname then
					value.streetname = node.name
				elseif value.streetname ~= node.name then
					value.streetname = value.streetname .. "/" .. node.name
				if not value.streetzone then
					value.streetzone = node.district
				elseif value.streetzone ~= node.district then
					value.streetzone = value.streetzone .. "/" .. node.district
				end
			end
		else
			for i = 1, #route - 1 do
				local path = calculatePathByNodeIDs( math.abs(route[i]), math.abs(route[i+1]) )
				for key, value in ipairs(path) do
					if value.id == -route[i] or value.id == -route[i+1] then
					
					elseif not value.streetname then
						value.streetname = node.name
					elseif value.streetname ~= node.name then
						value.streetname = value.streetname .. "/" .. node.name

					elseif not value.streetzone then
						value.streetzone = node.district
					elseif value.streetzone ~= node.district then
						value.streetzone = value.streetzone .. "/" .. node.district
						end
					end
				end
			end
		end
	end
end

local cacheX, cacheY, cacheZ = 0, 0, 0

addEventHandler("onClientRender", getRootElement(),
	function()
		local x, y, z = getElementPosition(getLocalPlayer())
		if cacheX ~= x or cacheY ~= y or cacheZ ~= z then
			local node = findNodeClosestToPoint(vehicleNodes, x, y, z)
			setElementData(getLocalPlayer(), "speedo:street", node.streetname)
			setElementData(getLocalPlayer(), "speedo:zone", node.district)
			cacheX = x
			cacheY = y
			cacheZ = z
		end
	end
)

 

 

This is my code that displays streetnames, and should be displaying the district right underneath it.

			-- street names
			local streetname = getElementData(getLocalPlayer(), "speedo:street" )
			if streetname and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetname )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 296, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetname, x, y - 292 )
			end

			-- district names
			local streetzone = getElementData(getLocalPlayer(), "speedo:zone" )
			if streetzone and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetzone )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 76-5, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetzone, x, y - 72-5 )
			end

 

Edited by 22small
Link to comment

Try this

 


 

--	[ Zone ]
local DefZoneToNew = {
    ["YourNewZoneName"] = "OldZoneName",
}


function getPlayerZone(element)
    local x, y, z = getElementPosition(element)
    local location = getZoneName(x, y, z)
    if DefZoneToNew[location] then
        return DefZoneToNew[location]
    else
        return location
    end
end

--	[ City ]
local DefCityToNew = {
    ["YourNewCityName"] = "OldCityName",
}


function getPlayerCity(element)
    local x, y, z = getElementPosition(element)
    local location = getZoneName(x, y, z, true)
    if DefCityToNew[location] then
        return DefCityToNew[location]
    else
        return location
    end
end



addEventHandler("onClientRender", root, function()
    dxDrawText(getPlayerZone(localPlayer).." City: "..getPlayerCity(localPlayer), x,y, 20, 80, 1, "default")
end)

 

Edited by TheMOG
Link to comment
24 minutes ago, TheMOG said:

Try this

 


 


--	[ Zone ]
local DefZoneToNew = {
    ["YourNewZoneName"] = "OldZoneName",
}


function getPlayerZone(element)
    local x, y, z = getElementPosition(element)
    local location = getZoneName(x, y, z)
    if DefZoneToNew[location] then
        return DefZoneToNew[location]
    else
        return location
    end
end

--	[ City ]
local DefCityToNew = {
    ["YourNewCityName"] = "OldCityName",
}


function getPlayerCity(element)
    local x, y, z = getElementPosition(element)
    local location = getZoneName(x, y, z, true)
    if DefCityToNew[location] then
        return DefCityToNew[location]
    else
        return location
    end
end



addEventHandler("onClientRender", root, function()
    dxDrawText(getPlayerZone(localPlayer).." City: "..getPlayerCity(localPlayer), x,y, 20, 80, 1, "default")
end)

 

Thanks for your solution, though it's not what I'm looking for heh. I'm using a custom map, though using vehicle nodes to clarify the street name, but I'm trying to use that same table string to add a custom district to it.

 

Below is the base of what I first had, this just only shows me "Interstate 89" in game above the speedo. I'm trying to get Vice Point to show below the speedo.

local names =
{

	
	-- Node, street, district
	{ { 1703957, 1703958 },  name = "Interstate 89", district = "Vice Point" },
}

for k, node in ipairs( names ) do
	for _, route in ipairs( node ) do
		if #route == 1 then
			local value = getNodeByID( vehicleNodes, route[1] )
			if value then
				if not value.streetname then
					value.streetname = node.name
				elseif value.streetname ~= node.name then
					value.streetname = value.streetname .. "/" .. node.name
				end
			end
		else
			for i = 1, #route - 1 do
				local path = calculatePathByNodeIDs( math.abs(route[i]), math.abs(route[i+1]) )
				for key, value in ipairs(path) do
					if value.id == -route[i] or value.id == -route[i+1] then
					
					elseif not value.streetname then
						value.streetname = node.name
					elseif value.streetname ~= node.name then
						value.streetname = value.streetname .. "/" .. node.name
					end
				end
			end
		end
	end
end

local cacheX, cacheY, cacheZ = 0, 0, 0

addEventHandler("onClientRender", getRootElement(),
	function()
		local x, y, z = getElementPosition(getLocalPlayer())
		if cacheX ~= x or cacheY ~= y or cacheZ ~= z then
			local node = findNodeClosestToPoint(vehicleNodes, x, y, z)
			setElementData(getLocalPlayer(), "speedo:street", node.streetname)
			cacheX = x
			cacheY = y
			cacheZ = z
		end
	end
)

 

 

I copied the code for streetname, and changed it so that it would/should show the district data below the speedo. Though that hasn't worked yet.

			local streetname = getElementData(getLocalPlayer(), "speedo:street" )
			if streetname and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetname )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 296, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetname, x, y - 292 )
			end

			-- district names
			local streetzone = getElementData(getLocalPlayer(), "speedo:zone" )
			if streetzone and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetzone )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 76-5, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetzone, x, y - 72-5 )
			end

 

 

Link to comment
local names =
{

		-- Node, street, district
	{ [1703957, 1703958] ,  name = "Interstate 89", district = "Vice Point" },
}

for k, node in ipairs( names ) do
	for _, route in ipairs( node ) do
		if #route == 1 then
			local value = getNodeByID( vehicleNodes, route[1] )
			if value then
				if not value.streetname then
					value.streetname = node.name
				elseif value.streetname ~= node.name then
					value.streetname = value.streetname .. "/" .. node.name
				end
			end
		else
			for i = 1, #route - 1 do
				local path = calculatePathByNodeIDs( math.abs(route[i]), math.abs(route[i+1]) )
				for key, value in ipairs(path) do
					if value.id == -route[i] or value.id == -route[i+1] then
					
					elseif not value.streetname then
						value.streetname = node.name
					elseif value.streetname ~= node.name then
						value.streetname = value.streetname .. "/" .. node.name
					end
				end
			end
		end
	end
end

local cacheX, cacheY, cacheZ = 0, 0, 0

addEventHandler("onClientRender", getRootElement(),
	function()
		local x, y, z = getElementPosition(getLocalPlayer())
		if cacheX ~= x or cacheY ~= y or cacheZ ~= z then
			local node = findNodeClosestToPoint(vehicleNodes, x, y, z)
			setElementData(getLocalPlayer(), "speedo:street", node.streetname)
			cacheX = x
			cacheY = y
			cacheZ = z
		end
	end
)

			local streetname = getElementData(getLocalPlayer(), "speedo:street" )
			if streetname and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetname )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 296, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetname, x, y - 292 )
			end

			-- district names
			local streetzone = getElementData(getLocalPlayer(), "speedo:zone" )
			if streetzone and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetzone )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 76-5, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetzone, x, y - 72-5 )
			end

 

Link to comment
26 minutes ago, Dimos7 said:

local names =
{

		-- Node, street, district
	{ [1703957, 1703958] ,  name = "Interstate 89", district = "Vice Point" },
}

for k, node in ipairs( names ) do
	for _, route in ipairs( node ) do
		if #route == 1 then
			local value = getNodeByID( vehicleNodes, route[1] )
			if value then
				if not value.streetname then
					value.streetname = node.name
				elseif value.streetname ~= node.name then
					value.streetname = value.streetname .. "/" .. node.name
				end
			end
		else
			for i = 1, #route - 1 do
				local path = calculatePathByNodeIDs( math.abs(route[i]), math.abs(route[i+1]) )
				for key, value in ipairs(path) do
					if value.id == -route[i] or value.id == -route[i+1] then
					
					elseif not value.streetname then
						value.streetname = node.name
					elseif value.streetname ~= node.name then
						value.streetname = value.streetname .. "/" .. node.name
					end
				end
			end
		end
	end
end

local cacheX, cacheY, cacheZ = 0, 0, 0

addEventHandler("onClientRender", getRootElement(),
	function()
		local x, y, z = getElementPosition(getLocalPlayer())
		if cacheX ~= x or cacheY ~= y or cacheZ ~= z then
			local node = findNodeClosestToPoint(vehicleNodes, x, y, z)
			setElementData(getLocalPlayer(), "speedo:street", node.streetname)
			cacheX = x
			cacheY = y
			cacheZ = z
		end
	end
)


			local streetname = getElementData(getLocalPlayer(), "speedo:street" )
			if streetname and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetname )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 296, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetname, x, y - 292 )
			end

			-- district names
			local streetzone = getElementData(getLocalPlayer(), "speedo:zone" )
			if streetzone and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetzone )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 76-5, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetzone, x, y - 72-5 )
			end

 

ERROR: Loading script failed: gps-system\c_streetNames.lua:5 ']' expected near ','
I got this error in debugscript from the edit you made, although there wasn't any change to define the district anywhere else, like I had tried on my first submit so that it would display with the dxDraw

Edited by 22small
Link to comment
20 minutes ago, 22small said:

ERROR: Loading script failed: gps-system\c_streetNames.lua:5 ']' expected near ','
I got this error in debugscript from the edit you made, although there wasn't any change to define the district anywhere else, like I had tried on my first submit so that it would display with the dxDraw

Remove the []  and try

Link to comment
6 hours ago, Dimos7 said:

Remove the []  and try

Doesn't do what I need it to 

I need district = "Vice Point" from that table to show below my speedo, from the code of my very first post. Cuz it's not showing anything with the code that I gave on the first post which is this.

BUT with this code, it stopped showing either, unless I remove everything with value.streetzone, then it will only show "Template Name" above my speedo. Though I need "District Template" to show Below my speedo.

local names =
{

	
	-- nodes, name and district
	{ { 1703957, 1703958 },  name = "Template Name", district = "District Template" },
}

for k, node in ipairs( names ) do
	for _, route in ipairs( node ) do
		if #route == 1 then
			local value = getNodeByID( vehicleNodes, route[1] )
			if value then
				if not value.streetname then
					value.streetname = node.name
				elseif value.streetname ~= node.name then
					value.streetname = value.streetname .. "/" .. node.name
				if not value.streetzone then
					value.streetzone = node.district
				elseif value.streetzone ~= node.district then
					value.streetzone = value.streetzone .. "/" .. node.district
				end
			end
		else
			for i = 1, #route - 1 do
				local path = calculatePathByNodeIDs( math.abs(route[i]), math.abs(route[i+1]) )
				for key, value in ipairs(path) do
					if value.id == -route[i] or value.id == -route[i+1] then
					
					elseif not value.streetname then
						value.streetname = node.name
					elseif value.streetname ~= node.name then
						value.streetname = value.streetname .. "/" .. node.name

					elseif not value.streetzone then
						value.streetzone = node.district
					elseif value.streetzone ~= node.district then
						value.streetzone = value.streetzone .. "/" .. node.district
						end
					end
				end
			end
		end
	end
end

local cacheX, cacheY, cacheZ = 0, 0, 0

addEventHandler("onClientRender", getRootElement(),
	function()
		local x, y, z = getElementPosition(getLocalPlayer())
		if cacheX ~= x or cacheY ~= y or cacheZ ~= z then
			local node = findNodeClosestToPoint(vehicleNodes, x, y, z)
			setElementData(getLocalPlayer(), "speedo:street", node.streetname)
			setElementData(getLocalPlayer(), "speedo:zone", node.district)
			cacheX = x
			cacheY = y
			cacheZ = z
		end
	end
)
			-- street names
			local streetname = getElementData(getLocalPlayer(), "speedo:street" )
			if streetname and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetname )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 296, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetname, x, y - 292 )
			end

			-- district names
			local streetzone = getElementData(getLocalPlayer(), "speedo:zone" )
			if streetzone and getVehicleType(vehicle) ~= "Boat" and getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane" then
				local width = dxGetTextWidth( streetzone )
				local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
				dxDrawRectangle( x - 8, y - 76-5, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
				dxDrawText( streetzone, x, y - 72-5 )
			end

 

Edited by 22small
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...