Move mouse with Lua?

I’m trying to get splitscreen working to play with a friend, but i’ve run into a problem.
+lookup and +lookdown are broken. They simply do nothing in Garry’s mod. I’m mapping a gamepad for the second player (The concmd’s don’t work with keyboard mappings either). Now i know there is a gui.SetMousePos(x,y), but this only works for the cursor right? Is there any function that allows me to directly move the players view?

http://puu.sh/9OUB

[editline]3rd December 2011[/editline]

Whipped something up, can someone tell me why this doesnt work?


looking_up = 0
looking_down = 0

function upStart(player,command,args)
	looking_up = 1
end

function upStop(player,command,args)
	looking_up = 0
end

function downStart(player,command,args)
	looking_down = 1
end

function downStop(player,command,args)
	looking_down = 0
end

function MyCalcView(ply, pos, angles, fov)
    local view = {}
    view.origin = pos
    view.fov = fov
 
	if looking_up then
		view.angles = angles+Angle(1,0,0)
		return view
	elseif looking_down then
	    view.angles = angles-Angle(1,0,0)
		return view
	end
end
 
hook.Add("CalcView", "MyCalcView", MyCalcView)
 
-- Console commands
concommand.Add("+up",upStart)
concommand.Add("-up",upStop)
concommand.Add("+down",downStart)
concommand.Add("-down",downStop)


**[Gamemode.CreateMove

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.CreateMove)**

[editline]3th December 2011[/editline]
Also your calcview function would never work anyway because looking_up will always be true in that hook, and it would always add 1 to the pitch, nothing else, it would never increase.

Oops yeah, i had to player:eyeAngles+Angle(1,0,0)

[editline]3rd December 2011[/editline]

Got it done, thanks for that hook btw!



looking_up = 0
looking_down = 0
looking_left = 0
looking_right = 0

ysens = CreateConVar("y_sens", "0.5")
xsens = CreateConVar("x_sens", "0.5")

function upStart(player,command,args)
	if looking_up == 0 then
		hook.Add("CreateMove", "ViewFix", ViewFix)
		looking_up = 1
	end
end

function upStop(player,command,args)
	looking_up = 0
	if looking_up == 0 & looking_down == 0 & looking_left == 0 & looking_right ==0 then
		hook.Remove("CreateMove", "ViewFix")
	end
end

function downStart(player,command,args)
	if looking_down == 0 then
		hook.Add("CreateMove", "ViewFix", ViewFix)
		looking_down = 1
	end
end

function downStop(player,command,args)
	looking_down = 0
	if looking_up == 0 & looking_down == 0 & looking_left == 0 & looking_right ==0 then
		hook.Remove("CreateMove", "ViewFix")
	end
end




function leftStart(player,command,args)
	if looking_left == 0 then
		hook.Add("CreateMove", "ViewFix", ViewFix)
		looking_left = 1
	end
end

function leftStop(player,command,args)
	looking_left = 0
	if looking_up == 0 & looking_down == 0 & looking_left == 0 & looking_right ==0 then
		hook.Remove("CreateMove", "ViewFix")
	end
end

function rightStart(player,command,args)
	if looking_right == 0 then
		hook.Add("CreateMove", "ViewFix", ViewFix)
		looking_right = 1
	end
end

function rightStop(player,command,args)
	looking_right = 0
	if looking_up == 0 & looking_down == 0 & looking_left == 0 & looking_right ==0 then
		hook.Remove("CreateMove", "ViewFix")
	end
end

function ViewFix(cmd)
	local pitch = LocalPlayer():EyeAngles().p
	local yaw = LocalPlayer():EyeAngles().y
	local roll = LocalPlayer():EyeAngles().r
	local y = ysens:GetFloat()
	local x = xsens:GetFloat()
	
	if looking_up==1 then
		pitch = pitch-y
	elseif looking_down==1 then
	    pitch = pitch+y
	end
	
	if looking_left==1 then
		yaw = yaw+x
	elseif looking_right==1 then
		yaw = yaw-x
	end	
	
	local fPitch = math.Clamp(pitch, -180, 180)
	local fAng = Angle(fPitch, yaw, roll)
	cmd:SetViewAngles(fAng)
end

 
-- Console commands
concommand.Add("+up",upStart)
concommand.Add("-up",upStop)
concommand.Add("+down",downStart)
concommand.Add("-down",downStop)
concommand.Add("+right2",rightStart)
concommand.Add("-right2",rightStop)
concommand.Add("+left2",leftStart)
concommand.Add("-left2",leftStop)


Another question. The code above doesn’t work with prop rotation. Anyone can help me on that?

[editline]3rd December 2011[/editline]

And how can i simulate a mouse click in the spawn menu? +attack isn’t working here…