aboutsummaryrefslogtreecommitdiff
path: root/entities/weapons/hands.lua
blob: 02c2500eccc2b9b78f8d3ecdd6bad669a4ca59ea (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
AddCSLuaFile("hands.lua")

SWEP.ViewModel				= "models/error.mdl"
SWEP.WorldModel				= "models/error.mdl"

SWEP.HoldType 				= "normal"

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   	= false
SWEP.Secondary.Ammo         = "none"

SWEP.DrawAmmo				= false
SWEP.DrawCrosshair			= false

function SWEP:Initialize()
	self:SetWeaponHoldType(self.HoldType)
	self:DrawShadow(false)
	
	if (CLIENT) then 
		self.MOB = ClientsideModel("error.mdl")
		self.MOB:SetNoDraw(true)
		self.MOB:DrawShadow(false)
	end
end

function SWEP:ShouldDropOnDie()
	return false
end

function SWEP:Think()
end

function SWEP:Reload()
end

local Box = Vector(8,8,8)

function SWEP:PrimaryAttack()
	if (CLIENT and !IsFirstTimePredicted()) then return end
	if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end
	if (self.Owner.CD and self.Owner.CD > CurTime()) then return end
	
	local item = self.Owner.Weapons[self.Owner.Select].Item
	
	if (!item or !item.OnPrimary) then return end
	
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	
	local Trace = {
		start 	= self.Owner:GetShootPos(),
		endpos 	= self.Owner:GetShootPos()+self.Owner:GetAimVector()*item.Range,
		filter 	= self.Owner,
		mins 	= Box*-1,
		maxs	= Box,
	}
		
	local Tr = util.TraceHull(Trace)
		
	item:OnPrimary(self.Owner,Tr)
	
	self.Owner.CD = CurTime()+item.CD
end

function SWEP:SecondaryAttack()
	if (CLIENT and !IsFirstTimePredicted()) then return end
	if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end
	if (self.Owner.CD and self.Owner.CD > CurTime()) then return end
	
	local item = self.Owner.Weapons[self.Owner.Select].Item
	
	if (!item or !item.OnSecondary) then return end
	
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	
	local Trace = {
		start 	= self.Owner:GetShootPos(),
		endpos 	= self.Owner:GetShootPos()+self.Owner:GetAimVector()*item.Range,
		filter 	= self.Owner,
		mins 	= Box*-1,
		maxs	= Box,
	}
		
	local Tr = util.TraceHull(Trace)
		
	item:OnSecondary(self.Owner,Tr) 
	
	self.Owner.CD = CurTime()+item.CD
end

if (CLIENT) then
	local Zero = Vector(1,1,1)
	
	function SWEP:DrawWorldModel()
		if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end
		
		local item = self.Owner.Weapons[self.Owner.Select].Item
		
		for k,v in pairs(item.Structure) do
			local ID 		= self.Owner:LookupBone(v.Bone)
			local Pos,Ang 	= self.Owner:GetBonePosition(ID)
			
			local Offset = v.Pos*1
			Offset:Rotate(Ang)
			Pos = Pos + Offset
			
			local Dang 	 = Ang*1
			
			Ang:RotateAroundAxis(Dang:Right(),v.Ang.p)
			Ang:RotateAroundAxis(Dang:Up(),v.Ang.y)
			Ang:RotateAroundAxis(Dang:Forward(),v.Ang.r)
			
			self.MOB:SetModel(v.Model)
			self.MOB:SetRenderOrigin(Pos)
			self.MOB:SetRenderAngles(Ang)
				
			local mat 	= Matrix()
			mat:Scale( v.Size or Zero )
			
			self.MOB:EnableMatrix( "RenderMultiply", mat )
			self.MOB:SetupBones()
			self.MOB:DrawModel() 
		end
	end
end