Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. include('shared.lua')
  2.  
  3. SWEP.PrintName = "#GMOD_Camera"
  4. SWEP.Slot = 5
  5. SWEP.SlotPos = 1
  6. SWEP.DrawAmmo = false
  7. SWEP.DrawCrosshair = false
  8. SWEP.Spawnable = false
  9. SWEP.AdminSpawnable = false
  10. SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_camera" )
  11.  
  12. // Don't draw the weapon info on the weapon selection thing
  13. function SWEP:DrawHUD() end
  14. function SWEP:PrintWeaponInfo( x, y, alpha ) end
  15.  
  16.  
  17. function SWEP:HUDShouldDraw( name )
  18.  
  19. // So we can change weapons
  20. if (name == "CHudWeaponSelection") then return true end
  21.  
  22. return false;
  23.  
  24. end
  25.  
  26. /*---------------------------------------------------------
  27. Name: SWEP:FreezeMovement()
  28. ---------------------------------------------------------*/
  29. function SWEP:FreezeMovement()
  30.  
  31. if ( self.m_fFreezeMovement ) then
  32.  
  33. if ( self.m_fFreezeMovement > RealTime() ) then return true end
  34.  
  35. self.m_fFreezeMovement = nil
  36.  
  37. end
  38.  
  39. // Don't aim if we're holding the right mouse button
  40. if ( self.Owner:KeyDown( IN_ATTACK2 ) || self.Owner:KeyReleased( IN_ATTACK2 ) ) then return true end
  41. return false
  42.  
  43. end
  44.  
  45. /*---------------------------------------------------------
  46. Name: CalcView
  47. Allows override of the default view
  48. ---------------------------------------------------------*/
  49. function SWEP:CalcView( ply, origin, angles, fov )
  50.  
  51. if ( self.Roll != 0 ) then
  52. angles.Roll = self.Roll
  53. end
  54.  
  55. if (!self.TrackEntity || !self.TrackEntity:IsValid()) then return origin, angles, fov end
  56.  
  57. local AimPos = self.TrackEntity:GetPos()
  58.  
  59. self.LastAngles = self.LastAngles or angles
  60.  
  61. if ( self.TrackOffset ) then
  62.  
  63. local Distance = AimPos:Distance( self.Owner:GetShootPos() )
  64.  
  65. AimPos = AimPos + Vector(0,0,1) * self.TrackOffset.y * 256
  66. AimPos = AimPos + self.LastAngles:Right() * self.TrackOffset.x * 256
  67.  
  68. end
  69.  
  70. local AimNormal = AimPos - self.Owner:GetShootPos()
  71. AimNormal:Normalize()
  72.  
  73. angles = AimNormal:Angle() //LerpAngle( 0.1, self.LastAngles, AimNormal:Angle() )
  74.  
  75. // Setting the eye angles here makes it so the player is actually aiming in this direction
  76. // Rather than just making their screen render in this direction.
  77. self.Owner:SetEyeAngles( Angle( angles.Pitch, angles.Yaw, 0 ) )
  78.  
  79. self.LastAngles = angles
  80.  
  81. if ( self.Roll != 0 ) then
  82. angles.Roll = self.Roll
  83. end
  84.  
  85. return origin, angles, fov
  86.  
  87. end
  88.  
  89. /*---------------------------------------------------------
  90. Think does nothing
  91. ---------------------------------------------------------*/
  92. function SWEP:DoRotateThink( cmd, fDelta )
  93.  
  94. // Think isn't frame rate independant on the client.
  95. // It gets called more per frame in single player than multiplayer
  96. // So we will have to make it frame rate independant ourselves
  97.  
  98.  
  99.  
  100. // Right held down
  101. if ( self.Owner:KeyDown( IN_ATTACK2 ) ) then
  102.  
  103. self.Roll = self.Roll + cmd:GetMouseX() * 0.5 * fDelta
  104.  
  105. end
  106.  
  107. // Right released
  108. if ( self.Owner:KeyReleased( IN_ATTACK2 ) ) then
  109.  
  110. // This stops the camera suddenly jumping when you release zoom
  111. self.m_fFreezeMovement = RealTime() + 0.1
  112.  
  113. end
  114.  
  115. // We are tracking an entity. Trace mouse movement for offsetting.
  116. if ( self.TrackEntity && self.TrackEntity != NULL && !self.Owner:KeyDown( IN_ATTACK2 ) ) then
  117.  
  118. self.TrackOffset = self.TrackOffset or Vector(0,0,0)
  119.  
  120. local cmd = self.Owner:GetCurrentCommand()
  121. self.TrackOffset.x = math.Clamp( self.TrackOffset.x + cmd:GetMouseX() * 0.005 * fDelta, -0.5, 0.5 )
  122. self.TrackOffset.y = math.Clamp( self.TrackOffset.y - cmd:GetMouseY() * 0.005 * fDelta, -0.5, 0.5 )
  123.  
  124. end
  125.  
  126. // If we're pressing use scan for an entity to track.
  127. if ( self.Owner:KeyDown( IN_USE ) && !self.TrackEntity ) then
  128.  
  129. self.TrackEntity = self.Owner:GetEyeTrace().Entity
  130. if ( self.TrackEntity && !self.TrackEntity:IsValid() ) then
  131.  
  132. self.TrackEntity = nil
  133. self.LastAngles = nil
  134. self.TrackOffset = nil
  135.  
  136. end
  137.  
  138. end
  139.  
  140. // Released use. Stop tracking.
  141. if ( self.Owner:KeyReleased( IN_USE ) ) then
  142.  
  143. self.TrackEntity = nil
  144. self.LastAngles = nil
  145. self.TrackOffset = nil
  146.  
  147. end
  148.  
  149. // Reload isn't called on the client, so fire it off here.
  150. if ( self.Owner:KeyPressed( IN_RELOAD ) ) then
  151.  
  152. self:Reload()
  153.  
  154. end
  155.  
  156. end
  157.  
  158. /*---------------------------------------------------------
  159. Name: TranslateFOV
  160. ---------------------------------------------------------*/
  161. function SWEP:TranslateFOV( current_fov )
  162.  
  163. return self.CameraZoom
  164.  
  165. end
  166.  
  167.  
  168. /*---------------------------------------------------------
  169. Name: AdjustMouseSensitivity()
  170. Desc: Allows you to adjust the mouse sensitivity.
  171. ---------------------------------------------------------*/
  172. function SWEP:AdjustMouseSensitivity()
  173.  
  174. if ( self.Owner:KeyDown( IN_ATTACK2 ) ) then return 1 end
  175.  
  176. return 1 * ( self.CameraZoom / 80 )
  177.  
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement