I’m learning lua and I would like to know how to make a persons view 3rd person. I don’t mind if it is locked in place or not but it would be helpful if anyone could tell me how. Also i have a problem when trying to make people change teams when they die i am using an ondeath function with this line of code:
GAMEMODE:PlayerJoinTeam( pl, "TEAM_ZOMBIES" )
but all it does is switch you to connecting/joining team. And my last ? is how do you make it to where when a player chooses a class they can’t change it again.
For thirdperson, this is a really simple way of doing it.
[lua]function GM:CalcView(ply, origin, angles, fov)
if (!ply:Alive()) then
return;
end
local viewdistance = 126;
local vec = ply:GetAimVector();
local org = (vec * -viewdistance);
local tr = util.QuickTrace(origin, org, ply);
org = ((tr.Hit && (tr.HitPos + (vec * 8))) || tr.HitPos);
local view = {};
view.origin = org;
view.angles = angles;
return view;
end[/lua]
Ok i kind of get it but i can’t see the player model any help there?
[lua]function CLASS:ShouldDrawLocalPlayer(ply)
return true;
end[/lua]
That is, if you’re using the class system. I’m sure there are ways to do it otherwise, but I’m not sure I know any.
ok also it seems when i move around a bit the camera is offset to the left or right any way to fix this?
EDIT: Nvm i fixed it thanks so much for the help = )
EDIT:Is there a way for it to be toggled by pressing a key like n or something?
Just set up a variable on the player, and have a function or console command toggle it.
[lua]function CLASS:ShouldDrawLocalPlayer(ply)
return (ply.ThirdPersonB || false);
end
function GM:CalcView(ply, origin, angles, fov)
if (!ply:Alive() || !ply.ThirdPersonB) then
return;
end
local viewdistance = 126;
local vec = ply:GetAimVector();
local org = (vec * -viewdistance);
local tr = util.QuickTrace(origin, org, ply);
org = ((tr.Hit && (tr.HitPos + (vec * 8))) || tr.HitPos);
local view = {};
view.origin = org;
view.angles = angles;
return view;
end
local function ToggleTP(ply, cmd, args)
ply.ThirdPersonB = (!ply.ThirdPersonB || true);
end
concommand.Add(“ToggleTP”, ToggleTP);[/lua]
Something to that effect.
would i put that in cl_init or the class file?