Advertisement
Guest User

test 2

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