Cam move with mouse - Mouse spawn npc´s?

Hey, First sorry for my bad English

Ok lets begin im trying to make my first “real” gamemod, and have made a Top view and have the mouse on.

Top View:
[lua]
function MyCalcView( ply, origin, angles, fov )

local view = {}

view.origin = origin + Vector(0,0,1000) 
view.angles = angles + Angle(90,0,0) 

return view

end

hook.Add(“CalcView”, “MyCalcView”, MyCalcView)
[/lua]
and for the mouse on i use “gui.EnableScreenClicker(true)” so i need to know how to make it so when the mouse moves out to the side, the Camp view moves to, like if u used WASD.

And the last thing is that i need some way to spawn Zombies when i press Right mouse button i found a way on wiki but i cant get it to work, so help whould be good.

Keep in mind im a newbie :slight_smile: Thanks

-Trivkz

I got this to move my Cam now:

[lua]
function MyCalcView( ply, origin, angles, fov )

local view = {}
view.origin = origin + Vector(gui.MouseY(),gui.MouseX(),1000)
view.angles = angles + Angle(90,0,0)

return view

end
hook.Add(“CalcView”, “MyCalcView”, MyCalcView)
[/lua]

but as the good lua scripts can see that dosent work that good, i can only move it a verry short distance. so anyone got another way to do it?

Check if you are nearby any boundaries!

Ye that chould help, but i dont know how to do that. I looked up “boundaries” but found nothing :confused: on the wiki.

Use ScrW and ScrH

Hmm chould some one make a Exampel on how to use it with my code? i cant rly get it to work. Thanks

There’s a function for mouse aim vector, look in the Player dump.

I have this now.

Client site:

[lua]
function GM:CalcView( player, origin, angles, fov )

 player.oldorigin = player:GetNWVector("CameraPos")  
 local view = {}  
 view.origin = player.oldorigin  
 view.angles = Angle(90,0,0)  
 if gui.MouseX() < 5 then view.origin = player.oldorigin + <span class="highlight">Vector</span>(0,10,0) end  
 if gui.MouseX() > ScrW() - 5 then view.origin = player.oldorigin + <span class="highlight">Vector</span>(0,-10,0) end  
 if gui.MouseY() < 5 then view.origin = player.oldorigin + <span class="highlight">Vector</span>(10,0,0) end  
 if gui.MouseY() > ScrH() - 5 then view.origin = player.oldorigin + <span class="highlight">Vector</span>(-10,0,0) end  
 player.oldorigin = view.origin  
 RunConsoleCommand("UpdateViewPos", player.oldorigin.x, player.oldorigin.y, player.oldorigin.z)   

 if player:GetNWBool("IsInBirdEye") == true then  
     gui.EnableScreenClicker(true)  
    return view  
 elseif player:GetNWBool("IsInBirdEye") == false then  
     gui.EnableScreenClicker(false)  
 end  

end
[/lua]

Server site:
[lua]
function GM:KeyPress(ply, key)
if key == IN_RELOAD and ply:GetNWBool(“IsInBirdEye”) == false then
ply:SetNWBool(“IsInBirdEye”, true)
ply:SetNWVector(“CameraPos”, ply:GetPos() + <span class=“highlight”>Vector</span>(0,0,500))
elseif key == IN_RELOAD and ply:GetNWBool(“IsInBirdEye”) == true then
ply:SetNWBool(“IsInBirdEye”, false)
end

 if key == IN_ATTACK and ply:GetNWBool("IsInBirdEye") == true then  
	local orig = ply:GetNWVector("CameraPos")  
	local ang = ply:GetCursorAimVector()  
	local trace = util.QuickTrace(orig, orig + ang * 1e9, ply)  
     barrel = ents.Create("prop_physics")  
     barrel:SetModel("models/props_c17/oildrum001.mdl")  
     barrel:SetPos(trace.HitPos)  
     barrel:Spawn()  
 end  

end

concommand.Add(“UpdateViewPos”, function(ply, cmd, args)
if args[1] and args[2] and args[3] then
ply:SetNWVector(“CameraPos”, <span class=“highlight”>Vector</span>(args[1], args[2], args[3]))
end
end)
[/lua]

but i get this error: RTS_Trivkz/gamemode/cl_init.lua:18: unexpected symbol near ‘<’
anyone knows why i get that? Its line 7 here Btw.

[lua] function GM:CalcView( player, origin, angles, fov )

 player.oldorigin = player:GetNWVector("CameraPos")  
 local view = {}  
 view.origin = player.oldorigin  
 view.angles = Angle(90,0,0)  
 if gui.MouseX() &lt; 5 then view.origin = player.oldorigin + Vector(0,10,0) end  
 if gui.MouseX() &gt; ScrW() - 5 then view.origin = player.oldorigin + Vector(0,-10,0) end  
 if gui.MouseY() &lt; 5 then view.origin = player.oldorigin + Vector(10,0,0) end  
 if gui.MouseY() &gt; ScrH() - 5 then view.origin = player.oldorigin + Vector(-10,0,0) end  
 player.oldorigin = view.origin  
 RunConsoleCommand("UpdateViewPos", player.oldorigin.x, player.oldorigin.y, player.oldorigin.z)   

 if player:GetNWBool("IsInBirdEye") == true then  
     gui.EnableScreenClicker(true)  
    return view  
 elseif player:GetNWBool("IsInBirdEye") == false then  
     gui.EnableScreenClicker(false)  
 end  

end [/lua]

[lua] function GM:KeyPress(ply, key)
if key == IN_RELOAD and ply:GetNWBool(“IsInBirdEye”) == false then
ply:SetNWBool(“IsInBirdEye”, true)
ply:SetNWVector(“CameraPos”, ply:GetPos() + Vector(0,0,500))
elseif key == IN_RELOAD and ply:GetNWBool(“IsInBirdEye”) == true then
ply:SetNWBool(“IsInBirdEye”, false)
end

 if key == IN_ATTACK and ply:GetNWBool("IsInBirdEye") == true then  
	local orig = ply:GetNWVector("CameraPos")  
	local ang = ply:GetCursorAimVector()  
	local trace = util.QuickTrace(orig, orig + ang * 1e9, ply)  
     barrel = ents.Create("prop_physics")  
     barrel:SetModel("models/props_c17/oildrum001.mdl")  
     barrel:SetPos(trace.HitPos)  
     barrel:Spawn()  
 end  

end

concommand.Add(“UpdateViewPos”, function(ply, cmd, args)
if args[1] and args[2] and args[3] then
ply:SetNWVector(“CameraPos”, Vector(args[1], args[2], args[3]))
end
end)
[/lua] You had the stupid highlighting thing that comes about when you search. Fixed.

Thanks alot :slight_smile:

No problem.

Have another question, How do i make a selection box, that selects my zombie npc´s on left click and move them to the point u click with right mouse?

I know that u need to use traceline using EyePos() and EyeAngles() but i cant get that working, and i know that i need to use:

and

but i cant figure it out :confused: and Btw thats to thomasfn for the links. hope some one can help me :slight_smile: