Added a way for the opp radar mode to work, vehicle data now has the 'rayType' variable

This commit is contained in:
Dan
2019-11-10 13:10:23 +00:00
parent bdf204cdbf
commit e38f9f0123

View File

@@ -99,9 +99,10 @@ RADAR.caughtEnt = nil
-- These vectors are used in the custom ray tracing system -- These vectors are used in the custom ray tracing system
RADAR.rayTraces = { RADAR.rayTraces = {
{ startVec = { x = 0.0, y = 5.0 }, endVec = { x = 0.0, y = 150.0 } }, { startVec = { x = 0.0, y = 5.0 }, endVec = { x = 0.0, y = 150.0 }, rayType = "same" },
{ startVec = { x = -5.0, y = 15.0 }, endVec = { x = -5.0, y = 150.0 } }, { startVec = { x = -5.0, y = 15.0 }, endVec = { x = -5.0, y = 150.0 }, rayType = "same" },
{ startVec = { x = 5.0, y = 15.0 }, endVec = { x = 5.0, y = 150.0 } } { startVec = { x = 5.0, y = 15.0 }, endVec = { x = 5.0, y = 150.0 }, rayType = "same" },
{ startVec = { x = -15.0, y = 15.0 }, endVec = { x = -15.0, y = 150.0 }, rayType = "opp" }
} }
-- Each of these are used for sorting the captured vehicle data, depending on what the -- Each of these are used for sorting the captured vehicle data, depending on what the
@@ -176,6 +177,10 @@ function RADAR:ToggleAntenna( ant )
self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit
end end
function RADAR:IsAntennaOn( ant )
return self.vars.antennas[ant].xmit
end
function RADAR:SetAntennaMode( ant, mode ) function RADAR:SetAntennaMode( ant, mode )
if ( type( mode ) == "number" ) then if ( type( mode ) == "number" ) then
if ( mode >= 0 and mode <= 3 ) then if ( mode >= 0 and mode <= 3 ) then
@@ -289,9 +294,10 @@ function RADAR:ResetCapturedVehicles()
self.capturedVehicles = {} self.capturedVehicles = {}
end end
function RADAR:InsertCapturedVehicleData( t ) function RADAR:InsertCapturedVehicleData( t, rt )
if ( type( t ) == "table" and not UTIL:IsTableEmpty( t ) ) then if ( type( t ) == "table" and not UTIL:IsTableEmpty( t ) ) then
for _, v in pairs( t ) do for _, v in pairs( t ) do
v.rayType = rt
table.insert( self.capturedVehicles, v ) table.insert( self.capturedVehicles, v )
end end
end end
@@ -335,6 +341,16 @@ function RADAR:GetFastestFrontAndRear()
return vehs return vehs
end end
function RADAR:GetVehiclesForAntenna()
if ( self:IsAntennaOn( "front" ) or self:IsAntennaOn( "rear" ) ) then
local fastVehs = self:GetFastestFrontAndRear()
for i = 1, -1, -2 do
end
end
end
--[[ --[[
TEST! TEST!
@@ -489,7 +505,7 @@ function RADAR:GetVehsHitByRay( ownVeh, vehs, s, e )
if ( hasData ) then return t end if ( hasData ) then return t end
end end
function RADAR:CreateRayThread( vehs, from, startX, endX, endY ) function RADAR:CreateRayThread( vehs, from, startX, endX, endY, rayType )
Citizen.CreateThread( function() Citizen.CreateThread( function()
local startP = GetOffsetFromEntityInWorldCoords( from, startX, 0.0, 0.0 ) local startP = GetOffsetFromEntityInWorldCoords( from, startX, 0.0, 0.0 )
local endP = GetOffsetFromEntityInWorldCoords( from, endX, endY, 0.0 ) local endP = GetOffsetFromEntityInWorldCoords( from, endX, endY, 0.0 )
@@ -498,13 +514,21 @@ function RADAR:CreateRayThread( vehs, from, startX, endX, endY )
local hitVehs = self:GetVehsHitByRay( from, vehs, startP, endP ) local hitVehs = self:GetVehsHitByRay( from, vehs, startP, endP )
self:InsertCapturedVehicleData( hitVehs ) self:InsertCapturedVehicleData( hitVehs, rayType )
UTIL:DebugPrint( "Ray thread: increasing ray state from " .. tostring( self:GetRayTraceState() ) .. " to " .. tostring( self:GetRayTraceState() + 1 ) ) UTIL:DebugPrint( "Ray thread: increasing ray state from " .. tostring( self:GetRayTraceState() ) .. " to " .. tostring( self:GetRayTraceState() + 1 ) )
self:IncreaseRayTraceState() self:IncreaseRayTraceState()
end ) end )
end end
function RADAR:CreateRayThreads( ownVeh, vehicles )
UTIL:DebugPrint( "Creating ray threads." )
for _, v in pairs( self.rayTraces ) do
self:CreateRayThread( vehicles, ownVeh, v.startVec.x, v.endVec.x, v.endVec.y, v.rayType )
end
end
function RADAR:RunControlManager() function RADAR:RunControlManager()
-- 'Z' key, toggles debug mode -- 'Z' key, toggles debug mode
if ( IsDisabledControlJustPressed( 1, 20 ) ) then if ( IsDisabledControlJustPressed( 1, 20 ) ) then
@@ -541,10 +565,7 @@ function RADAR:Main()
self:ResetCapturedVehicles() self:ResetCapturedVehicles()
self:ResetRayTraceState() self:ResetRayTraceState()
UTIL:DebugPrint( "Creating ray threads." ) self:CreateRayThreads( plyVeh, vehs )
for _, v in pairs( self.rayTraces ) do
self:CreateRayThread( vehs, plyVeh, v.startVec.x, v.endVec.x, v.endVec.y )
end
UTIL:DebugPrint( "Reached end of stage 0." ) UTIL:DebugPrint( "Reached end of stage 0." )
UTIL:DebugPrint( "Stage = " .. tostring( self:GetRadarStage() ) .. "\tTrace state = " .. tostring( self:GetRayTraceState() ) ) UTIL:DebugPrint( "Stage = " .. tostring( self:GetRadarStage() ) .. "\tTrace state = " .. tostring( self:GetRayTraceState() ) )
@@ -563,7 +584,7 @@ function RADAR:Main()
UTIL:DebugPrint( "Printing table for sort mode " .. self:GetSortModeText() ) UTIL:DebugPrint( "Printing table for sort mode " .. self:GetSortModeText() )
for k, v in pairs( caughtVehs ) do for k, v in pairs( caughtVehs ) do
UTIL:DebugPrint( tostring( k ) .. " - " .. tostring( v.veh ) .. " - " .. tostring( v.relPos ) .. " - " .. tostring( v.dist ) .. " - " .. tostring( v.speed ) .. " - " .. tostring( v.size ) ) UTIL:DebugPrint( tostring( k ) .. " - " .. tostring( v.veh ) .. " - " .. tostring( v.relPos ) .. " - " .. tostring( v.dist ) .. " - " .. tostring( v.speed ) .. " - " .. tostring( v.size ) .. " - " .. tostring( v.rayType ) )
end end
self.caughtEnt = caughtVehs[1] self.caughtEnt = caughtVehs[1]
@@ -595,7 +616,7 @@ Citizen.CreateThread( function()
while ( true ) do while ( true ) do
RADAR:Main() RADAR:Main()
Citizen.Wait( 50 ) Citizen.Wait( 100 )
end end
end ) end )