getNearestPoliceVehicle
Definition
-- @/lua/ge/extensions/gameplay/police.lua:158
local function getNearestPoliceVehicle(targetId, isVisible, isUsable) -- returns the nearest police car from the given vehicle, with a few options
local bestId
local bestDist, bestInterDist = math.huge, math.huge -- best distance, best interactive distance (police driver looking ahead)
for id, veh in pairs(policeVehs) do
if getObjectByID(id):getActive() then
local target = veh.role.validTargets[targetId or 0] -- gets cached data
if target then
if (not vars.useVisibility or not isVisible or target.visible) and (not isUsable or veh.role.state ~= 'disabled') then
if target.dist < bestDist then
bestDist = target.dist
bestInterDist = target.interDist
bestId = id
end
end
end
end
end
return bestId, bestDist, bestInterDist
end
Callers
@/lua/ge/extensions/gameplay/police.lua
local pursuit = veh.pursuit
local bestPoliceId, bestDist, bestInterDist = getNearestPoliceVehicle(id, true, true)
@/lua/ge/extensions/gameplay/traffic/roles/suspect.lua
gameplay_police.setPursuitMode(self.pursuitMode, self.veh.id, policeIds) -- police start chasing the wanted suspect
local bestId = gameplay_police.getNearestPoliceVehicle(self.veh.id, true, true)
self:setTarget(bestId or policeIds[1])