{"slug":"graphics/minimap/radar/radar_configs","category":"graphics","title":"Radar configs","kind":"code","intro":"","body":"--    EXAMPLE OF USING:\n--------------------------------------------------------------------------------------------\n--------------------------------------------------------------------------------------------\n--\n--  INCREASE RADAR MAP BY 10.0\n--  Citizen.InvokeNative(0x9C113883487FD53C, 0xDF5DB58C, 0)\n--\n--  INCREASE RADAR MAP BY [10.0 * modifier 0.8] = 8.0\n--  Citizen.InvokeNative(0x9C113883487FD53C, 0xDF5DB58C, 0x3589012A)\n--\n------------------------------------------------------------------------------------------------------------------\n------------------------------------------------------------------------------------------------------------------\n\n\nlocal radar_configs = {\n\n  `RADAR_CONFIG_CARAVAN`,              -- zoom 7.0, 0xD0F4B483\n  `RADAR_CONFIG_CODE_CONTROL`,         -- zoom 0.0, 0x25B517BF\n  `RADAR_CONFIG_FOOT_FAST_TOWN`,       -- zoom 3.5, 0x874D8F10\n  `RADAR_CONFIG_FOOT_FAST_WILDERNESS`, -- zoom 3.0, 0x14BAAA02\n  `RADAR_CONFIG_FOOT_SLOW_TOWN`,       -- zoom 5.0, 0xF8F7A9AF\n  `RADAR_CONFIG_FOOT_SLOW_WILDERNESS`, -- zoom 5.0, 0xF4BB863C\n  `RADAR_CONFIG_INDOOR`,               -- zoom 10.0, 0xDF5DB58C\n  `RADAR_CONFIG_RIDE_FAST_TOWN`,       -- zoom 3.0, 0x264804B4\n  `RADAR_CONFIG_RIDE_FAST_WILDERNESS`, -- zoom 2.5, 0x8C251CF0\n  `RADAR_CONFIG_RIDE_SLOW_TOWN`,       -- zoom 4.0, 0xEF4631D2\n  `RADAR_CONFIG_RIDE_SLOW_WILDERNESS`, -- zoom 3.0, 0x1B2D4031\n  `RADAR_CONFIG_WANTED`,               -- zoom 1.1, 0x7BFC01D8\n  `RADAR_CONFIG_WANTED_WITNESSED`,     -- zoom 2.2, 0x8997C4AF\n\n}\n\n\nlocal radar_modifiers = {\n\n  `RADAR_MOD_TEST`,                -- zoom 0.01, 0x2BECEB22\n  `RADAR_MOD_CONTROL_XML_CARAVAN`, -- zoom 0.8, 0x3589012A\n\n}\n\n--[[\n--------------------------------------------------------------------------------------------------------------------------------------------\n--                                                                                                                                        --\n--                                                                EXAMPLE USAGE                                                           --\n--                                    This is a pretty faithful recreation of the game's radar behavior                                   --\n--                                                                                                                                        --\n--------------------------------------------------------------------------------------------------------------------------------------------\n]]\n\nlocal EXCLUDED_INTERIORS <const> = {\n  [`agu_fus_cave_int`] = true,\n  [`bea_01_int`] = true,\n  [`elh_seacaves_int`] = true,\n  [`j_16_tunnel_int`] = true,\n  [`l_14_cave_int`] = true,\n  [`m05_bearcave_main`] = true,\n  [`mil_mine_cave_int`] = true,\n  [0x26FB0E67] = true,\n  [0x615D3CCA] = true,\n}\n\nlocal INCLUDED_TOWN_ZONES <const> = {\n  [`aguasdulcesfarm`] = true,\n  [`aguasdulcesruins`] = true,\n  [`aguasdulcesvilla`] = true,\n  [`annesburg`] = true,\n  [`armadillo`] = true,\n  [`beechershope`] = true,\n  [`blackwater`] = true,\n  [`braithwaite`] = true,\n  [`butcher`] = true,\n  [`caliga`] = true,\n  [`cornwall`] = true,\n  [`emerald`] = true,\n  [`lagras`] = true,\n  [`manicato`] = true,\n  [`manzanita`] = true,\n  [`rhodes`] = true,\n  [`siska`] = true,\n  [`stdenis`] = true,\n  [`strawberry`] = true,\n  [`tumbleweed`] = true,\n  [`valentine`] = true,\n  [`vanhorn`] = true,\n  [`wallace`] = true,\n  [`wapiti`] = true,\n}\n\nlocal lastState = nil\n\nlocal function IsIndoors(ped)\n  local interior = GetInteriorFromEntity(ped)\n  if not IsValidInterior(interior) then return false end\n  local _, hash = GetInteriorLocationAndNamehash(interior)\n  if EXCLUDED_INTERIORS[hash] then return false end\n  return true\nend\n\n-- Note: This may be too big in certain cases\n-- Game uses volumes for this, this is a simpler but less accurate approach\nlocal function IsInTown(ped)\n  local pos = GetEntityCoords(ped)\n  local zone = GetMapZoneAtCoords(pos.x, pos.y, pos.z, 1)\n  return INCLUDED_TOWN_ZONES[zone] or false\nend\n\nlocal function IsRiding(ped)\n  return IsPedOnMount(ped) or IsPedInAnyVehicle(ped, false) or IsPedInAnyTrain(ped)\nend\n\nlocal function UpdateSpeedState(speed, riding, current)\n  local margin = (current == nil) and 0.0 or (riding and 2.5 or 1.0)\n  local threshold = riding and 7.0 or 3.0\n\n  if speed < (threshold - margin) then return false end\n  if speed >= (threshold + margin) then return true end\n  return current\nend\n\nlocal function UpdateRadar()\n  local ped = PlayerPedId()\n  local speed = GetEntitySpeed(ped)\n  local riding = IsRiding(ped)\n\n  -- Speed is relative to the current state\n  lastState = UpdateSpeedState(speed, riding, lastState)\n\n  if IsIndoors(ped) then\n    SetRadarConfigType(`RADAR_CONFIG_INDOOR`, 0)\n    return\n  end\n\n  -- Construct the radar config key dynamically\n  local strRide = riding and \"RIDE\" or \"FOOT\"\n  local strSpeed = lastState and \"FAST\" or \"SLOW\"\n  local strLoc = IsInTown(ped) and \"TOWN\" or \"WILDERNESS\"\n  local config = string.format(\"RADAR_CONFIG_%s_%s_%s\", strRide, strSpeed, strLoc)\n\n  SetRadarConfigType(joaat(config), 0)\nend\n\nCreateThread(function()\n  while true do\n    UpdateRadar()\n\n    -- 1000ms feels pretty good, feel free to adjust as needed\n    Wait(1000)\n  end\nend)\n","tables":[],"sourceUrl":"https://github.com/femga/rdr3_discoveries/blob/477aaaccadb7f0c042286611d9939009636cff12/graphics/minimap/radar/radar_configs.lua","rows":[]}