Advertisement
Guest User

Untitled

a guest
Oct 9th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. SWEP.PrintName = "Chair Chucker"
  2. SWEP.Author = "(Codmodz)"
  3. SWEP.Instructions = "Left mouse to fire a chair!"
  4. SWEP.Category = "TMG_Modderz"
  5. SWEP.Spawnable = true
  6. SWEP.AdminOnly = true
  7. SWEP.Primary.ClipSize = -1
  8. SWEP.Primary.DefaultClip = -1
  9. SWEP.Primary.Automatic = true
  10. SWEP.Primary.Ammo = "none"
  11.  
  12. SWEP.Secondary.ClipSize = -1
  13. SWEP.Secondary.DefaultClip = -1
  14. SWEP.Secondary.Automatic = false
  15. SWEP.Secondary.Ammo = "none"
  16. SWEP.Weight = 5
  17. SWEP.AutoSwitchTo = false
  18. SWEP.AutoSwitchFrom = false
  19.  
  20. SWEP.Slot = 1
  21. SWEP.SlotPos = 2
  22. SWEP.DrawAmmo = false
  23. SWEP.DrawCrosshair = true
  24. SWEP.ViewModel = "models/weapons/v_pistol.mdl"
  25. SWEP.WorldModel = "models/weapons/w_pistol.mdl"
  26. local ShootSound = Sound( "Metal.SawbladeStick" )
  27. --
  28. -- Called when the left mouse button is pressed
  29. --
  30. function SWEP:PrimaryAttack()
  31.  
  32. -- This weapon is 'automatic'. This function call below defines
  33. -- the rate of fire. Here we set it to shoot every 0.5 seconds.
  34. self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
  35.  
  36. -- Call 'ThrowChair' on self with this model
  37. self:ThrowChair( "models/props/cs_office/Chair_office.mdl" )
  38.  
  39. end
  40.  
  41.  
  42. --
  43. -- Called when the rightmouse button is pressed
  44. --
  45. function SWEP:SecondaryAttack()
  46.  
  47. -- Note we don't call SetNextSecondaryFire here because it's not
  48. -- automatic and so we let them fire as fast as they can click.
  49.  
  50. -- Call 'ThrowChair' on self with this model
  51. self:ThrowChair( "models/props_c17/FurnitureChair001a.mdl" )
  52.  
  53. end
  54.  
  55. --
  56. -- A custom function we added. When you call this the player will fire a chair!
  57. --
  58. function SWEP:ThrowChair( model_file )
  59.  
  60. --
  61. -- Play the shoot sound we precached earlier!
  62. --
  63. self:EmitSound( ShootSound )
  64.  
  65.  
  66. --
  67. -- If we're the client ) then this is as much as we want to do.
  68. -- We play the sound above on the client due to prediction.
  69. -- ( if ( we didn't they would feel a ping delay during multiplayer )
  70. --
  71. if ( CLIENT ) then return end
  72.  
  73. --
  74. -- Create a prop_physics entity
  75. --
  76. local ent = ents.Create( "prop_physics" )
  77.  
  78. --
  79. -- Always make sure that created entities are actually created!
  80. --
  81. if ( !IsValid( ent ) ) then return end
  82.  
  83. --
  84. -- Set the entity's model to the passed in model
  85. --
  86. ent:SetModel( model_file )
  87.  
  88. --
  89. -- Set the position to the player's eye position plus 16 units forward.
  90. -- Set the angles to the player'e eye angles. Then spawn it.
  91. --
  92. ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
  93. ent:SetAngles( self.Owner:EyeAngles() )
  94. ent:Spawn()
  95.  
  96.  
  97. --
  98. -- Now get the physics object. Whenever we get a physics object
  99. -- we need to test to make sure its valid before using it.
  100. -- If it isn't ) then we'll remove the entity.
  101. --
  102. local phys = ent:GetPhysicsObject()
  103. if ( !IsValid( phys ) ) then ent:Remove() return end
  104.  
  105.  
  106. --
  107. -- Now we apply the force - so the chair actually throws instead
  108. -- of just falling to the ground. You can play with this value here
  109. -- to adjust how fast we throw it.
  110. --
  111. local velocity = self.Owner:GetAimVector()
  112. velocity = velocity * 100
  113. velocity = velocity + ( VectorRand() * 10 ) -- a random element
  114. phys:ApplyForceCenter( velocity )
  115.  
  116. --
  117. -- Assuming we're playing in Sandbox mode we want to add this
  118. -- entity to the cleanup and undo lists. This is done like so.
  119. --
  120. cleanup.Add( self.Owner, "props", ent )
  121.  
  122. undo.Create( "Thrown_Chair" )
  123. undo.AddEntity( ent )
  124. undo.SetPlayer( self.Owner )
  125. undo.Finish()
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement