-
Notifications
You must be signed in to change notification settings - Fork 789
/
gmod_camera.lua
280 lines (181 loc) · 5.83 KB
/
gmod_camera.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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"
util.PrecacheModel( SWEP.ViewModel )
util.PrecacheModel( SWEP.WorldModel )
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
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
if ( SERVER ) then
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
--
-- A concommand to quickly switch to the camera
--
concommand.Add( "gmod_camera", function( player, command, arguments )
player:SelectWeapon( "gmod_camera" )
end )
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" );
if ( SERVER ) then
self:SetZoom( 70 )
self:SetRoll( 0 )
end
end
--[[---------------------------------------------------------
Initialize Stuff
-----------------------------------------------------------]]
function SWEP:Initialize()
self:SetWeaponHoldType( "camera" )
end
--[[---------------------------------------------------------
Precache Stuff
-----------------------------------------------------------]]
function SWEP:Precache()
util.PrecacheSound( self.ShootSound )
end
--[[---------------------------------------------------------
Reload does nothing
-----------------------------------------------------------]]
function SWEP:Reload()
if ( !self.Owner:KeyDown( IN_ATTACK2 ) ) then self:SetZoom( 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
-----------------------------------------------------------]]
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
-----------------------------------------------------------]]
function SWEP:SecondaryAttack()
-- Nothing. See Think for zooming.
end
--[[---------------------------------------------------------
-----------------------------------------------------------]]
function SWEP:Tick()
local cmd = self.Owner:GetCurrentCommand()
local fDelta = 0.05
self:DoZoomThink( cmd, fDelta )
self:DoRotateThink( cmd, fDelta )
end
--[[---------------------------------------------------------
-----------------------------------------------------------]]
function SWEP:DoZoomThink( cmd, fDelta )
-- Right held down
if ( !cmd:KeyDown( IN_ATTACK2 ) ) then return end
self:SetZoom( math.Clamp( self:GetZoom() + cmd:GetMouseY() * 2 * fDelta, 0.1, 175 ) )
end
if ( CLIENT ) then
-- Don't draw the weapon info on the weapon selection thing
function SWEP:DrawHUD() end
function SWEP:PrintWeaponInfo( x, y, alpha ) end
function SWEP:HUDShouldDraw( name )
-- So we can change weapons
if ( name == "CHudWeaponSelection" ) then return true end
if ( name == "CHudChat" ) then return true end
return false;
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
return false
end
function SWEP:CalcView( ply, origin, angles, fov )
if ( self:GetRoll() != 0 ) then
angles.Roll = self:GetRoll()
end
return origin, angles, fov
end
function SWEP:AdjustMouseSensitivity()
if ( self.Owner:KeyDown( IN_ATTACK2 ) ) then return 1 end
return 1 * ( self:GetZoom() / 80 )
end
end
--
-- Rotate Think
--
function SWEP:DoRotateThink( cmd, fDelta )
if ( cmd:KeyDown( IN_ATTACK2 ) ) then
self:SetRoll( self:GetRoll() + cmd:GetMouseX() * 0.5 * fDelta )
end
end
--
-- TranslateFOV
--
function SWEP:TranslateFOV( current_fov )
return self:GetZoom()
end
--
-- Allow lastinv
--
function SWEP:Deploy()
return true
end
--
-- Set FOV to players desired FOV
--
function SWEP:Equip()
if ( self:GetZoom() == 70 && self.Owner:IsPlayer() ) then
self:SetZoom( self.Owner:GetInfoNum( "fov_desired", 75 ) )
end
end
function SWEP:ShouldDropOnDie() return false end