Replying to this one. As HighHowdy put in a pretty much functioning loop there is no need to look into my resource. The code he mentioned is exactly what you need.
As for specifying different areas, what you are asking is all configuration, which means the following:
Specify the config you want to be different inside the table with the locations. It could look like the example below.
local areas = {
{x = 111.1, y = 222.2, z = 333.3, markertype = 36, vred = 255, vgreen = 0, vblue = 0, text = "Press ~INPUT_CONTEXT~ for vehicles", flag = "vehicles"},
{x = 444.4, y = 555.5, z = 666.6, markertype = 37, vred = 0, vgreen = 255, vblue = 0, text = "Press ~INPUT_CONTEXT~ for bikes", flag = "bikes"},
}
Notice ~INPUT_CONTEXT~
instead of E
as this will show the selected key instead of a hardcoded button. It’s really helpful if you changed your control scheme.
Now you create the thread as is and access the different information just as you would the coordinates:
for k, v in pairs(areas) do
local dist = GetDistanceBetweenCoords(pos, v.x, v.y, v.z, true)
if dist < 30.0 then
sleep = 0
DrawMarker(v.markertype, v.x, v.y, v.z, [direction, rotation and scale values, try to experiment here; you can save these in the config as well], v.vred, v.vgreen, v.vblue, ...)
if dist < 1.0 then
BeginTextCommandDisplayHelp("STRING") -- this displays a helpwindow in the top left corner
AddTextComponentString(v.text)
EndTextCommandDisplayHelp(0,0,0, 500)
if IsControlJustPressed(0, 38) then
TriggerEvent('OpenGarage', v.flag)
end
end
end
end
One info for the last line (TriggerEvent...
): if you want to open a different garage depending on where you are, use a flag to influence the behavior or use different events that trigger depending on the flag.
So that event OpenGarage
could look like this:
AddEventHandler('OpenGarage', function(flag)
if flag == 'vehicles' then
-- do something here
elseif flag == 'bikes' then
-- do something else here
elseif flag == 'whatever' then
end
end)