Permalink
Browse files

Update gmod_camera.lua

Fixed Facepunch/garrysmod-issues#1389 and cleaned up the code
  • Loading branch information...
1 parent bab2ab9 commit 3a1e9f01fe093246002acfebe59ec0aa28d1e4b8 @robotboy655 robotboy655 committed Aug 2, 2014
Showing with 114 additions and 168 deletions.
  1. +114 −168 garrysmod/gamemodes/sandbox/entities/weapons/gmod_camera.lua
@@ -1,17 +1,8 @@
-AddCSLuaFile()
-
--- Variables that are used on both client and server
-SWEP.Author = ""
-SWEP.Contact = ""
-SWEP.Purpose = ""
-SWEP.Instructions = ""
-
-SWEP.ViewModel = "models/weapons/c_arms_animations.mdl"
-SWEP.WorldModel = "models/MaxOfS2D/camera.mdl"
+AddCSLuaFile()
-util.PrecacheModel( SWEP.ViewModel )
-util.PrecacheModel( SWEP.WorldModel )
+SWEP.ViewModel = Model( "models/weapons/c_arms_animations.mdl" )
+SWEP.WorldModel = Model( "models/MaxOfS2D/camera.mdl" )
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
@@ -23,18 +14,20 @@ SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
-SWEP.ShootSound = "NPC_CScanner.TakePhoto"
-SWEP.PrintName = "#GMOD_Camera"
-SWEP.Slot = 5
-SWEP.SlotPos = 1
-SWEP.DrawAmmo = false
-SWEP.DrawCrosshair = false
-SWEP.Spawnable = true
+SWEP.PrintName = "#GMOD_Camera"
+
+SWEP.Slot = 5
+SWEP.SlotPos = 1
+
+SWEP.DrawAmmo = false
+SWEP.DrawCrosshair = false
+SWEP.Spawnable = true
+
+SWEP.ShootSound = Sound( "NPC_CScanner.TakePhoto" )
if ( SERVER ) then
- SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
@@ -49,19 +42,13 @@ if ( SERVER ) then
end
-if ( CLIENT ) then
-
- SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_camera" )
-
-end
-
--
-- Network/Data Tables
--
function SWEP:SetupDataTables()
- self:NetworkVar( "Float", 0, "Zoom" );
- self:NetworkVar( "Float", 1, "Roll" );
+ self:NetworkVar( "Float", 0, "Zoom" )
+ self:NetworkVar( "Float", 1, "Roll" )
if ( SERVER ) then
self:SetZoom( 70 )
@@ -70,211 +57,170 @@ function SWEP:SetupDataTables()
end
-
-
---[[---------------------------------------------------------
- Initialize Stuff
------------------------------------------------------------]]
+--
+-- Initialize Stuff
+--
function SWEP:Initialize()
self:SetHoldType( "camera" )
end
---[[---------------------------------------------------------
- Precache Stuff
------------------------------------------------------------]]
-function SWEP:Precache()
-
- util.PrecacheSound( self.ShootSound )
-
-end
-
---[[---------------------------------------------------------
- Reload does nothing
------------------------------------------------------------]]
+--
+-- Reload resets the FOV and Roll
+--
function SWEP:Reload()
- if ( !self.Owner:KeyDown( IN_ATTACK2 ) ) then self:SetZoom( self.Owner:GetInfoNum( "fov_desired", 75 ) ) end
+ if ( !self.Owner:KeyDown( IN_ATTACK2 ) ) then self:SetZoom( self.Owner:IsBot() && 75 || self.Owner:GetInfoNum( "fov_desired", 75 ) ) end
self:SetRoll( 0 )
-
-end
-
-
---[[---------------------------------------------------------
- The effect when a weapon is fired successfully
------------------------------------------------------------]]
-function SWEP:DoShootEffect()
-
- self.Weapon:EmitSound( self.ShootSound )
- self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
-
- if ( SERVER && !game.SinglePlayer() ) then
- --
- -- Note that the flash effect is only
- -- shown to other players!
- --
-
- local vPos = self.Owner:GetShootPos()
- local vForward = self.Owner:GetAimVector()
-
- local trace = {}
- trace.start = vPos
- trace.endpos = vPos + vForward * 256
- trace.filter = self.Owner
-
- local tr = util.TraceLine( trace )
-
- local effectdata = EffectData()
- effectdata:SetOrigin( tr.HitPos )
- util.Effect( "camera_flash", effectdata, true )
-
- end
-
end
---[[---------------------------------------------------------
- PrimaryAttack
------------------------------------------------------------]]
+--
+-- PrimaryAttack - make a screenshot
+--
function SWEP:PrimaryAttack()
self:DoShootEffect()
-
+
-- If we're multiplayer this can be done totally clientside
if ( !game.SinglePlayer() && SERVER ) then return end
if ( CLIENT && !IsFirstTimePredicted() ) then return end
-
+
self.Owner:ConCommand( "jpeg" )
-
+
end
---[[---------------------------------------------------------
- SecondaryAttack
------------------------------------------------------------]]
+--
+-- SecondaryAttack - Nothing. See Tick for zooming.
+--
function SWEP:SecondaryAttack()
-
- -- Nothing. See Think for zooming.
-
end
---[[---------------------------------------------------------
-
------------------------------------------------------------]]
+--
+-- Mouse 2 action
+--
function SWEP:Tick()
+ if ( CLIENT && self.Owner != LocalPlayer() ) then return end -- If someone is spectating a player holding this weapon, bail
+
local cmd = self.Owner:GetCurrentCommand()
-
- local fDelta = 0.05
- self:DoZoomThink( cmd, fDelta )
- self:DoRotateThink( cmd, fDelta )
+ if ( !cmd:KeyDown( IN_ATTACK2 ) ) then return end -- Not holding Mouse 2, bail
+
+ self:SetZoom( math.Clamp( self:GetZoom() + cmd:GetMouseY() * 0.1, 0.1, 175 ) ) -- Handles zooming
+ self:SetRoll( self:GetRoll() + cmd:GetMouseX() * 0.025 ) -- Handles rotation
end
---[[---------------------------------------------------------
-
------------------------------------------------------------]]
-function SWEP:DoZoomThink( cmd, fDelta )
+--
+-- Override players Field Of View
+--
+function SWEP:TranslateFOV( current_fov )
- -- Right held down
- if ( !cmd:KeyDown( IN_ATTACK2 ) ) then return end
-
- self:SetZoom( math.Clamp( self:GetZoom() + cmd:GetMouseY() * 2 * fDelta, 0.1, 175 ) )
+ return self:GetZoom()
end
-if ( CLIENT ) then
+--
+-- Deploy - Allow lastinv
+--
+function SWEP:Deploy()
+
+ return true
- -- Don't draw the weapon info on the weapon selection thing
- function SWEP:DrawHUD() end
- function SWEP:PrintWeaponInfo( x, y, alpha ) end
+end
- function SWEP:HUDShouldDraw( name )
+--
+-- Set FOV to players desired FOV
+--
+function SWEP:Equip()
- -- So we can change weapons
- if ( name == "CHudWeaponSelection" ) then return true end
- if ( name == "CHudChat" ) then return true end
-
- return false;
-
+ if ( self:GetZoom() == 70 && self.Owner:IsPlayer() && !self.Owner:IsBot() ) then
+ self:SetZoom( self.Owner:GetInfoNum( "fov_desired", 75 ) )
end
-
- function SWEP:FreezeMovement()
- -- Don't aim if we're holding the right mouse button
- if ( self.Owner:KeyDown( IN_ATTACK2 ) || self.Owner:KeyReleased( IN_ATTACK2 ) ) then
- return true
- end
+end
- return false
-
- end
+function SWEP:ShouldDropOnDie() return false end
- function SWEP:CalcView( ply, origin, angles, fov )
+--
+-- The effect when a weapon is fired successfully
+--
+function SWEP:DoShootEffect()
- if ( self:GetRoll() != 0 ) then
- angles.Roll = self:GetRoll()
- end
+ self:EmitSound( self.ShootSound )
+ self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
+ self.Owner:SetAnimation( PLAYER_ATTACK1 )
- return origin, angles, fov
-
- end
-
- function SWEP:AdjustMouseSensitivity()
+ if ( SERVER && !game.SinglePlayer() ) then
+
+ --
+ -- Note that the flash effect is only
+ -- shown to other players!
+ --
+
+ local vPos = self.Owner:GetShootPos()
+ local vForward = self.Owner:GetAimVector()
+
+ local trace = {}
+ trace.start = vPos
+ trace.endpos = vPos + vForward * 256
+ trace.filter = self.Owner
+
+ local tr = util.TraceLine( trace )
- if ( self.Owner:KeyDown( IN_ATTACK2 ) ) then return 1 end
+ local effectdata = EffectData()
+ effectdata:SetOrigin( tr.HitPos )
+ util.Effect( "camera_flash", effectdata, true )
- return 1 * ( self:GetZoom() / 80 )
-
end
end
+if ( SERVER ) then return end -- Only clientside lua after this line
+SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_camera" )
+-- Don't draw the weapon info on the weapon selection thing
+function SWEP:DrawHUD() end
+function SWEP:PrintWeaponInfo( x, y, alpha ) end
---
--- Rotate Think
---
-function SWEP:DoRotateThink( cmd, fDelta )
+function SWEP:HUDShouldDraw( name )
- if ( cmd:KeyDown( IN_ATTACK2 ) ) then
+ -- So we can change weapons
+ if ( name == "CHudWeaponSelection" ) then return true end
+ if ( name == "CHudChat" ) then return true end
- self:SetRoll( self:GetRoll() + cmd:GetMouseX() * 0.5 * fDelta )
-
- end
+ return false
end
---
--- TranslateFOV
---
-function SWEP:TranslateFOV( current_fov )
-
- return self:GetZoom()
+function SWEP:FreezeMovement()
-end
+ -- Don't aim if we're holding the right mouse button
+ if ( self.Owner:KeyDown( IN_ATTACK2 ) || self.Owner:KeyReleased( IN_ATTACK2 ) ) then
+ return true
+ end
---
--- Allow lastinv
---
-function SWEP:Deploy()
+ return false
- return true
-
end
---
--- Set FOV to players desired FOV
---
-function SWEP:Equip()
+function SWEP:CalcView( ply, origin, angles, fov )
- if ( self:GetZoom() == 70 && self.Owner:IsPlayer() ) then
- self:SetZoom( self.Owner:GetInfoNum( "fov_desired", 75 ) )
+ if ( self:GetRoll() != 0 ) then
+ angles.Roll = self:GetRoll()
end
+ return origin, angles, fov
+
end
-function SWEP:ShouldDropOnDie() return false end
+function SWEP:AdjustMouseSensitivity()
+
+ if ( self.Owner:KeyDown( IN_ATTACK2 ) ) then return 1 end
+
+ return self:GetZoom() / 80
+
+end

0 comments on commit 3a1e9f0

Please sign in to comment.