jay5476

Lifesteal gun

Dec 16th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. ---- Example TTT custom weapon
  2.  
  3. -- First some standard GMod stuff
  4. if SERVER then
  5. AddCSLuaFile( "shared.lua" )
  6. end
  7.  
  8. if CLIENT then
  9. SWEP.PrintName = "Life stealer"
  10. SWEP.Slot = 6 -- add 1 to get the slot number key
  11.  
  12. SWEP.ViewModelFOV = 72
  13. SWEP.ViewModelFlip = true
  14. end
  15.  
  16. -- Always derive from weapon_tttbase.
  17. SWEP.Base = "weapon_tttbase"
  18.  
  19. --- Standard GMod values
  20.  
  21. SWEP.HoldType = "pistol"
  22.  
  23. SWEP.Primary.Delay = 0.4
  24. SWEP.Primary.Recoil = 1
  25. SWEP.Primary.Automatic = false
  26. SWEP.Primary.Damage = 15
  27. SWEP.Primary.Cone = 0.01
  28. SWEP.Primary.Ammo = "pistol"
  29. SWEP.Primary.ClipSize = 5
  30. SWEP.Primary.ClipMax = 20
  31. SWEP.Primary.DefaultClip = 25
  32. SWEP.sound = "weapon_pistol.Single"
  33. --- TTT config values
  34.  
  35. -- Kind specifies the category this weapon is in. Players can only carry one of
  36. -- each. Can be: WEAPON_... MELEE, PISTOL, HEAVY, NADE, CARRY, EQUIP1, EQUIP2 or ROLE.
  37. -- Matching SWEP.Slot values: 0 1 2 3 4 6 7 8
  38. SWEP.Kind = WEAPON_EQUIP1
  39.  
  40. -- If AutoSpawnable is true and SWEP.Kind is not WEAPON_EQUIP1/2, then this gun can
  41. -- be spawned as a random weapon. Of course this AK is special equipment so it won't,
  42. -- but for the sake of example this is explicitly set to false anyway.
  43. SWEP.AutoSpawnable = false
  44.  
  45. -- The AmmoEnt is the ammo entity that can be picked up when carrying this gun.
  46. SWEP.AmmoEnt = "none"
  47.  
  48. -- CanBuy is a table of ROLE_* entries like ROLE_TRAITOR and ROLE_DETECTIVE. If
  49. -- a role is in this table, those players can buy this.
  50. SWEP.CanBuy = { ROLE_TRAITOR }
  51.  
  52. -- InLoadoutFor is a table of ROLE_* entries that specifies which roles should
  53. -- receive this weapon as soon as the round starts. In this case, none.
  54. SWEP.InLoadoutFor = nil
  55.  
  56. -- If LimitedStock is true, you can only buy one per round.
  57. SWEP.LimitedStock = true
  58.  
  59. -- If AllowDrop is false, players can't manually drop the gun with Q
  60. SWEP.AllowDrop = true
  61.  
  62. -- If IsSilent is true, victims will not scream upon death.
  63. SWEP.IsSilent = false
  64.  
  65. -- If NoSights is true, the weapon won't have ironsights
  66. SWEP.NoSights = true
  67.  
  68. -- Equipment menu information is only needed on the client
  69. if CLIENT then
  70. -- Text shown in the equip menu
  71. SWEP.EquipMenuData = {
  72. type = "Weapon",
  73. desc = "Shoot a bullet to inflict 15hp on target and regain 10hp to self"
  74. };
  75. end
  76.  
  77. function SWEP:PrimaryAttack()
  78. if ( !self:CanPrimaryAttack() ) then return end
  79.  
  80. local bullet = {}
  81. bullet.Num = 1
  82. bullet.Src = self.Owner:GetShootPos() // Source
  83. bullet.Dir = self.Owner:GetAimVector() // Dir of bullet
  84. bullet.Spread = Vector( self.Primary.Cone, self.Primary.Cone, 0 ) // Aim Cone
  85. bullet.Tracer = 0 // Show a tracer on every x bullets
  86. bullet.TracerName = tracer // what Tracer Effect should be used
  87. bullet.Force = 1 // Amount of force to give to phys objects
  88. bullet.Damage = self.Primary.Damage
  89. bullet.AmmoType = "Pistol"
  90.  
  91. self.Owner:FireBullets( bullet )
  92.  
  93. local trace = util.GetPlayerTrace( self.Owner )
  94. local traceRes = util.TraceLine( trace )
  95. self:EmitSound( self.sound )
  96.  
  97. if ( traceRes.HitNonWorld ) then
  98. if traceRes.Entity:IsPlayer() then
  99. if self.Owner:Health()+10 < 100 then
  100. self.Owner:SetHealth( self.Owner:Health() + 10 )
  101. else
  102. self.Owner:SetHealth( 100 )
  103. end
  104. end
  105. end
  106.  
  107. self:TakePrimaryAmmo(1)
  108. self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  109. self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
  110. end
Advertisement
Add Comment
Please, Sign In to add comment