Advertisement
thatsmrcole

Untitled

Aug 30th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. SWEP.Author = "Darkfortune, Dorpz (For fixing)"
  2. SWEP.Contact = "dorpzman@hotmail.com"
  3. SWEP.Purpose = "Allows you to swing all over the place like!"
  4. SWEP.Instructions = "Left click to shot web"
  5.  
  6. SWEP.Spawnable = true
  7. SWEP.AdminSpawnable = true
  8.  
  9. SWEP.PrintName = "Spiderman's Gun"
  10. SWEP.Slot = 2
  11. SWEP.SlotPos = 0
  12. SWEP.DrawAmmo = false
  13. SWEP.DrawCrosshair = true
  14. SWEP.ViewModel = "models/weapons/v_pistol.mdl"
  15. SWEP.WorldModel = "models/weapons/w_pistol.mdl"
  16.  
  17. function SWEP:Initialize()
  18.  
  19. nextshottime = CurTime()
  20. self:SetWeaponHoldType( "pistol" )
  21.  
  22. end
  23.  
  24. function SWEP:Think()
  25.  
  26. if (!self.Owner || self.Owner == NULL) then return end
  27.  
  28. if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
  29.  
  30. self:StartAttack()
  31.  
  32. elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
  33.  
  34. self:UpdateAttack()
  35.  
  36. elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
  37.  
  38. self:EndAttack( true )
  39.  
  40. end
  41.  
  42. if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
  43.  
  44. self:Attack2()
  45.  
  46. end
  47.  
  48. end
  49.  
  50. function SWEP:DoTrace( endpos )
  51. local trace = {}
  52. trace.start = self.Owner:GetShootPos()
  53. trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096)
  54. if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
  55. trace.filter = { self.Owner, self.Weapon }
  56.  
  57. self.Tr = nil
  58. self.Tr = util.TraceLine( trace )
  59. end
  60.  
  61. function SWEP:StartAttack()
  62. local gunPos = self.Owner:GetShootPos()
  63. local disTrace = self.Owner:GetEyeTrace()
  64. local hitPos = disTrace.HitPos
  65.  
  66. local x = (gunPos.x - hitPos.x)^2;
  67. local y = (gunPos.y - hitPos.y)^2;
  68. local z = (gunPos.z - hitPos.z)^2;
  69. local distance = math.sqrt(x + y + z);
  70.  
  71. local distanceCvar = GetConVarNumber("rope_distance")
  72. inRange = false
  73. if distance <= distanceCvar then
  74. inRange = true
  75. end
  76.  
  77. if inRange then
  78. if (SERVER) then
  79.  
  80. if (!self.Beam) then
  81. self.Beam = ents.Create( "rope" )
  82. self.Beam:SetPos( self.Owner:GetShootPos() )
  83. self.Beam:Spawn()
  84. end
  85.  
  86. self.Beam:SetParent( self.Owner )
  87. self.Beam:SetOwner( self.Owner )
  88.  
  89. end
  90.  
  91. self:DoTrace()
  92. self.speed = 1000000000
  93. self.startTime = CurTime()
  94. self.endTime = CurTime() + self.speed
  95. self.dt = -1
  96.  
  97. if (SERVER && self.Beam) then
  98. self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
  99. end
  100.  
  101. self:UpdateAttack()
  102.  
  103. else
  104. end
  105. end
  106.  
  107. function SWEP:UpdateAttack()
  108.  
  109. self.Owner:LagCompensation( true )
  110.  
  111. if (!endpos) then endpos = self.Tr.HitPos end
  112.  
  113. if (SERVER && self.Beam) then
  114. self.Beam:GetTable():SetEndPos( endpos )
  115. end
  116.  
  117. lastpos = endpos
  118.  
  119.  
  120. if ( self.Tr.Entity:IsValid() ) then
  121.  
  122. endpos = self.Tr.Entity:GetPos()
  123. if ( SERVER ) then
  124. self.Beam:GetTable():SetEndPos( endpos )
  125. end
  126.  
  127. end
  128.  
  129. local vVel = (endpos - self.Owner:GetPos())
  130. local Distance = endpos:Distance(self.Owner:GetPos())
  131.  
  132. local et = (self.startTime + (Distance/self.speed))
  133. if(self.dt != 0) then
  134. self.dt = (et - CurTime()) / (et - self.startTime)
  135. end
  136. if(self.dt < 0) then
  137. self.dt = 0
  138. end
  139.  
  140. if(self.dt == 0) then
  141. zVel = self.Owner:GetVelocity().z
  142. vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
  143. if( SERVER ) then
  144. local gravity = GetConVarNumber("sv_Gravity")
  145. vVel:Add(Vector(0,0,(gravity/50)*1.5))
  146. if(zVel < 0) then
  147. vVel:Sub(Vector(0,0,zVel/100))
  148. end
  149. self.Owner:SetVelocity(vVel)
  150. end
  151. end
  152.  
  153. endpos = nil
  154.  
  155. self.Owner:LagCompensation( false )
  156.  
  157. end
  158.  
  159. function SWEP:EndAttack( shutdownsound )
  160.  
  161. if ( CLIENT ) then return end
  162. if ( !self.Beam ) then return end
  163.  
  164. self.Beam:Remove()
  165. self.Beam = nil
  166.  
  167. end
  168.  
  169. function SWEP:Attack2()
  170.  
  171.  
  172. if (CLIENT) then return end
  173. local CF = self.Owner:GetFOV()
  174. if CF == 90 then
  175. self.Owner:SetFOV(30,.3)
  176. elseif CF == 30 then
  177. self.Owner:SetFOV(90,.3)
  178. end
  179. end
  180.  
  181. function SWEP:Holster()
  182. self:EndAttack( false )
  183. return true
  184. end
  185.  
  186. function SWEP:OnRemove()
  187. self:EndAttack( false )
  188. return true
  189. end
  190.  
  191.  
  192. function SWEP:PrimaryAttack()
  193. end
  194.  
  195. function SWEP:SecondaryAttack()
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement