thomasfn

Untitled

Aug 28th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.33 KB | None | 0 0
  1.  
  2. if (SERVER) then AddCSLuaFile( "alienswarmcamera.lua" ) end
  3.  
  4. if (CLIENT) then
  5.  
  6.     local mX = ScrW() / 2
  7.     local mY = ScrH() / 2
  8.  
  9.     local view = {}
  10.     local vec = Vector( 0, -64, 256 )
  11.     local dist = 64
  12.     local function CalcView( ply, origin, angles, fov )
  13.         view.origin = ply:GetPos() + vec
  14.         if (view.AimPosition) then
  15.             local aim = view.AimPosition
  16.             aim.z = view.origin.z
  17.             view.origin = Lerp( 0.25, view.origin, view.AimPosition )
  18.         end
  19.         view.angles = (vec * -1):Angle()
  20.         view.fov = fov
  21.         return view
  22.     end
  23.     hook.Add( "CalcView", "AS_Cam", CalcView )
  24.    
  25.     local function ShouldDrawLocalPlayer()
  26.         return true
  27.     end
  28.     hook.Add( "ShouldDrawLocalPlayer", "AS_DrawLocal", ShouldDrawLocalPlayer )
  29.    
  30.    
  31.     local trace = {}
  32.     local colBlue = Color( 0, 0, 255 )
  33.     local function InputMouseApply( cmd, x, y, angle )
  34.         local w, h = ScrW(), ScrH()
  35.         mX = mX + (x / 5)
  36.         mY = mY + (y / 5)
  37.         if (mX > w) then mX = w end
  38.         if (mY > h) then mY = h end
  39.         if (mX < 0) then mX = 0 end
  40.         if (mY < 0) then mY = 0 end
  41.        
  42.         --print( x, y )
  43.         trace.start = view.origin
  44.         trace.endpos = trace.start + (gui.ScreenToVector( mX, mY ) * 1024)
  45.         local tr = util.TraceLine( trace )
  46.         local ang = (tr.HitPos - LocalPlayer():GetShootPos()):Angle()
  47.         cmd:SetViewAngles( ang )
  48.         --debugoverlay.Line(tr.StartPos, tr.HitPos, 10, Color(255, 0, 0))
  49.         view.AimPosition = tr.HitPos
  50.         debugoverlay.Cross( tr.HitPos, 15, 0.05, colBlue )
  51.         return true
  52.     end
  53.     hook.Add( "InputMouseApply", "AS_Mouse", InputMouseApply )
  54.    
  55.     local function HUDPaint()
  56.         if (view.AimPosition) then
  57.             local w, h = ScrW(), ScrH()
  58.             local ang = math.atan2( mY - (h / 2), mX - (w / 2) )
  59.            
  60.             surface.SetDrawColor( color_white )
  61.             surface.DrawLine( mX, mY, mX + (10 * -math.cos(ang)), mY + (10 * -math.sin(ang)) )
  62.             surface.DrawLine( mX, mY, mX + (10 * -math.sin(ang)), mY + (10 * math.cos(ang)) )
  63.             surface.DrawLine( mX, mY, mX + (10 * math.sin(ang)), mY + (10 * -math.cos(ang)) )
  64.         end
  65.     end
  66.     hook.Add( "HUDPaint", "AS_Paint", HUDPaint )
  67.    
  68.     local function HUDShouldDraw( name )
  69.         if (name == "CHudCrosshair") then return false end
  70.     end
  71.     hook.Add( "HUDShouldDraw", "AS_Hud", HUDShouldDraw )
  72.  
  73. end
  74.  
  75. local unitForward = Vector( 0, 1, 0 )
  76. local unitRight = Vector( 1, 0, 0 )
  77. local speed = 270
  78. local acc = 2000
  79. local friction = 5
  80. local function SetupMove( ply, data )
  81.     local t = CurTime()
  82.     ply.lastFrame = ply.lastFrame or t
  83.     ply.moveVel = ply.moveVel or Vector( 0, 0, 0 )
  84.     local forward = 0
  85.     local right = 0
  86.     if (ply:KeyDown( IN_FORWARD )) then forward = 1 end
  87.     if (ply:KeyDown( IN_BACK )) then forward = -1 end
  88.     if (ply:KeyDown( IN_MOVERIGHT )) then right = 1 end
  89.     if (ply:KeyDown( IN_MOVELEFT )) then right = -1 end
  90.     local accel = ((unitForward * forward) + (unitRight * right)):Normalize() * acc
  91.     local delta = t - ply.lastFrame
  92.     ply.lastFrame = t
  93.     ply.moveVel = (ply.moveVel + (accel * delta)) * math.Clamp( 1 - (friction * delta), 0, 1 )
  94.     local len = ply.moveVel:Length()
  95.     if (len > speed) then ply.moveVel = ply.moveVel:Normalize() * speed end
  96.     local z = data:GetVelocity().z
  97.     ply.moveVel.z = z
  98.     data:SetVelocity( ply.moveVel )
  99. end
  100. hook.Add( "Move", "AS_SetupMove", SetupMove )
  101.  
  102. if (SERVER) then
  103.  
  104.     local function PlayerConnect( ply )
  105.         ply:SetMaxSpeed( 0 )
  106.         ply:SetWalkSpeed( 0 )
  107.         ply:SetRunSpeed( 0 )
  108.     end
  109.     hook.Add( "PlayerConnect", "AS_PlayerC", PlayerConnect )
  110.  
  111. end
Advertisement
Add Comment
Please, Sign In to add comment