[Help] How to allow player to rotate camera when having BW

Hello. I’m using esx_ambulancejob and everything would be fine if the player could rotate the camera when having BW status or even allow him to close his ESC menu when dead, because now when the player dies when having ESC menu opened, they are basically freezed and they need to leave the server by console.

mhm, When you die then it triggers all of the DisableControls, You need to make a a check that closes the ESC Menu when PedIsDead

Yeah I see that it disable nearly all of DisableControls, but even if I removed the disables that still gives nothing. I think that blocking player controls when player is dead is GTA V mechanic, but I have seen some servers (and even played on one) where you can rotate the camera when having BW. Changing anything about disabling/enabling controls in esx_ambulancejob doesn’t work.

@edit And this doesn’t work:

if IsDead then
      if IsPauseMenuActive() then
        SetPauseMenuActive(false)
      end
end

Hi there. Not sure if people are still having this issue but pretty easy fix was this.

  • Open the esx_ambulancejob client.lua
  • Go all the way down to the botttom of the client.lua

Paste this at the bottom of it:

local cam = nil

local isDead = false

local angleY = 0.0

local angleZ = 0.0

--------------------------------------------------
---------------------- LOOP ----------------------
--------------------------------------------------

Citizen.CreateThread(function()

    while true do

        Citizen.Wait(1)

        

        -- process cam controls if cam exists and player is dead

        if (cam and isDead) then

            ProcessCamControls()

        end

    end

end)

Citizen.CreateThread(function()

    while true do

        Citizen.Wait(500)

        

        if (not isDead and NetworkIsPlayerActive(PlayerId()) and IsPedFatallyInjured(PlayerPedId())) then

            isDead = true

            

            StartDeathCam()

        elseif (isDead and NetworkIsPlayerActive(PlayerId()) and not IsPedFatallyInjured(PlayerPedId())) then

            isDead = false

            

            EndDeathCam()

        end

    end

end)

--------------------------------------------------

------------------- FUNCTIONS --------------------

--------------------------------------------------

-- initialize camera

function StartDeathCam()

    ClearFocus()

    local playerPed = PlayerPedId()

    

    cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", GetEntityCoords(playerPed), 0, 0, 0, GetGameplayCamFov())

    SetCamActive(cam, true)

    RenderScriptCams(true, true, 1000, true, false)

end

-- destroy camera

function EndDeathCam()

    ClearFocus()

    RenderScriptCams(false, false, 0, true, false)

    DestroyCam(cam, false)

    

    cam = nil

end

-- process camera controls

function ProcessCamControls()

    local playerPed = PlayerPedId()

    local playerCoords = GetEntityCoords(playerPed)

    -- disable 1st person as the 1st person camera can cause some glitches

    DisableFirstPersonCamThisFrame()

    

    -- calculate new position

    local newPos = ProcessNewPosition()

    -- focus cam area

    SetFocusArea(newPos.x, newPos.y, newPos.z, 0.0, 0.0, 0.0)

    

    -- set coords of cam

    SetCamCoord(cam, newPos.x, newPos.y, newPos.z)

    

    -- set rotation

    PointCamAtCoord(cam, playerCoords.x, playerCoords.y, playerCoords.z + 0.5)

end

function ProcessNewPosition()

    local mouseX = 0.0

    local mouseY = 0.0

    

    -- keyboard

    if (IsInputDisabled(0)) then

        -- rotation

        mouseX = GetDisabledControlNormal(1, 1) * 8.0

        mouseY = GetDisabledControlNormal(1, 2) * 8.0

        

    -- controller

    else

        -- rotation

        mouseX = GetDisabledControlNormal(1, 1) * 1.5

        mouseY = GetDisabledControlNormal(1, 2) * 1.5

    end

    angleZ = angleZ - mouseX -- around Z axis (left / right)

    angleY = angleY + mouseY -- up / down

    -- limit up / down angle to 90°

    if (angleY > 89.0) then angleY = 89.0 elseif (angleY < -89.0) then angleY = -89.0 end

    

    local pCoords = GetEntityCoords(PlayerPedId())

    

    local behindCam = {

        x = pCoords.x + ((Cos(angleZ) * Cos(angleY)) + (Cos(angleY) * Cos(angleZ))) / 2 * (5.5 + 0.5),

        y = pCoords.y + ((Sin(angleZ) * Cos(angleY)) + (Cos(angleY) * Sin(angleZ))) / 2 * (5.5 + 0.5),

        z = pCoords.z + ((Sin(angleY))) * (5.5 + 0.5)

    }

    local rayHandle = StartShapeTestRay(pCoords.x, pCoords.y, pCoords.z + 0.5, behindCam.x, behindCam.y, behindCam.z, -1, PlayerPedId(), 0)

    local a, hitBool, hitCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle)

    

    local maxRadius = 5.5

    if (hitBool and Vdist(pCoords.x, pCoords.y, pCoords.z + 0.5, hitCoords) < 5.5 + 0.5) then

        maxRadius = Vdist(pCoords.x, pCoords.y, pCoords.z + 0.5, hitCoords)

    end

    

    local offset = {

        x = ((Cos(angleZ) * Cos(angleY)) + (Cos(angleY) * Cos(angleZ))) / 2 * maxRadius,

        y = ((Sin(angleZ) * Cos(angleY)) + (Cos(angleY) * Sin(angleZ))) / 2 * maxRadius,

        z = ((Sin(angleY))) * maxRadius

    }

    

    local pos = {

        x = pCoords.x + offset.x,

        y = pCoords.y + offset.y,

        z = pCoords.z + offset.z

    }

        

    -- Debug x,y,z axis

    --DrawMarker(1, pCoords.x, pCoords.y, pCoords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.03, 0.03, 5.0, 0, 0, 255, 255, false, false, 2, false, 0, false)

    --DrawMarker(1, pCoords.x, pCoords.y, pCoords.z, 0.0, 0.0, 0.0, 0.0, 90.0, 0.0, 0.03, 0.03, 5.0, 255, 0, 0, 255, false, false, 2, false, 0, false)

    --DrawMarker(1, pCoords.x, pCoords.y, pCoords.z, 0.0, 0.0, 0.0, -90.0, 0.0, 0.0, 0.03, 0.03, 5.0, 0, 255, 0, 255, false, false, 2, false, 0, false)

    

    return pos

end

Boom, restart the resource, kill a player to test, and they should have no issue with turning their camera! :slight_smile: if you want, you can find all the values of 5.5 (there should 5 of these values. This is how close the camera will be to the player :slight_smile:

Good luck and this should work 100% without a doubt :slight_smile: