Disable my third person script when in a vehicle.

So I have a third person script and this is in my gamemode under cl_init.lua
here is my code



if( CLIENT ) then

	function ThirdPersonUmsg( data )
		if( LocalPlayer().ThirdPerson == nil ) then
			LocalPlayer().ThirdPerson = true;
		else
			LocalPlayer().ThirdPerson = !LocalPlayer().ThirdPerson;
		end;	
	end;
	usermessage.Hook( "ThirdPerson", ThirdPersonUmsg );
	
	usermessage.Hook( "ThirdPerson", ThirdPersonUmsg );
	
	function ThirdPerson( ply, pos, ang, fov )
		if( LocalPlayer().ThirdPerson ) then
			local view = {};
			local dist = 75;
			local trace = {};
			
			trace.start = pos;
			trace.endpos = pos - ( ang:Forward() * dist );
			trace.filter = LocalPlayer();
			local trace = util.TraceLine( trace );
			if( trace.HitPos:Distance( pos ) < dist - 10 ) then
				dist = trace.HitPos:Distance( pos ) - 10;
			end;
			view.origin = pos - ( ang:Forward() * dist ) + (ang:Right()*15) + (ang:Up()*5);
			view.angles = ang;
			view.fov = fov;
			return view;
		end;
	end;
	hook.Add( "CalcView", "ThirdPerson", ThirdPerson );
	
	function ThirdPersonSDLP()
		if( LocalPlayer().ThirdPerson ) then
			return true;
		end;
	end;
	hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonSDLP", ThirdPersonSDLP );

else

	function ToggleThirdPerson( ply )
		umsg.Start( "ThirdPerson", ply );
		umsg.End();
	end;
	hook.Add( "ShowHelp", "ToggleThirdPerson", ToggleThirdPerson );	
end;
	
hook.Add("HUDPaint","Crosshair",function()
	if( LocalPlayer().ThirdPerson ) then
	local p = LocalPlayer():GetEyeTrace().HitPos:ToScreen()
	local x,y = p.x, p.y
	 
	--set the drawcolor
	surface.SetDrawColor( 255, 0, 0, 255 )
	
	local gap = 0
	local length = gap + 8
	 
	--draw the crosshair
	surface.DrawLine( x - length, y, x - gap, y )
	surface.DrawLine( x + length, y, x + gap, y )
	surface.DrawLine( x, y - length, x, y - gap )
	surface.DrawLine( x, y + length, x, y + gap )
	end;
end )

local function HideThings( name )
	if( LocalPlayer().ThirdPerson ) then
	if(name == "CHudCrosshair") then
             return false
        end
        -- We don't return anything here otherwise it will overwrite all other 
        -- HUDShouldDraw hooks.
	end
end;
hook.Add( "HUDShouldDraw", "HideThings", HideThings )


So How do I make it toggle off when player enters a vehicle

[editline]7th February 2016[/editline]

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
FIXED THIS PROBLEM BUT NOT THE FIRST ONE
also I have it hooked to ShowHelp which is the bind to F1 and it still binds to F2 can someone help me with that too



	function ToggleThirdPerson( ply )
		umsg.Start( "ThirdPerson", ply );
		umsg.End();
	end;
	hook.Add( "ShowHelp", "ToggleThirdPerson", ToggleThirdPerson );	




if LocalPlayer():GetVehicle() and LocalPlayer():GetVehicle():IsValid() then return end


?

edit:

Oh I guess you said you already solved that. Now the issue is it’s bound to two F keys? Are you sure you don’t still have an old hook? Restart the server.

No I fixed the problem with the f key Ill try what you gave me

[quote=“RealDope, post:2, topic:218982”]



if LocalPlayer():GetVehicle() and LocalPlayer():GetVehicle():IsValid() then return end


Didn’t seem to work unless I placed the code in the wrong spot

Hook http://wiki.garrysmod.com/page/GM/PlayerEnteredVehicle and call ToggleThirdPerson. Then add the check I gave you above to the ToggleThirdPerson function so players can’t put themselves in thirdperson by pressing F1 if they’re in a vehicle. Obviously replace LocalPlayer() with the player object on the server.

GM:PlayerEnteredVehicle( Player ply, Vehicle veh, number role )

“Called when a player enters a vehicle. Note: although this hook is defined in the base gamemode as shared, it doesn’t appear to be called clientside.” < This is a client sided code

Just network it then