Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. SWEP.HoldType = "melee"
  4.  
  5. if CLIENT then
  6. SWEP.PrintName = "Light Saber"
  7.  
  8. SWEP.Slot = 0
  9.  
  10. SWEP.Icon = "vgui/ttt/icon_cbar"
  11. SWEP.ViewModelFOV = 54
  12. end
  13.  
  14. SWEP.UseHands = true
  15. SWEP.Base = "weapon_tttbase"
  16. SWEP.ViewModel = "models/weapons/v_crewbar.mdl"
  17. SWEP.WorldModel = "models/weapons/v_crewbar.mdl"
  18. SWEP.Weight = 5
  19. SWEP.DrawCrosshair = false
  20. SWEP.ViewModelFlip = false
  21. SWEP.Primary.Damage = 20
  22. SWEP.Primary.ClipSize = -1
  23. SWEP.Primary.DefaultClip = -1
  24. SWEP.Primary.Automatic = true
  25. SWEP.Primary.Delay = 0.5
  26. SWEP.Primary.Ammo = "none"
  27. SWEP.Secondary.ClipSize = -1
  28. SWEP.Secondary.DefaultClip = -1
  29. SWEP.Secondary.Automatic = true
  30. SWEP.Secondary.Ammo = "none"
  31. SWEP.Secondary.Delay = 5
  32.  
  33. SWEP.Kind = WEAPON_MELEE
  34. SWEP.WeaponID = AMMO_CROWBAR
  35.  
  36. SWEP.InLoadoutFor = { nil }
  37.  
  38. SWEP.NoSights = true
  39. SWEP.IsSilent = true
  40.  
  41. SWEP.AutoSpawnable = false
  42.  
  43. SWEP.AllowDelete = false -- never removed for weapon reduction
  44. SWEP.AllowDrop = false
  45.  
  46. local sound_single = Sound("Weapon_Crowbar.Single")
  47. local sound_open = Sound("DoorHandles.Unlocked3")
  48.  
  49. if SERVER then
  50. CreateConVar("ttt_crowbar_unlocks", "1", FCVAR_ARCHIVE)
  51. CreateConVar("ttt_crowbar_pushforce", "395", FCVAR_NOTIFY)
  52. end
  53.  
  54. -- only open things that have a name (and are therefore likely to be meant to
  55. -- open) and are the right class. Opening behaviour also differs per class, so
  56. -- return one of the OPEN_ values
  57. local function OpenableEnt(ent)
  58. local cls = ent:GetClass()
  59. if ent:GetName() == "" then
  60. return OPEN_NO
  61. elseif cls == "prop_door_rotating" then
  62. return OPEN_ROT
  63. elseif cls == "func_door" or cls == "func_door_rotating" then
  64. return OPEN_DOOR
  65. elseif cls == "func_button" then
  66. return OPEN_BUT
  67. elseif cls == "func_movelinear" then
  68. return OPEN_NOTOGGLE
  69. else
  70. return OPEN_NO
  71. end
  72. end
  73.  
  74.  
  75. local function CrowbarCanUnlock(t)
  76. return not GAMEMODE.crowbar_unlocks or GAMEMODE.crowbar_unlocks[t]
  77. end
  78.  
  79. -- will open door AND return what it did
  80. function SWEP:OpenEnt(hitEnt)
  81. -- Get ready for some prototype-quality code, all ye who read this
  82. if SERVER and GetConVar("ttt_crowbar_unlocks"):GetBool() then
  83. local openable = OpenableEnt(hitEnt)
  84.  
  85. if openable == OPEN_DOOR or openable == OPEN_ROT then
  86. local unlock = CrowbarCanUnlock(openable)
  87. if unlock then
  88. hitEnt:Fire("Unlock", nil, 0)
  89. end
  90.  
  91. if unlock or hitEnt:HasSpawnFlags(256) then
  92. if openable == OPEN_ROT then
  93. hitEnt:Fire("OpenAwayFrom", self.Owner, 0)
  94. end
  95. hitEnt:Fire("Toggle", nil, 0)
  96. else
  97. return OPEN_NO
  98. end
  99. elseif openable == OPEN_BUT then
  100. if CrowbarCanUnlock(openable) then
  101. hitEnt:Fire("Unlock", nil, 0)
  102. hitEnt:Fire("Press", nil, 0)
  103. else
  104. return OPEN_NO
  105. end
  106. elseif openable == OPEN_NOTOGGLE then
  107. if CrowbarCanUnlock(openable) then
  108. hitEnt:Fire("Open", nil, 0)
  109. else
  110. return OPEN_NO
  111. end
  112. end
  113. return openable
  114. else
  115. return OPEN_NO
  116. end
  117. end
  118.  
  119. function SWEP:PrimaryAttack()
  120. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  121.  
  122. if not IsValid(self.Owner) then return end
  123.  
  124. if self.Owner.LagCompensation then -- for some reason not always true
  125. self.Owner:LagCompensation(true)
  126. end
  127.  
  128. local spos = self.Owner:GetShootPos()
  129. local sdest = spos + (self.Owner:GetAimVector() * 70)
  130.  
  131. local tr_main = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL})
  132. local hitEnt = tr_main.Entity
  133.  
  134. self.Weapon:EmitSound("weapons/ls/lightsaber_swing.wav")
  135.  
  136. if IsValid(hitEnt) or tr_main.HitWorld then
  137. self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  138.  
  139. if not (CLIENT and (not IsFirstTimePredicted())) then
  140. local edata = EffectData()
  141. edata:SetStart(spos)
  142. edata:SetOrigin(tr_main.HitPos)
  143. edata:SetNormal(tr_main.Normal)
  144.  
  145. --edata:SetSurfaceProp(tr_main.MatType)
  146. --edata:SetDamageType(DMG_CLUB)
  147. edata:SetEntity(hitEnt)
  148.  
  149. if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then
  150. util.Effect("BloodImpact", edata)
  151.  
  152. -- does not work on players rah
  153. --util.Decal("Blood", tr_main.HitPos + tr_main.HitNormal, tr_main.HitPos - tr_main.HitNormal)
  154.  
  155. -- do a bullet just to make blood decals work sanely
  156. -- need to disable lagcomp because firebullets does its own
  157. self.Owner:LagCompensation(false)
  158. self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=0})
  159. else
  160. util.Effect("Impact", edata)
  161. end
  162. end
  163. else
  164. self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
  165. end
  166.  
  167.  
  168. if CLIENT then
  169. -- used to be some shit here
  170. else -- SERVER
  171.  
  172. -- Do another trace that sees nodraw stuff like func_button
  173. local tr_all = nil
  174. tr_all = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner})
  175.  
  176. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  177.  
  178. if hitEnt and hitEnt:IsValid() then
  179. if self:OpenEnt(hitEnt) == OPEN_NO and tr_all.Entity and tr_all.Entity:IsValid() then
  180. -- See if there's a nodraw thing we should open
  181. self:OpenEnt(tr_all.Entity)
  182. end
  183.  
  184. local dmg = DamageInfo()
  185. dmg:SetDamage(self.Primary.Damage)
  186. dmg:SetAttacker(self.Owner)
  187. dmg:SetInflictor(self.Weapon)
  188. dmg:SetDamageForce(self.Owner:GetAimVector() * 1500)
  189. dmg:SetDamagePosition(self.Owner:GetPos())
  190. dmg:SetDamageType(DMG_CLUB)
  191.  
  192. hitEnt:DispatchTraceAttack(dmg, spos + (self.Owner:GetAimVector() * 3), sdest)
  193.  
  194. -- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  195.  
  196. -- self.Owner:TraceHullAttack(spos, sdest, Vector(-16,-16,-16), Vector(16,16,16), 30, DMG_CLUB, 11, true)
  197. -- self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=20})
  198.  
  199. else
  200. -- if tr_main.HitWorld then
  201. -- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  202. -- else
  203. -- self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
  204. -- end
  205.  
  206. -- See if our nodraw trace got the goods
  207. if tr_all.Entity and tr_all.Entity:IsValid() then
  208. self:OpenEnt(tr_all.Entity)
  209. end
  210. end
  211. end
  212.  
  213. if self.Owner.LagCompensation then
  214. self.Owner:LagCompensation(false)
  215. end
  216. end
  217.  
  218. function SWEP:SecondaryAttack()
  219. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  220. self.Weapon:SetNextSecondaryFire( CurTime() + 0.1 )
  221.  
  222. if self.Owner.LagCompensation then
  223. self.Owner:LagCompensation(true)
  224. end
  225.  
  226. local tr = self.Owner:GetEyeTrace(MASK_SHOT)
  227.  
  228. if tr.Hit and IsValid(tr.Entity) and tr.Entity:IsPlayer() and (self.Owner:EyePos() - tr.HitPos):Length() < 100 then
  229. local ply = tr.Entity
  230.  
  231. if SERVER and (not ply:IsFrozen()) then
  232. local pushvel = tr.Normal * GetConVar("ttt_crowbar_pushforce"):GetFloat()
  233.  
  234. -- limit the upward force to prevent launching
  235. pushvel.z = math.Clamp(pushvel.z, 50, 100)
  236.  
  237. ply:SetVelocity(ply:GetVelocity() + pushvel)
  238. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  239.  
  240. ply.was_pushed = {att=self.Owner, t=CurTime()} --, infl=self}
  241. end
  242.  
  243. self.Weapon:EmitSound(sound_single)
  244. self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
  245.  
  246. self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  247. end
  248.  
  249. if self.Owner.LagCompensation then
  250. self.Owner:LagCompensation(false)
  251. end
  252. end
  253.  
  254. function SWEP:GetClass()
  255. return "weapon_light_saber"
  256. end
  257.  
  258. function SWEP:OnDrop()
  259. self:Remove()
  260. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement