• Toggle between third person with F3?
    6 replies, posted
Heads up: this is my first post so please don't get annoyed if I've put this in the wrong thread. Hey everyone, Alright so I'm having trouble trying to toggle third person with F3, I've already got some code to toggle third person with a console command, but I cannot seem to get it working with the F3 toggling in it. Here's my current code: [CODE] if ( CLIENT ) then local on = true local function toggle() on = !on if on == true then else end end hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonDrawPlayer", function() if on and LocalPlayer():Alive() then return true end end ) hook.Add( "CalcView", "ThirdPersonView", function( ply, pos, angles, fov ) if on and ply:Alive() then local view = {} view.origin = pos - ( angles:Forward() * 70 ) + ( angles:Right() * 20 ) + ( angles:Up() * 5 ) view.angles = ply:EyeAngles() + Angle( 1, 1, 0 ) view.fov = fov return GAMEMODE:CalcView( ply, view.origin, view.angles, view.fov ) end end ) concommand.Add( "thirdperson_toggle", toggle ) end [/CODE] Help is much appreciated :)
For F3 it would be [code] hook.Add("ShowSpare1", "unique name", function(ply) ply:ConCommand("console command here") end) [/code] Some other F keys are: [code] F1 = "ShowHelp" F2 = "ShowTeam" F3 = "ShowSpare1" F4 = "ShowSpare2" [/code]
All alright, thanks for that :)
-snip-
Hmm, it doesn't seem to be working man. Thanks though. Here is what I have now: [CODE] if ( CLIENT ) then local on = false local function toggle() on = !on if on == true then else end end hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonDrawPlayer", function() if on and LocalPlayer():Alive() then return true end end ) hook.Add( "CalcView", "ThirdPersonView", function( ply, pos, angles, fov ) if on and ply:Alive() then local view = {} view.origin = pos - ( angles:Forward() * 70 ) + ( angles:Right() * 20 ) + ( angles:Up() * 5 ) view.angles = ply:EyeAngles() + Angle( 1, 1, 0 ) view.fov = fov return GAMEMODE:CalcView( ply, view.origin, view.angles, view.fov ) end end ) concommand.Add( "thirdperson_toggle", toggle ) hook.Add("ShowSpare1", "ThirdPersonToggle", function( ply ) ply:RunConCommand("thirdperson_toggle") -- A friend of mine told me to use RunConCommand instead of ConCommand since it's client side. end) end [/CODE] Edit: I have tried adding: [CODE] local ply = LocalPlayer() [/CODE] at the top, but that doesn't help with anything :/
The way I did it was using the util.AddNetworkString but I do not think it is the best way. But since you are doing it in one code I guess I would do it this way. Maybe this will work: [CODE] if ( CLIENT ) then local on = false local function toggle() on = !on if on == true then else end end hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonDrawPlayer", function() if on and LocalPlayer():Alive() then return true end end ) hook.Add( "CalcView", "ThirdPersonView", function( ply, pos, angles, fov ) if on and ply:Alive() then local view = {} view.origin = pos - ( angles:Forward() * 70 ) + ( angles:Right() * 20 ) + ( angles:Up() * 5 ) view.angles = ply:EyeAngles() + Angle( 1, 1, 0 ) view.fov = fov return GAMEMODE:CalcView( ply, view.origin, view.angles, view.fov ) end end ) concommand.Add( "thirdperson_toggle", toggle ) hook.Add("ShowSpare1", "ThirdPersonToggle", function( ply ) ply:RunConCommand("thirdperson_toggle") -- A friend of mine told me to use RunConCommand instead of ConCommand since it's client side. end) elseif ( SERVER ) then function GM:ShowSpare1( ply ) toggle() end end [/CODE] If that does not work I would try removing local from the function on line 4.
Nevermind guys, I managed to fix it. For anyone who has the same issue here is the code: [CODE] function GM:ShowSpare1( ply ) ply:ConCommand("thirdperson_toggle") end [/CODE]
Sorry, you need to Log In to post a reply to this thread.