Third Person toggling?

Hey guys, i’m currently trying to make a server with a thirdperson script in it, and I want it to toggle when you say: “thirdpersonview 1/0” in console, but how would I do this? I’m using this code as base:
[lua]function MyCalcView(ply, pos, angles, fov)
local view = {}
view.origin = pos-(angles:Forward()*100)
view.angles = angles
view.fov = fov

return view

end

hook.Add(“CalcView”, “MyCalcView”, MyCalcView)

hook.Add(“ShouldDrawLocalPlayer”, “MyHax ShouldDrawLocalPlayer”, function(ply)
return true
end)
[/lua]

There’s no need to make a code for that… if you type thirdperson in console it’ll put you in thirdperson

I’m doing it for my server and I don’t want to turn sv_cheats 1 on.

Oh… I wasnt aware that thirdperson required cheats… I never used it just knew that there was a command like that… Sorry for me being stupid… Rate me dumb :>

There is a mod for that - Over The Shoulder View, but server must have it and clients of course.

Well, I looked at that, but the code is like, really complicated, i’d rather have something simple


 CreateClientConVar("thirdpersonview",0,false,false) 

Use that to create a ConVar then use this to check if it’s on or off:


    if GetConVarNumber("thirdpersonview") == 1 then

How would I put this together as code? I’m not a good lua’er, never used ConVar

if the convar == 1 then
– execute CalcView hook you made

[lua]function calc()
if GetConVarNumber(“thirdpersonview”) == 1 then
hook.Add(“CalcView”, “MyCalcView”, function(ply, pos, angles, fov)
local view = {}
view.origin = pos-(angles:Forward()*100)
view.angles = angles
view.fov = fov
return view
end)
end[/lua]

[editline]28th October 2010[/editline]

Sorry about terrible tabbing, fucking FP doesn’t allow tab so I have to push space xD

I don’t really understand, is this a code that is actually working?
Or is there something missing, it wont work for me.

[lua]local cvThirdPerson = CreateClientConVar( “thirdpersonview”, 0, true, false )

local view = {}
hook.Add( “CalcView”, “ThirdPersonView”, function( ply, origin, angles, fov )
if not cvThirdPerson:GetBool() then return end

view.origin = pos - (angles:Forward() * 100)
view.angles = angles
view.fov = fov

return view

end )

hook.Add( “ShouldDrawLocalPlayer”, “DrawPlayer”, function()
return cvThirdPerson:GetBool()
end )
[/lua]
Haven’t tested but I didn’t notice any errors.

Hook ‘ThirdPersonView’ Failed: [@autorun hirdperson.lua:9] bad argument #1 to ‘?’ (Vector expected, got nil)

It does let you watch from thirdperson, but it’s very close to the player, and it gives an error. ^

Got it, thank you guys for all your help!

view.fov = fov

Should not return that error at all. (Show us the real code! :L)

change view.origin = pos … to view.origin = origin …

Thank you CapsAdmin. :love: