here is my edit :
local player = getLocalPlayer ( )
fpsmode = false
addEventHandler ( "onClientCursorMove", getRootElement ( ),
function ( guiy1, guiy1, guix2, guiy2, x2, y2, z2 )
if not isCursorShowing ( ) and not isChatBoxInputActive ( ) and not isMainMenuActive ( ) and fpsmode and isPedInVehicle ( player ) then
local x1, y1, z1 = getPedBonePosition ( player, 6 )
setCameraMatrix ( x1, y1, z1, x2, y2, z2 )
end
end )
function setFPSCamera ( )
local x1, y1, z1 = getPedBonePosition ( player, 6 )
setCameraMatrix ( x1, y1, z1 )
if not getControlState ( "aim_weapon" ) then
setControlState ( "aim_weapon", true )
end
end
bindKey ( "r", "down",
function ( )
fpsmode = not fpsmode
toggle ( )
end )
function toggle ( )
if isPedInVehicle ( player ) and fpsmode then
addEventHandler ( "onClientPreRender", setFPSCamera )
else
setCameraTarget ( player )
removeEventHandler ( "onClientPreRender", setFPSCamera )
end
end
addEventHandler ( "onClientPlayerVehicleEnter", player, toggle )
addEventHandler ( "onClientPlayerVehicleExit", player, toggle )
at line 27 @ addEventHandler