/
weapon_fists.lua
220 lines (144 loc) · 5.08 KB
/
weapon_fists.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
AddCSLuaFile()
SWEP.PrintName = "Fists"
SWEP.Author = "Killburn, robotboy655, MaxOfS2D & Tenrys"
SWEP.Purpose = "Well we sure as hell didn't use guns! We would just wrestle Hunters to the ground with our bare hands! I used to kill ten, twenty a day, just using my fists."
SWEP.Spawnable = true
SWEP.UseHands = true
SWEP.DrawAmmo = false
SWEP.ViewModel = "models/weapons/c_arms_citizen.mdl"
SWEP.WorldModel = ""
SWEP.ViewModelFOV = 52
SWEP.Slot = 0
SWEP.SlotPos = 5
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
local SwingSound = Sound( "weapons/slam/throw.wav" )
local HitSound = Sound( "Flesh.ImpactHard" )
function SWEP:Initialize()
self:SetWeaponHoldType( "fist" )
end
function SWEP:PreDrawViewModel( vm, wep, ply )
vm:SetMaterial( "engine/occlusionproxy" ) -- Hide that view model with hacky material
end
SWEP.HitDistance = 48
function SWEP:SetupDataTables()
self:NetworkVar( "Float", 0, "NextMeleeAttack" )
self:NetworkVar( "Float", 1, "NextIdle" )
self:NetworkVar( "Int", 2, "Combo" )
end
function SWEP:UpdateNextIdle()
local vm = self.Owner:GetViewModel()
self:SetNextIdle( CurTime() + vm:SequenceDuration() )
end
function SWEP:PrimaryAttack( right )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
local anim = "fists_left"
if ( right ) then anim = "fists_right" end
if ( self:GetCombo() >= 2 ) then
anim = "fists_uppercut"
end
local vm = self.Owner:GetViewModel()
vm:SendViewModelMatchingSequence( vm:LookupSequence( anim ) )
self:EmitSound( SwingSound )
self:UpdateNextIdle()
self:SetNextMeleeAttack( CurTime() + 0.2 )
self:SetNextPrimaryFire( CurTime() + 0.9 )
self:SetNextSecondaryFire( CurTime() + 0.9 )
end
function SWEP:SecondaryAttack()
self:PrimaryAttack( true )
end
function SWEP:DealDamage()
local anim = self:GetSequenceName(self.Owner:GetViewModel():GetSequence())
self.Owner:LagCompensation( true )
local tr = util.TraceLine( {
start = self.Owner:GetShootPos(),
endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
filter = self.Owner
} )
if ( !IsValid( tr.Entity ) ) then
tr = util.TraceHull( {
start = self.Owner:GetShootPos(),
endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
filter = self.Owner,
mins = Vector( -10, -10, -8 ),
maxs = Vector( 10, 10, 8 )
} )
end
if ( tr.Hit && SERVER ) then self.Owner:EmitSound( HitSound ) end
local hit = false
if ( SERVER && IsValid( tr.Entity ) && ( tr.Entity:IsNPC() || tr.Entity:IsPlayer() || tr.Entity:Health() > 0 ) ) then
local dmginfo = DamageInfo()
local attacker = self.Owner
if ( !IsValid( attacker ) ) then attacker = self end
dmginfo:SetAttacker( attacker )
dmginfo:SetInflictor( self )
dmginfo:SetDamage( math.random( 8, 12 ) )
if ( anim == "fists_left" ) then
dmginfo:SetDamageForce( self.Owner:GetRight() * 49125 + self.Owner:GetForward() * 99984 ) -- Yes we need those specific numbers
elseif ( anim == "fists_right" ) then
dmginfo:SetDamageForce( self.Owner:GetRight() * -49124 + self.Owner:GetForward() * 99899 )
elseif ( anim == "fists_uppercut" ) then
dmginfo:SetDamageForce( self.Owner:GetUp() * 51589 + self.Owner:GetForward() * 100128 )
dmginfo:SetDamage( math.random( 12, 24 ) )
end
tr.Entity:TakeDamageInfo( dmginfo )
hit = true
end
if ( SERVER && IsValid( tr.Entity ) ) then
local phys = tr.Entity:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:ApplyForceOffset( self.Owner:GetAimVector() * 80 * phys:GetMass(), tr.HitPos )
end
end
if ( SERVER ) then
if ( hit && anim != "fists_uppercut" ) then
self:SetCombo( self:GetCombo() + 1 )
else
self:SetCombo( 0 )
end
end
self.Owner:LagCompensation( false )
end
function SWEP:OnRemove()
if ( IsValid( self.Owner ) ) then
local vm = self.Owner:GetViewModel()
if ( IsValid( vm ) ) then vm:SetMaterial( "" ) end
end
end
function SWEP:Holster( wep )
self:OnRemove()
return true
end
function SWEP:Deploy()
local vm = self.Owner:GetViewModel()
vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_draw" ) )
self:UpdateNextIdle()
if ( SERVER ) then
self:SetCombo( 0 )
end
return true
end
function SWEP:Think()
local vm = self.Owner:GetViewModel()
local curtime = CurTime()
local idletime = self:GetNextIdle()
if ( idletime > 0 && CurTime() > idletime ) then
vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) )
self:UpdateNextIdle()
end
local meleetime = self:GetNextMeleeAttack()
if ( meleetime > 0 && CurTime() > meleetime ) then
self:DealDamage()
self:SetNextMeleeAttack( 0 )
end
if ( SERVER && CurTime() > self:GetNextPrimaryFire() + 0.1 ) then
self:SetCombo( 0 )
end
end