I’ve been looking for a script or a way to force First Person on players when they are doing a drive-by as the driver but couldn’t find anything.
So I spent the last hour trying different methods and functions and I finally got it to work.
As I believe there is no publicly released script that can achieve this purpose, I wanted to share my code with the community
I also made it so when the player stops doing the drive-by it’ll switch him back to the view cam that he had before.
So, for this to work, put this code on the client side
------------------------------------------------------
--------- Forced First Person On Driveby -----------
------------------------------------------------------
local recentViewMode = 0
local changedViewMode = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local veh = GetVehiclePedIsIn(ped, false)
if GetPedInVehicleSeat(veh, -1) == ped and IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
------------------------------------------------------
--------- Forced First Person On Driveby -----------
------------------------------------------------------
local recentViewMode = 0
local changedViewMode = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local veh = GetVehiclePedIsIn(ped, false)
if GetPedInVehicleSeat(veh, -1) == ped and IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local veh = GetVehiclePedIsIn(ped, false)
if GetPedInVehicleSeat(veh, 0) == ped and IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local veh = GetVehiclePedIsIn(ped, false)
if GetPedInVehicleSeat(veh, 1) == ped and IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local veh = GetVehiclePedIsIn(ped, false)
if GetPedInVehicleSeat(veh, 2) == ped and IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
That’s very bad performance-wise.
All those threads for something that can be easily checked within the initial thread.
If you want to force First Person on anyone doing a drive by ( not only the driver ), you can do this:
------------------------------------------------------
--------- Forced First Person On Driveby -----------
------------------------------------------------------
local recentViewMode = 0
local changedViewMode = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
if IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
------------------------------------------------------
--------- Forced First Person On Driveby -----------
------------------------------------------------------
local recentViewMode = 0
local changedViewMode = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
if IsPedDoingDriveby(ped) then
if GetFollowVehicleCamViewMode() ~= 4 then
recentViewMode = GetFollowVehicleCamViewMode()
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, 4)
changedViewMode = true
end
end
if changedViewMode and not IsPedDoingDriveby(ped) then
local context = GetCamActiveViewModeContext()
SetCamViewModeForContext(context, recentViewMode)
changedViewMode = false
end
end
end
end)
I see that you misunderstood what my code does.
My initial script only works for the driver.
The second code here does it for all the passengers of that vehicle: