summaryrefslogtreecommitdiff
path: root/entities/weapons/rad_grenade/shared.lua
blob: 516f491dde2371d46713b074871d0bbc036c162f (plain)
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
if SERVER then

	AddCSLuaFile("shared.lua")
	
end

if CLIENT then

	SWEP.ViewModelFlip      = true
	
	SWEP.PrintName = "HE Grenade"
	SWEP.IconLetter = "h"
	SWEP.Slot = 3
	SWEP.Slotpos = 3
	
end

SWEP.HoldType = "grenade"

SWEP.Base = "rad_base"

SWEP.ViewModel			= "models/weapons/v_eq_fraggrenade.mdl"
SWEP.WorldModel			= "models/weapons/w_eq_fraggrenade.mdl"

SWEP.SprintPos = Vector (10.9603, -1.1484, -0.4996)
SWEP.SprintAng = Vector (13.9974, 21.7915, 59.3288)

SWEP.IsSniper = false
SWEP.AmmoType = "Knife"
SWEP.ThrowPower = 350

SWEP.Primary.Sound			= Sound( "WeaponFrag.Throw" )
SWEP.Primary.Recoil			= 6.5
SWEP.Primary.Damage			= 1
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.100
SWEP.Primary.Delay			= 2.300

SWEP.Primary.ClipSize		= 1
SWEP.Primary.Automatic		= false

function SWEP:Think()	

	if self.Owner:GetVelocity():Length() > 0 then
	
		if self.Owner:KeyDown( IN_SPEED ) and self.Owner:GetVelocity():Length() > 0 and self.Owner:GetNWFloat( "Weight", 0 ) < 50 then
		
			self.LastRunFrame = CurTime() + 0.3
		
		end
		
	end
	
	if self.ThrowTime then
	
		if self.ThrowTime - 0.3 < CurTime() and not self.ThrowAnim then
		
			self.ThrowAnim = true 
			
			if self.ThrowPower > 1000 then
			
				self.Weapon:SendWeaponAnim( ACT_VM_THROW )
				
			end
		
		end
		
		if self.ThrowTime < CurTime() then
	
			self.ThrowTime = nil
			self.ReloadTime = CurTime() + 0.75
			
			if CLIENT then return end
			
			local tbl = item.GetByModel( "models/weapons/w_eq_fraggrenade_thrown.mdl" )
			
			if self.Owner:HasItem( tbl.ID ) then 
		
				self.Owner:RemoveFromInventory( tbl.ID )
			
			end
			
			local ent = ents.Create( "sent_grenade" )
			ent:SetPos( self.Owner:GetShootPos() + self.Owner:GetRight() * 5 + self.Owner:GetUp() * -5 )
			ent:SetOwner( self.Owner )
			ent:SetAngles( self.Owner:GetAimVector():Angle() )
			ent:SetSpeed( self.ThrowPower )
			ent:Spawn()
			
			if not self.Owner:HasItem( tbl.ID ) then
				
				self.Owner:StripWeapon( "rad_grenade" )
				
			end
			
		end
	
	end
	
	if self.ReloadTime and self.ReloadTime < CurTime() then
	
		self.ReloadTime = nil
	
		self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
	
	end

end

function SWEP:SecondaryAttack()

	self.Weapon:SendWeaponAnim( ACT_VM_PULLBACK_LOW )
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:ShootEffects()
	
	self.ThrowTime = CurTime() + 1.25
	self.ThrowAnim = false
	self.ThrowPower = 800

end

function SWEP:PrimaryAttack()

	self.Weapon:SendWeaponAnim( ACT_VM_PULLBACK_LOW )
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:ShootEffects()
	
	self.ThrowTime = CurTime() + 1.25
	self.ThrowAnim = false
	self.ThrowPower = 3000
	
end

function SWEP:ShootEffects()	

	if IsFirstTimePredicted() then
	
		self.Owner:ViewPunch( Angle( math.Rand( -0.2, -0.1 ) * self.Primary.Recoil, math.Rand( -0.05, 0.05 ) * self.Primary.Recoil, 0 ) ) 
		
	end
								
	self.Owner:SetAnimation( PLAYER_ATTACK1 )	
	
end

function SWEP:DrawHUD()

end