So currently, i am to edit the heli script and i already have it so it says the road but i also want it to convert GetEntityHeading(vehicle) into Cardinal Direction so i can use it in a Text Component String. so if anyone knows how i would do that please let me know
Hey, by direction do you mean the direction of the car that the heli is looking at?
I’m also guessing you want it in North, East, South and West right?
Yeah, i tried to use one array from a compass hud script but it breaks the heli script function.
Wanna post the code that broke in here a sec?
Heading is in right-handed degrees relative to North.
Adapt this to whatever language you’re using.
cardinalDirections = [“North”, “West”, “South”, “East”]
index = floor(heading / 90)
return cardinalDirections[index]
local directions = { [0] = 'N', [45] = 'NW', [90] = 'W', [135] = 'SW', [180] = 'S', [225] = 'SE', [270] = 'E', [315] = 'NE', [360] = 'N', }
while true do
Citizen.Wait(0)
for k,v in pairs(directions)do
if vehicle ~= nil then
direction = GetEntityHeading(vehicle)
if(math.abs(direction - k) < 22.5)then
direction = v
break;
end
end
end
end
^^^ LUA btw forgot to mention
The direction variable should now be the vehicles direction.
If you only want N, E, S and W just remove the middle ones from the table.
That should work, let me know!
I tried using your snippet but every time i opened up the camera and tried to lock on to the vehicle it crashes the hud. heres some code so if i messed up you can see it.
function RenderVehicleInfo(vehicle)
if DoesEntityExist(vehicle) then
local model = GetEntityModel(vehicle)
local vehname = GetLabelText(GetDisplayNameFromVehicleModel(model))
local licenseplate = GetVehicleNumberPlateText(vehicle)
local direction = GetEntityHeading(vehicle)
local directions = { [0] = 'N', [45] = 'NW', [90] = 'W', [135] = 'SW', [180] = 'S', [225] = 'SE', [270] = 'E', [315] = 'NE', [360] = 'N', }
while true do
Citizen.Wait(0)
for k,v in pairs(directions)do
if vehicle ~= nil then
direction = GetEntityHeading(vehicle)
if(math.abs(direction - k) < 22.5)then
direction = v
break;
end
end
end
end
if speed_measure == "MPH" then
vehspeed = GetEntitySpeed(vehicle)*2.236936
else
vehspeed = GetEntitySpeed(vehicle)*3.6
end
local x,y,z = table.unpack(GetEntityCoords(vehicle, false))
local streetName, crossing = GetStreetNameAtCoord(x, y, z)
streetName = GetStreetNameFromHashKey(streetName)
local location = ""
if crossing ~= 0 then
crossing = GetStreetNameFromHashKey(crossing)
location = direction .. " | " .. streetName .. ", " .. crossing
else
location = direction .. " | " .. streetName
end
SetTextFont(0)
SetTextProportional(1)
if vehicle_display == 0 then
SetTextScale(0.0, 0.49)
elseif vehicle_display == 1 then
SetTextScale(0.0, 0.55)
end
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
if vehicle_display == 0 then
AddTextComponentString("Speed: " .. math.ceil(vehspeed) .. " " .. speed_measure .. "\nModel: " .. vehname .. "\nLocation: " .. location)
elseif vehicle_display == 1 then
AddTextComponentString("Model: " .. vehname .. "\nPlate: " .. licenseplate)
end
DrawText(0.45, 0.9)
end
end
You caught me just as I was leaving for work, I’ll be back in a few hours and check then.
Try deleting the break, any errors?
Here’s a working code. Have just tested it a couple of times on my server. Had the same issue with GameTimeLewis’ code as you, so this should solve it for you, too.
function RenderVehicleInfo(vehicle)
if DoesEntityExist(vehicle) then
local model = GetEntityModel(vehicle)
local vehname = GetLabelText(GetDisplayNameFromVehicleModel(model))
local licenseplate = GetVehicleNumberPlateText(vehicle)-- Location of target vehicle local x,y,z = table.unpack(GetEntityCoords(vehicle, false)) local streetName, crossing = GetStreetNameAtCoord(x, y, z) streetName = GetStreetNameFromHashKey(streetName) local location = "" if crossing ~= 0 then crossing = GetStreetNameFromHashKey(crossing) location = streetName .. ", " .. crossing else location = streetName end -- Heading of target vehicle local directions = { [0] = 'North', [45] = 'North-West', [90] = 'West', [135] = 'South-West', [180] = 'South', [225] = 'South-East', [270] = 'East', [315] = 'North-East', [360] = 'North', } for k,v in pairs(directions)do direction = GetEntityHeading(vehicle, false) if(math.abs(direction - k) < 22.5)then direction = v break; end end if speed_measure == "MPH" then vehspeed = GetEntitySpeed(vehicle)*2.236936 else vehspeed = GetEntitySpeed(vehicle)*3.6 end SetTextFont(0) SetTextProportional(1) if vehicle_display == 0 then SetTextScale(0.0, 0.40) elseif vehicle_display == 1 then SetTextScale(0.0, 0.40) end SetTextColour(255, 255, 255, 255) SetTextDropshadow(0, 0, 0, 0, 255) SetTextEdge(1, 0, 0, 0, 255) SetTextDropShadow() SetTextOutline() SetTextEntry("STRING") if vehicle_display == 0 then AddTextComponentString("Speed: " .. math.ceil(vehspeed) .. " " .. speed_measure .. "\nModel: " .. vehname .. "\nPlate: " .. licenseplate) elseif vehicle_display == 1 then AddTextComponentString("Heading: " .. direction .. "\nLocation: " .. location .. "\nSpeed: " .. math.ceil(vehspeed) .. "\nModel: " .. vehname .. "\nPlate: " .. licenseplate) end DrawText(0.45, 0.8)
end
end
This is the complete function, including the text display. Just substitute it in heli_client.lua (lina 576 onwards for me). If you want to edit what is displayed how, edit the AddTextComponentString lines accordingly. The text size is above that in SetTextScale(0, 0.X). Just edit the X to make it smaller or larger.
Awesome! Thanks for the help and the code.