LUA help - CalcView in GM Prophunters

So I made a thread previously asking for help with changing the POV of a prop.
I found another thread from December 2014 that someone else made, and at the end they gave the following code:


function GM:CalcView(ply, pos, angles, fov)
	if self:IsCSpectating() && IsValid(self:GetCSpectatee()) then
		ply = self:GetCSpectatee()
	end
	if ply:IsPlayer() && !ply:Alive() then
		ply = ply:GetRagdollEntity()
	end
	if IsValid(ply) then
		if ply:IsPlayer() && ply:IsDisguised() then
			local maxs = ply:GetNWVector("disguiseMaxs")
			local mins = ply:GetNWVector("disguiseMins")
			local view = {}

			local reach = math.max(135, maxs.z - mins.z)
			local trace = {}
			trace.start = ply:GetPropEyePos()
			trace.endpos = trace.start + angles:Forward() * -(reach + 5)
			local tab = ents.FindByClass("prop_ragdoll")
			table.insert(tab, ply)
			trace.filter = tab

			local tr = util.TraceLine(trace)
			view.origin = trace.start + (trace.endpos - trace.start):GetNormal() * math.Clamp(trace.start:Distance(tr.HitPos) - 5, 0, reach)

			view.angles = angles
			view.fov = fov
			return view
		end
	end
end

The gamemode I’m using is called Prophunters. Does anyone know where I need to put this? I’m tried cl_disguise, sh_disguise, sv_disguise, cl_init and init ( all lua files )

CalcView is a clientside hook so cl_init sounds right to me.

What about cl_disguise aswell? Cause I’m only wanting this to work for players in teh Prop team when they change into a Prop.

[editline]14th April 2016[/editline]

Nope, still doesn’t work… Would I need to add these to the cl_init.lua file in the fretta folder as well?

the gamemode probably already defines this function, so you’ll have to find where it does and disable/replace it.

I’ve looked in every .lua file under prophunters/gamemode/ and none of them have the same function D;

Still not working… This is what the codes look like in the two files:

cl_init.lua


include("shared.lua")
include("cl_fixplayercolor.lua")
include("cl_ragdoll.lua")
include("cl_chattext.lua")
include("cl_rounds.lua")
include("cl_hud.lua")
include("cl_player.lua")
include("cl_scoreboard.lua")
include("cl_spectate.lua")
include("cl_health.lua")
include("sh_weightedrandom.lua")
include("cl_killfeed.lua")
include("cl_voicepanels.lua")
include("cl_disguise.lua")
include("cl_taunt.lua")
include("cl_endroundboard.lua")
include("cl_wraptext.lua")
include("cl_mapvote.lua")
include("cl_bannedmodels.lua")

function GM:Initialize() 
end

function GM:InitPostEntity()
	net.Start("clientIPE")
	net.SendToServer()
end

function GM:Think()
end


function GM:EntityRemoved(ent)

end

function GM:PostDrawViewModel( vm, ply, weapon )

	if ( weapon.UseHands || !weapon:IsScripted() ) then

		local hands = LocalPlayer():GetHands()
		if ( IsValid( hands ) ) then hands:DrawModel() end

	end

end

function GM:RenderScene( origin, angles, fov )
	local client = LocalPlayer()
	if IsValid(client) then
		local wep = client:GetActiveWeapon()
		if IsValid(wep) && wep.PostDrawTranslucentRenderables then
			local errored, retval = pcall(wep.PostDrawTranslucentRenderables, wep)
			if !errored then
				print( retval )
			end
		end
	end
end


function GM:PostDrawTranslucentRenderables()

end
function GM:DrawMonitors()
end

function GM:PreDrawTranslucentRenderables()

end

function GM:PreDrawHalos()
	self:RenderDisguiseHalo()
end


function GM:OnReloaded()
end



local function lerp(from, to, step)
	if from < to then
		return math.min(from + step, to)	
	end
	return math.max(from - step, to)
end

function GM:ShouldDrawLocalPlayer()
	return false
end

function GM:CreateMove( cmd )

end

net.Receive("hull_set", function (len)
	local ply = net.ReadEntity()
	if !IsValid(ply) then return end
	local hullx = net.ReadFloat()
	local hully = net.ReadFloat()
	local hullz = net.ReadFloat()
	local duckz = net.ReadFloat()
	GAMEMODE:PlayerSetHull(ply, hullx, hully, hullz, duckz)
end)


function GM:RenderScene()
	self:RenderDisguises()
end

function GM:PostDrawEffects()
end

function GM:EntityRemoved(ent)
	if IsValid(ent.PropMod) then
		ent.PropMod:Remove()
	end
end

concommand.Add("+menu_context", function ()
	RunConsoleCommand("ph_lockrotation")
end)

concommand.Add("-menu_context", function ()
end)

net.Receive("player_model_sex", function ()
	local sex = net.ReadString()
	if #sex == 0 then
		sex = nil
	end
	GAMEMODE.PlayerModelSex = sex
end)

function GM:StartChat()
	if IsValid(self.EndRoundPanel) && self.EndRoundPanel:IsVisible() then
		timer.Simple(0, function () chat.Close() end)

		self.EndRoundPanel:SetKeyboardInputEnabled(true)
		self.EndRoundPanel.ChatTextEntry:RequestFocus()
		return true
	end
end

function GM:ChatText(i, name, text, filter)
	self:EndRoundAddChatText(Color(0, 120, 220), text)

	if ( filter == "chat" ) then
		Msg( name, ": ", text, "
" )
	else
		Msg( text, "
" )
	end
	
	return false
end

local function GM:CalcView(ply, pos, angles, fov)
	if self:IsCSpectating() && IsValid(self:GetCSpectatee()) then
		ply = self:GetCSpectatee()
	end
	if ply:IsPlayer() && !ply:Alive() then
		ply = ply:GetRagdollEntity()
	end
	if IsValid(ply) then
		if ply:IsPlayer() && ply:IsDisguised() then
			local maxs = ply:GetNWVector("disguiseMaxs")
			local mins = ply:GetNWVector("disguiseMins")
			local view = {}

			local reach = math.max(135, maxs.z - mins.z)
			local trace = {}
			trace.start = ply:GetPropEyePos()
			trace.endpos = trace.start + angles:Forward() * -(reach + 5)
			local tab = ents.FindByClass("prop_ragdoll")
			table.insert(tab, ply)
			trace.filter = tab

			local tr = util.TraceLine(trace)
			view.origin = trace.start + (trace.endpos - trace.start):GetNormal() * math.Clamp(trace.start:Distance(tr.HitPos) - 5, 0, reach)

			view.angles = angles
			view.fov = fov
			return view
		end
	end
end

cl_disguise.lua


include("sh_disguise.lua")

local PlayerMeta = FindMetaTable("Player")

function PlayerMeta:IsDisguised()
	return self:GetNWBool("disguised", false)
end

local function renderDis(self)
	for k, ply in pairs(player.GetAll()) do
		if ply:Alive() && ply:IsDisguised() then
			local model = ply:GetNWString("disguiseModel")
			if model && model != "" then

				local ent = ply:GetNWEntity("disguiseEntity")
				if IsValid(ent) then
					-- ent:SetNoDraw(false)
					local mins = ply:GetNWVector("disguiseMins")
					local maxs = ply:GetNWVector("disguiseMaxs")
					local ang = ply:EyeAngles()
					ang.p = 0
					ang.r = 0
					if ply:DisguiseRotationLocked() then
						ang.y = ply:GetNWFloat("disguiseRotationLockYaw")
					end
					local pos = ply:GetPos() + Vector(0, 0, -mins.z)
					local center = (maxs + mins) / 2
					center.z = 0
					center:Rotate(ang)
					ent:SetPos(pos - center)
					ent:SetAngles(ang)
					-- ent:SetupBones()
					ent:SetSkin(ply:GetNWInt("disguiseSkin", 1))
					-- ent:DrawShadow()
					-- ent:DrawModel()
				end
			end
		else
			local ent = ply:GetNWEntity("disguiseEntity")
			if IsValid(ent) then
				-- ent:SetNoDraw(true)
			end
		end
	end
end

function GM:RenderDisguises()
	
	cam.Start3D( EyePos(), EyeAngles() )
	local b, err = pcall(renderDis, self)
	cam.End3D()
	if !b then
		MsgC(Color(255, 0, 0), err .. "
")
	end
end

function GM:RenderDisguiseHalo()
	local client = LocalPlayer()
	if client:Team() == 3 then
		local tr = client:GetPropEyeTrace()
		if IsValid(tr.Entity) then
			if tr.HitPos:Distance(tr.StartPos) < 100 then
				if client:CanDisguiseAsProp(tr.Entity) then
					local col = Color(50, 220, 50)
					local hullxy, hullz = tr.Entity:GetPropSize()
					if !client:CanFitHull(hullxy, hullxy, hullz) then
						col = Color(220, 50, 50)
					end
					halo.Add({tr.Entity}, col, 2, 2, 2, true, true)
				end
			end
		end
		local tab = {}
		for k, ply in pairs(player.GetAll()) do
			if ply != client && ply:Team() == 3 && ply:IsDisguised() then
				if IsValid(ply.PropMod) then
					table.insert(tab, ply.PropMod)
				end
			end
		end
		halo.Add(tab, team.GetColor(3), 2, 2, 2, true, false)
	end

end

function GM:CalcView(ply, pos, angles, fov)
	if self:IsCSpectating() && IsValid(self:GetCSpectatee()) then
		ply = self:GetCSpectatee()
	end
	if ply:IsPlayer() && !ply:Alive() then
		ply = ply:GetRagdollEntity()
	end
	if IsValid(ply) then
		if ply:IsPlayer() && ply:IsDisguised() then
			local maxs = ply:GetNWVector("disguiseMaxs")
			local mins = ply:GetNWVector("disguiseMins")
			local view = {}

			local reach = math.max(135, maxs.z - mins.z)
			local trace = {}
			trace.start = ply:GetPropEyePos()
			trace.endpos = trace.start + angles:Forward() * -(reach + 5)
			local tab = ents.FindByClass("prop_ragdoll")
			table.insert(tab, ply)
			trace.filter = tab

			local tr = util.TraceLine(trace)
			view.origin = trace.start + (trace.endpos - trace.start):GetNormal() * math.Clamp(trace.start:Distance(tr.HitPos) - 5, 0, reach)

			view.angles = angles
			view.fov = fov
			return view
		end
	end
end

Please help if you can! D; This has been nagging at me for a long while now

Uh…This should just be



function GM:CalcView(...)


Also, you should combine the two CalcView functions.

Ah, explain please?

Scroll to the bottom of each of your files and you’ll see. There are two functions with the key CalcView in the GM table. This means that the function defined last will overwrite the function defined first.

Ahh hang on…

[editline]15th April 2016[/editline]

I am very much confused. I don’t see CalcView written twice at the bottom?

facepalm
You have this in cl_disguise.lua: [lua]function GM:CalcView(ply, pos, angles, fov)
if self:IsCSpectating() && IsValid(self:GetCSpectatee()) then
ply = self:GetCSpectatee()
end
if ply:IsPlayer() && !ply:Alive() then
ply = ply:GetRagdollEntity()
end
if IsValid(ply) then
if ply:IsPlayer() && ply:IsDisguised() then
local maxs = ply:GetNWVector(“disguiseMaxs”)
local mins = ply:GetNWVector(“disguiseMins”)
local view = {}

		local reach = math.max(135, maxs.z - mins.z)
		local trace = {}
		trace.start = ply:GetPropEyePos()
		trace.endpos = trace.start + angles:Forward() * -(reach + 5)
		local tab = ents.FindByClass("prop_ragdoll")
		table.insert(tab, ply)
		trace.filter = tab

		local tr = util.TraceLine(trace)
		view.origin = trace.start + (trace.endpos - trace.start):GetNormal() * math.Clamp(trace.start:Distance(tr.HitPos) - 5, 0, reach)

		view.angles = angles
		view.fov = fov
		return view
	end
end

end[/lua] And this in cl_init.lua: [lua]local function GM:CalcView(ply, pos, angles, fov)
if self:IsCSpectating() && IsValid(self:GetCSpectatee()) then
ply = self:GetCSpectatee()
end
if ply:IsPlayer() && !ply:Alive() then
ply = ply:GetRagdollEntity()
end
if IsValid(ply) then
if ply:IsPlayer() && ply:IsDisguised() then
local maxs = ply:GetNWVector(“disguiseMaxs”)
local mins = ply:GetNWVector(“disguiseMins”)
local view = {}

		local reach = math.max(135, maxs.z - mins.z)
		local trace = {}
		trace.start = ply:GetPropEyePos()
		trace.endpos = trace.start + angles:Forward() * -(reach + 5)
		local tab = ents.FindByClass("prop_ragdoll")
		table.insert(tab, ply)
		trace.filter = tab

		local tr = util.TraceLine(trace)
		view.origin = trace.start + (trace.endpos - trace.start):GetNormal() * math.Clamp(trace.start:Distance(tr.HitPos) - 5, 0, reach)

		view.angles = angles
		view.fov = fov
		return view
	end
end

end[/lua]

Since they’re literally the same, and the one in cl_disguise is local, you might as well get rid of it and keep the one in cl_init.lua

My apologies for being stupid…

The one in cl_init.lua is the local one, not cl_disguise…? Regardless, I removed the code from cl_disguise and kept the one in cl_init, but still not getting the result I’m wanting. Nothing has changed.