-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.lua
197 lines (138 loc) · 3.85 KB
/
shared.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
SWEP.Author = "The Killer [NL]"
SWEP.Contact = "gooferclan@gmail.com"
SWEP.Purpose = "Allows You To Swing Around of The Map Like A Boss"
SWEP.Instructions = "Left click to shot web"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.PrintName = "Spiderman's Gun"
SWEP.Slot = 2
SWEP.SlotPos = 0
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
function SWEP:Initialize()
nextshottime = CurTime()
self:SetWeaponHoldType( "pistol" )
end
function SWEP:Think()
if (!self.Owner || self.Owner == NULL) then return end
if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
self:StartAttack()
elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
self:UpdateAttack()
elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
self:EndAttack( true )
end
if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
self:Attack2()
end
end
function SWEP:DoTrace( endpos )
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096)
if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
trace.filter = { self.Owner, self.Weapon }
self.Tr = nil
self.Tr = util.TraceLine( trace )
end
function SWEP:StartAttack()
local gunPos = self.Owner:GetShootPos()
local disTrace = self.Owner:GetEyeTrace()
local hitPos = disTrace.HitPos
local x = (gunPos.x - hitPos.x)^2;
local y = (gunPos.y - hitPos.y)^2;
local z = (gunPos.z - hitPos.z)^2;
local distance = math.sqrt(x + y + z);
local distanceCvar = GetConVarNumber("rope_distance")
inRange = false
if distance <= distanceCvar then
inRange = true
end
if inRange then
if (SERVER) then
if (!self.Beam) then
self.Beam = ents.Create( "rope" )
self.Beam:SetPos( self.Owner:GetShootPos() )
self.Beam:Spawn()
end
self.Beam:SetParent( self.Owner )
self.Beam:SetOwner( self.Owner )
end
self:DoTrace()
self.speed = 10000
self.startTime = CurTime()
self.endTime = CurTime() + self.speed
self.dt = -1
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
end
self:UpdateAttack()
else
end
end
function SWEP:UpdateAttack()
self.Owner:LagCompensation( true )
if (!endpos) then endpos = self.Tr.HitPos end
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( endpos )
end
lastpos = endpos
if ( self.Tr.Entity:IsValid() ) then
endpos = self.Tr.Entity:GetPos()
if ( SERVER ) then
self.Beam:GetTable():SetEndPos( endpos )
end
end
local vVel = (endpos - self.Owner:GetPos())
local Distance = endpos:Distance(self.Owner:GetPos())
local et = (self.startTime + (Distance/self.speed))
if(self.dt != 0) then
self.dt = (et - CurTime()) / (et - self.startTime)
end
if(self.dt < 0) then
self.dt = 0
end
if(self.dt == 0) then
zVel = self.Owner:GetVelocity().z
vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
if( SERVER ) then
local gravity = GetConVarNumber("sv_Gravity")
vVel:Add(Vector(0,0,(gravity/100)*1.5))
if(zVel < 0) then
vVel:Sub(Vector(0,0,zVel/100))
end
self.Owner:SetVelocity(vVel)
end
end
endpos = nil
self.Owner:LagCompensation( false )
end
function SWEP:EndAttack( shutdownsound )
if ( CLIENT ) then return end
if ( !self.Beam ) then return end
self.Beam:Remove()
self.Beam = nil
end
function SWEP:Attack2()
if (CLIENT) then return end
local CF = self.Owner:GetFOV()
if CF == 90 then
self.Owner:SetFOV(30,.3)
elseif CF == 30 then
self.Owner:SetFOV(90,.3)
end
end
function SWEP:Holster()
self:EndAttack( false )
return true
end
function SWEP:OnRemove()
self:EndAttack( false )
return true
end
function SWEP:PrimaryAttack()
end
function SWEP:SecondaryAttack()
end