Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.82 KB | None | 0 0
  1.  
  2. if SERVER then
  3. AddCSLuaFile( "shared.lua" )
  4. end
  5.  
  6. SWEP.HoldType = "shotgun"
  7.  
  8. if CLIENT then
  9.  
  10. SWEP.PrintName = "Torch"
  11. SWEP.Slot = 6
  12.  
  13. SWEP.ViewModelFlip = true
  14.  
  15. SWEP.EquipMenuData = {
  16. type = "item_weapon",
  17. desc = [[]]
  18. };
  19.  
  20.  
  21. SWEP.Icon = "vgui/ttt/icon_fire"
  22. end
  23.  
  24. SWEP.Base = "weapon_tttbase"
  25. SWEP.Spawnable = false
  26. SWEP.AdminSpawnable = true
  27.  
  28. SWEP.Kind = WEAPON_EQUIP
  29. SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
  30. SWEP.WeaponID = AMMO_SHOTGUN
  31.  
  32. SWEP.Primary.Ammo = "Buckshot"
  33. SWEP.Primary.Damage = 3
  34. SWEP.Primary.Cone = 0.15
  35. SWEP.Primary.Delay = 1.1
  36. SWEP.Primary.ClipSize = 4
  37. SWEP.Primary.ClipMax = 24
  38. SWEP.Primary.DefaultClip = 4
  39. SWEP.Primary.Automatic = true
  40. SWEP.Primary.NumShots = 12
  41. SWEP.AmmoEnt = "item_box_buckshot_ttt"
  42. SWEP.ViewModel = "models/weapons/v_shot_m3super90.mdl"
  43. SWEP.WorldModel = "models/weapons/w_shot_m3super90.mdl"
  44. SWEP.Primary.Recoil = 3
  45. SWEP.IronSightsPos = Vector( 5.6, -5, 2.14 )
  46. SWEP.IronSightsAng = Vector(0, 0.8, 0)
  47.  
  48. SWEP.Primary.Sound = Sound( "Weapon_M3.Single" )
  49.  
  50. SWEP.reloadtimer = 0
  51.  
  52. -- This is gonna give players some extra shotgun ammo when purchasing since it can be reloaded.
  53. function SWEP:WasBought(buyer)
  54. if IsValid(buyer) then
  55. buyer:GiveAmmo( 4, "Buckshot" )
  56. end
  57. end
  58.  
  59. function SWEP:SetupDataTables()
  60. self:DTVar("Bool", 0, "reloading")
  61.  
  62. return self.BaseClass.SetupDataTables(self)
  63. end
  64.  
  65. function SWEP:Reload()
  66. self:SetIronsights( false )
  67.  
  68. --if self.Weapon:GetNetworkedBool( "reloading", false ) then return end
  69. if self.dt.reloading then return end
  70.  
  71. if not IsFirstTimePredicted() then return end
  72.  
  73. if self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then
  74.  
  75. if self:StartReload() then
  76. return
  77. end
  78. end
  79.  
  80. end
  81.  
  82. function SWEP:StartReload()
  83. --if self.Weapon:GetNWBool( "reloading", false ) then
  84. if self.dt.reloading then
  85. return false
  86. end
  87.  
  88. if not IsFirstTimePredicted() then return false end
  89.  
  90. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  91.  
  92. local ply = self.Owner
  93.  
  94. if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then
  95. return false
  96. end
  97.  
  98. local wep = self.Weapon
  99.  
  100. if wep:Clip1() >= self.Primary.ClipSize then
  101. return false
  102. end
  103.  
  104. wep:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
  105.  
  106. self.reloadtimer = CurTime() + wep:SequenceDuration()
  107.  
  108. --wep:SetNWBool("reloading", true)
  109. self.dt.reloading = true
  110.  
  111. return true
  112. end
  113.  
  114. function SWEP:PerformReload()
  115. local ply = self.Owner
  116.  
  117. -- prevent normal shooting in between reloads
  118. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  119.  
  120. if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then return end
  121.  
  122. local wep = self.Weapon
  123.  
  124. if wep:Clip1() >= self.Primary.ClipSize then return end
  125.  
  126. self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
  127. self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
  128.  
  129. wep:SendWeaponAnim(ACT_VM_RELOAD)
  130.  
  131. self.reloadtimer = CurTime() + wep:SequenceDuration()
  132. end
  133.  
  134. function SWEP:FinishReload()
  135. self.dt.reloading = false
  136. self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)
  137.  
  138. self.reloadtimer = CurTime() + self.Weapon:SequenceDuration()
  139. end
  140.  
  141. function SWEP:CanPrimaryAttack()
  142. if self.Weapon:Clip1() <= 0 then
  143. self:EmitSound( "Weapon_Shotgun.Empty" )
  144. self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  145. return false
  146. end
  147. return true
  148. end
  149.  
  150. function SWEP:Think()
  151. if self.dt.reloading and IsFirstTimePredicted() then
  152. if self.Owner:KeyDown(IN_ATTACK) then
  153. self:FinishReload()
  154. return
  155. end
  156.  
  157. if self.reloadtimer <= CurTime() then
  158.  
  159. if self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
  160. self:FinishReload()
  161. elseif self.Weapon:Clip1() < self.Primary.ClipSize then
  162. self:PerformReload()
  163. else
  164. self:FinishReload()
  165. end
  166. return
  167. end
  168. end
  169. end
  170.  
  171. function SWEP:Deploy()
  172. self.dt.reloading = false
  173. self.reloadtimer = 0
  174. return self.BaseClass.Deploy(self)
  175. end
  176.  
  177.  
  178. local function RunIgniteTimer(ent, timer_name)
  179. if IsValid(ent) and ent:IsOnFire() then
  180. if ent:WaterLevel() > 0.2 then
  181. ent:Extinguish()
  182. elseif CurTime() > ent.burn_destroy then
  183. ent:SetNotSolid(true)
  184. ent:Remove()
  185. else
  186. -- keep on burning
  187. return
  188. end
  189. end
  190.  
  191. timer.Destroy(timer_name) -- stop running timer
  192. end
  193.  
  194. local SendScorches
  195.  
  196. if CLIENT then
  197. local function ReceiveScorches(um)
  198. local ent = um:ReadEntity()
  199. local num = um:ReadChar()
  200. for i=1, num do
  201. util.PaintDown(um:ReadVector(), "FadingScorch", ent)
  202. end
  203.  
  204. if IsValid(ent) then
  205. util.PaintDown(ent:LocalToWorld(ent:OBBCenter()), "Scorch", ent)
  206. end
  207. end
  208. usermessage.Hook("flare_scorch", ReceiveScorches)
  209. else
  210. -- it's sad that decals are so unreliable when drawn serverside, failing to
  211. -- draw more often than they work, that I have to do this
  212. SendScorches = function(ent, tbl)
  213. umsg.Start("flare_scorch")
  214. umsg.Entity(ent)
  215. umsg.Char(#tbl)
  216. for _, p in pairs(tbl) do
  217. umsg.Vector(p)
  218. end
  219. umsg.End()
  220. end
  221. usermessage.Hook("flare_scorch") -- pools it
  222. end
  223.  
  224.  
  225. local function ScorchUnderRagdoll(ent)
  226. if SERVER then
  227. local postbl = {}
  228. -- small scorches under limbs
  229. for i=0, ent:GetPhysicsObjectCount()-1 do
  230. local subphys = ent:GetPhysicsObjectNum(i)
  231. if IsValid(subphys) then
  232. local pos = subphys:GetPos()
  233. util.PaintDown(pos, "FadingScorch", ent)
  234.  
  235. table.insert(postbl, pos)
  236. end
  237. end
  238.  
  239. SendScorches(ent, postbl)
  240. end
  241.  
  242. -- big scorch at center
  243. local mid = ent:LocalToWorld(ent:OBBCenter())
  244. mid.z = mid.z + 25
  245. util.PaintDown(mid, "Scorch", ent)
  246. end
  247.  
  248.  
  249. function IgniteTarget(att, path, dmginfo)
  250. local ent = path.Entity
  251. if not IsValid(ent) then return end
  252.  
  253. if CLIENT and IsFirstTimePredicted() then
  254. if ent:GetClass() == "prop_ragdoll" then
  255. ScorchUnderRagdoll(ent)
  256. end
  257. return
  258. end
  259.  
  260. if SERVER then
  261.  
  262. local dur = ent:IsPlayer() and 5 or 10
  263.  
  264. -- disallow if prep or post round
  265. if ent:IsPlayer() and (not GAMEMODE:AllowPVP()) then return end
  266.  
  267. ent:Ignite(dur, 100)
  268.  
  269. ent.ignite_info = {att=dmginfo:GetAttacker(), infl=dmginfo:GetInflictor()}
  270.  
  271. if ent:IsPlayer() then
  272. timer.Simple(dur + 0.1, function()
  273. if IsValid(ent) then
  274. ent.ignite_info = nil
  275. end
  276. end)
  277.  
  278. elseif ent:GetClass() == "prop_ragdoll" then
  279. ScorchUnderRagdoll(ent)
  280.  
  281. local burn_time = 7.5
  282. local tname = Format("ragburn_%d_%d", ent:EntIndex(), math.ceil(CurTime()))
  283.  
  284. ent.burn_destroy = CurTime() + burn_time
  285.  
  286. timer.Create(tname,
  287. 0.1,
  288. math.ceil(1 + burn_time / 0.1), -- upper limit, failsafe
  289. function()
  290. RunIgniteTimer(ent, tname)
  291. end)
  292. end
  293. end
  294. end
  295.  
  296. function SWEP:ShootFlare()
  297. local cone = self.Primary.Cone
  298. local bullet = {}
  299. bullet.Num = 12
  300. bullet.Src = self.Owner:GetShootPos()
  301. bullet.Dir = self.Owner:GetAimVector()
  302. bullet.Spread = Vector( cone, cone, 0 )
  303. bullet.Tracer = 1
  304. bullet.Force = 2
  305. bullet.Damage = self.Primary.Damage * 1.75
  306. bullet.TracerName = self.Tracer
  307. bullet.Callback = IgniteTarget
  308.  
  309. self.Owner:FireBullets( bullet )
  310. end
  311.  
  312. function SWEP:PrimaryAttack()
  313. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  314.  
  315. if not self:CanPrimaryAttack() then return end
  316.  
  317. self.Weapon:EmitSound( self.Primary.Sound )
  318.  
  319. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  320.  
  321. self:ShootFlare()
  322.  
  323. self:TakePrimaryAmmo( 1 )
  324.  
  325. if IsValid(self.Owner) then
  326. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  327.  
  328. self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
  329. end
  330.  
  331. if ( (game.SinglePlayer() && SERVER) || CLIENT ) then
  332. self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
  333. end
  334. end
  335.  
  336. function SWEP:GetHeadshotMultiplier(victim, dmginfo)
  337. local att = dmginfo:GetAttacker()
  338. if not IsValid(att) then return 3 end
  339.  
  340. local dist = victim:GetPos():Distance(att:GetPos())
  341. local d = math.max(0, dist - 140)
  342.  
  343. -- decay from 3.1 to 1 slowly as distance increases
  344. return 1 + math.max(0, (2.1 - 0.002 * (d ^ 1.25)))
  345. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement