Advertisement
Guest User

Untitled

a guest
May 28th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.27 KB | None | 0 0
  1. if ( SERVER ) then
  2.  
  3. AddCSLuaFile( "shared.lua" )
  4. SWEP.HoldType = "melee2"
  5.  
  6. end
  7.  
  8. if ( CLIENT ) then
  9.  
  10. SWEP.PrintName = "Le Baguette" --weapon name
  11. SWEP.Author = "Gidz.Co"
  12. SWEP.Category = "Gidz.Co"
  13. SWEP.DrawAmmo = false
  14.  
  15. end
  16.  
  17.  
  18. SWEP.Base = "weapon_base"
  19.  
  20. SWEP.Spawnable = true
  21. SWEP.AdminSpawnable = true
  22.  
  23. SWEP.ViewModel = "models/weapons/gidzco/bagette/v_bagette.mdl" --replace this with the shit you want
  24. SWEP.WorldModel = "models/weapons/gidzco/bagette/w_bagette.mdl" --same with this
  25. SWEP.DrawCrosshair = true
  26.  
  27.  
  28. function SWEP:Initialize() --idk why this is here but ok sure
  29.  
  30. self:SetWeaponHoldType( "melee2" )
  31.  
  32. end
  33.  
  34.  
  35. function SWEP:Precache() --sounds
  36. util.PrecacheSound("weapons/gidzco/baguette/melee_tonfa_01")
  37. util.PrecacheSound("weapons/gidzco/baguette/melee_tonfa_02")
  38. util.PrecacheSound("weapons/gidzco/hl2_slash1.wav")
  39. end
  40.  
  41.  
  42. -------------Primary Fire Attributes----------------------------------------
  43. SWEP.Primary.Delay = 0.5
  44. SWEP.Primary.Recoil = 0
  45. SWEP.Primary.Damage = 5
  46. SWEP.Primary.NumShots = 1
  47. SWEP.Primary.Cone = 0
  48. SWEP.Primary.ClipSize = -1
  49. SWEP.Primary.DefaultClip = -1
  50. SWEP.Primary.Automatic = true
  51. SWEP.Primary.Ammo = "none"
  52. -------------End Primary Fire Attributes------------------------------------
  53.  
  54. -------------Secondary Fire Attributes-------------------------------------
  55. SWEP.Secondary.Delay = 1.2
  56. SWEP.Secondary.Recoil = 0
  57. SWEP.Secondary.Damage = 0
  58. SWEP.Secondary.NumShots = 1
  59. SWEP.Secondary.Cone = 0
  60. SWEP.Secondary.ClipSize = -1
  61. SWEP.Secondary.DefaultClip = -1
  62. SWEP.Secondary.Automatic = true
  63. SWEP.Secondary.Ammo = "none"
  64. -------------End Secondary Fire Attributes--------------------------------
  65. -- only open things that have a name (and are therefore likely to be meant to
  66. -- open) and are the right class. Opening behaviour also differs per class, so
  67. -- return one of the OPEN_ values
  68. local function OpenableEnt(ent)
  69. local cls = ent:GetClass()
  70. if ent:GetName() == "" then
  71. return OPEN_NO
  72. elseif cls == "prop_door_rotating" then
  73. return OPEN_ROT
  74. elseif cls == "func_door" or cls == "func_door_rotating" then
  75. return OPEN_DOOR
  76. elseif cls == "func_button" then
  77. return OPEN_BUT
  78. elseif cls == "func_movelinear" then
  79. return OPEN_NOTOGGLE
  80. else
  81. return OPEN_NO
  82. end
  83. end
  84.  
  85.  
  86. local function CrowbarCanUnlock(t)
  87. return not GAMEMODE.crowbar_unlocks or GAMEMODE.crowbar_unlocks[t]
  88. end
  89.  
  90. -- will open door AND return what it did
  91. function SWEP:OpenEnt(hitEnt)
  92. -- Get ready for some prototype-quality code, all ye who read this
  93. if SERVER then
  94. local openable = OpenableEnt(hitEnt)
  95.  
  96. if openable == OPEN_DOOR or openable == OPEN_ROT then
  97. local unlock = CrowbarCanUnlock(openable)
  98. if unlock then
  99. hitEnt:Fire("Unlock", nil, 0)
  100. end
  101.  
  102. if unlock or hitEnt:HasSpawnFlags(256) then
  103. if openable == OPEN_ROT then
  104. hitEnt:Fire("OpenAwayFrom", self.Owner, 0)
  105. end
  106. hitEnt:Fire("Toggle", nil, 0)
  107. else
  108. return OPEN_NO
  109. end
  110. elseif openable == OPEN_BUT then
  111. if CrowbarCanUnlock(openable) then
  112. hitEnt:Fire("Unlock", nil, 0)
  113. hitEnt:Fire("Press", nil, 0)
  114. else
  115. return OPEN_NO
  116. end
  117. elseif openable == OPEN_NOTOGGLE then
  118. if CrowbarCanUnlock(openable) then
  119. hitEnt:Fire("Open", nil, 0)
  120. else
  121. return OPEN_NO
  122. end
  123. end
  124. return openable
  125. else
  126. return OPEN_NO
  127. end
  128. end
  129.  
  130. function SWEP:PrimaryAttack()
  131. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  132.  
  133. if not IsValid(self.Owner) then return end
  134.  
  135. if self.Owner.LagCompensation then -- for some reason not always true
  136. self.Owner:LagCompensation(true)
  137. end
  138.  
  139. local spos = self.Owner:GetShootPos()
  140. local sdest = spos + (self.Owner:GetAimVector() * 70)
  141.  
  142. local tr_main = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL})
  143. local hitEnt = tr_main.Entity
  144.  
  145. self.Weapon:EmitSound(sound_single)
  146.  
  147. if IsValid(hitEnt) or tr_main.HitWorld then
  148. self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  149.  
  150. if not (CLIENT and (not IsFirstTimePredicted())) then
  151. local edata = EffectData()
  152. edata:SetStart(spos)
  153. edata:SetOrigin(tr_main.HitPos)
  154. edata:SetNormal(tr_main.Normal)
  155.  
  156. --edata:SetSurfaceProp(tr_main.MatType)
  157. --edata:SetDamageType(DMG_CLUB)
  158. edata:SetEntity(hitEnt)
  159.  
  160. if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then
  161. util.Effect("BloodImpact", edata)
  162.  
  163. -- does not work on players rah
  164. --util.Decal("Blood", tr_main.HitPos + tr_main.HitNormal, tr_main.HitPos - tr_main.HitNormal)
  165.  
  166. -- do a bullet just to make blood decals work sanely
  167. -- need to disable lagcomp because firebullets does its own
  168. self.Owner:LagCompensation(false)
  169. self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=0})
  170. else
  171. util.Effect("Impact", edata)
  172. end
  173. end
  174. else
  175. self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
  176. end
  177.  
  178.  
  179. if CLIENT then
  180. -- used to be some shit here
  181. else -- SERVER
  182.  
  183. -- Do another trace that sees nodraw stuff like func_button
  184. local tr_all = nil
  185. tr_all = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner})
  186.  
  187. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  188.  
  189. if hitEnt and hitEnt:IsValid() then
  190. if self:OpenEnt(hitEnt) == OPEN_NO and tr_all.Entity and tr_all.Entity:IsValid() then
  191. -- See if there's a nodraw thing we should open
  192. self:OpenEnt(tr_all.Entity)
  193. end
  194.  
  195. local dmg = DamageInfo()
  196. dmg:SetDamage(self.Primary.Damage)
  197. dmg:SetAttacker(self.Owner)
  198. dmg:SetInflictor(self.Weapon)
  199. dmg:SetDamageForce(self.Owner:GetAimVector() * 1500)
  200. dmg:SetDamagePosition(self.Owner:GetPos())
  201. dmg:SetDamageType(DMG_CLUB)
  202.  
  203. hitEnt:DispatchTraceAttack(dmg, spos + (self.Owner:GetAimVector() * 3), sdest)
  204.  
  205. -- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  206.  
  207. -- self.Owner:TraceHullAttack(spos, sdest, Vector(-16,-16,-16), Vector(16,16,16), 30, DMG_CLUB, 11, true)
  208. -- self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=20})
  209.  
  210. else
  211. -- if tr_main.HitWorld then
  212. -- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  213. -- else
  214. -- self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
  215. -- end
  216.  
  217. -- See if our nodraw trace got the goods
  218. if tr_all.Entity and tr_all.Entity:IsValid() then
  219. self:OpenEnt(tr_all.Entity)
  220. end
  221. end
  222. end
  223.  
  224. if self.Owner.LagCompensation then
  225. self.Owner:LagCompensation(false)
  226. end
  227. end
  228.  
  229. function SWEP:GetClass()
  230. return "weapon_crowbar"
  231. end
  232.  
  233. function SWEP:OnDrop()
  234. self:Remove()
  235. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement