Advertisement
Guest User

airboatgun

a guest
Jul 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1.  
  2. local function AirboatFire(ply,vehicle,shootOrigin,Attachment,damage)
  3. local bullet = {}
  4. bullet.Num = 1
  5. bullet.Src = shootOrigin
  6. bullet.Dir = Attachment.Ang:Forward()
  7. bullet.Spread = Vector(0.04,0.04,0)
  8. bullet.Tracer = 1
  9. bullet.TracerName = (damage > 10 and "AirboatGunHeavyTracer" or "AirboatGunTracer")
  10. bullet.Force = damage
  11. bullet.Damage = damage
  12. bullet.HullSize = 1
  13. bullet.DisableOverride = true
  14. bullet.Callback = function(att, tr, dmginfo)
  15. local effectdata = EffectData()
  16. effectdata:SetOrigin( tr.HitPos + tr.HitNormal )
  17. effectdata:SetNormal( tr.HitNormal )
  18. effectdata:SetRadius( (damage > 1) and 8 or 3 )
  19. util.Effect( "cball_bounce", effectdata, true, true )
  20. end
  21. bullet.Attacker = ply
  22.  
  23. vehicle:FireBullets( bullet )
  24. end
  25.  
  26. function simfphys.weapon:ValidClasses()
  27.  
  28. local classes = {
  29. "sim_fphys_jeep_armed2",
  30. }
  31.  
  32. return classes
  33. end
  34.  
  35. function simfphys.weapon:Initialize( vehicle )
  36. --vehicle:SetBodygroup(1,1)
  37.  
  38. local ID = vehicle:LookupAttachment( "gun_ref" )
  39. local attachmentdata = vehicle:GetAttachment( ID )
  40.  
  41. local prop = ents.Create( "gmod_sent_vehicle_fphysics_attachment" )
  42. prop:SetModel( "models/airboatgun.mdl" )
  43. prop:SetPos( attachmentdata.Pos )
  44. prop:SetAngles( attachmentdata.Ang )
  45. prop:SetModelScale( 0.5 )
  46. prop:SetOwner( self )
  47. prop:Spawn()
  48. prop:Activate()
  49. prop:SetNotSolid( true )
  50. prop:SetParent( vehicle, ID )
  51. prop.DoNotDuplicate = true
  52.  
  53. local pod = vehicle:GetDriverSeat()
  54.  
  55. simfphys.RegisterCrosshair( pod )
  56. end
  57.  
  58. function simfphys.weapon:AimWeapon( ply, vehicle, pod )
  59. local Aimang = ply:EyeAngles()
  60.  
  61. local Angles = vehicle:WorldToLocalAngles( Aimang ) - Angle(0,90,0)
  62. Angles:Normalize()
  63.  
  64. local Rate = 3
  65.  
  66. vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and (vehicle.sm_pp_yaw + math.Clamp(Angles.y - vehicle.sm_pp_yaw,-Rate,Rate) ) or 0
  67. vehicle.sm_pp_pitch = vehicle.sm_pp_pitch and ( vehicle.sm_pp_pitch + math.Clamp(Angles.p - vehicle.sm_pp_pitch,-Rate,Rate) ) or 0
  68.  
  69. vehicle:SetPoseParameter("vehicle_weapon_yaw", -vehicle.sm_pp_yaw )
  70. vehicle:SetPoseParameter("vehicle_weapon_pitch", -vehicle.sm_pp_pitch )
  71. end
  72.  
  73. function simfphys.weapon:Think( vehicle )
  74. local pod = vehicle:GetDriverSeat()
  75. if not IsValid( pod ) then return end
  76.  
  77. local ply = pod:GetDriver()
  78.  
  79. local curtime = CurTime()
  80.  
  81. if not IsValid( ply ) then
  82. if vehicle.wpn then
  83. vehicle.wpn:Stop()
  84. vehicle.wpn = nil
  85. end
  86.  
  87. return
  88. end
  89.  
  90. local ID = vehicle:LookupAttachment( "muzzle" )
  91. local Attachment = vehicle:GetAttachment( ID )
  92.  
  93. self:AimWeapon( ply, vehicle, pod )
  94.  
  95. vehicle.wOldPos = vehicle.wOldPos or Vector(0,0,0)
  96. local deltapos = vehicle:GetPos() - vehicle.wOldPos
  97. vehicle.wOldPos = vehicle:GetPos()
  98.  
  99. local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
  100.  
  101. vehicle.charge = vehicle.charge or 100
  102.  
  103. local fire = ply:KeyDown( IN_ATTACK ) and vehicle.charge > 0
  104.  
  105. if fire then
  106. self:PrimaryAttack( vehicle, ply, shootOrigin, Attachment, ID )
  107. else
  108. vehicle.charge = math.min(vehicle.charge + 0.3,100)
  109. end
  110.  
  111. vehicle.OldFire = vehicle.OldFire or false
  112. if vehicle.OldFire ~= fire then
  113. vehicle.OldFire = fire
  114. if fire then
  115. vehicle.wpn = CreateSound( vehicle, "weapons/airboat/airboat_gun_loop2.wav" )
  116. vehicle.wpn:Play()
  117. vehicle:CallOnRemove( "stopmesounds", function( vehicle )
  118. if vehicle.wpn then
  119. vehicle.wpn:Stop()
  120. end
  121. end)
  122. else
  123. if vehicle.wpn then
  124. vehicle.wpn:Stop()
  125. vehicle.wpn = nil
  126. end
  127.  
  128. vehicle:EmitSound("weapons/airboat/airboat_gun_lastshot"..math.random(1,2)..".wav")
  129. end
  130. end
  131. end
  132.  
  133. function simfphys.weapon:CanPrimaryAttack( vehicle )
  134. vehicle.NextShoot = vehicle.NextShoot or 0
  135. return vehicle.NextShoot < CurTime()
  136. end
  137.  
  138. function simfphys.weapon:SetNextPrimaryFire( vehicle, time )
  139. vehicle.NextShoot = time
  140. end
  141.  
  142. function simfphys.weapon:PrimaryAttack( vehicle, ply, shootOrigin, Attachment, ID )
  143. if not self:CanPrimaryAttack( vehicle ) then return end
  144.  
  145. local effectdata = EffectData()
  146. effectdata:SetOrigin( shootOrigin )
  147. effectdata:SetAngles( Attachment.Ang )
  148. effectdata:SetEntity( vehicle )
  149. effectdata:SetAttachment( ID )
  150. effectdata:SetScale( 1 )
  151. util.Effect( "AirboatMuzzleFlash", effectdata, true, true )
  152.  
  153. AirboatFire(ply,vehicle,shootOrigin,Attachment,(vehicle.charge / 5))
  154.  
  155. vehicle.charge = vehicle.charge - 0.5
  156.  
  157. if vehicle.charge <= 0 then
  158. if vehicle.charge > -1 then
  159. vehicle:EmitSound("weapons/airboat/airboat_gun_energy"..math.Round(math.random(1,2),0)..".wav")
  160. end
  161. vehicle.charge = -50
  162. end
  163.  
  164. self:SetNextPrimaryFire( vehicle, CurTime() + 0.05 )
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement