Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- AddCSLuaFile( "shared.lua" )
- end
- SWEP.HoldType = "shotgun"
- if CLIENT then
- SWEP.PrintName = "Torch"
- SWEP.Slot = 6
- SWEP.ViewModelFlip = true
- SWEP.EquipMenuData = {
- type = "item_weapon",
- desc = [[]]
- };
- SWEP.Icon = "vgui/ttt/icon_fire"
- end
- SWEP.Base = "weapon_tttbase"
- SWEP.Spawnable = false
- SWEP.AdminSpawnable = true
- SWEP.Kind = WEAPON_EQUIP
- SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
- SWEP.WeaponID = AMMO_SHOTGUN
- SWEP.Primary.Ammo = "Buckshot"
- SWEP.Primary.Damage = 3
- SWEP.Primary.Cone = 0.15
- SWEP.Primary.Delay = 1.1
- SWEP.Primary.ClipSize = 4
- SWEP.Primary.ClipMax = 24
- SWEP.Primary.DefaultClip = 4
- SWEP.Primary.Automatic = true
- SWEP.Primary.NumShots = 12
- SWEP.AmmoEnt = "item_box_buckshot_ttt"
- SWEP.ViewModel = "models/weapons/v_shot_m3super90.mdl"
- SWEP.WorldModel = "models/weapons/w_shot_m3super90.mdl"
- SWEP.Primary.Recoil = 3
- SWEP.IronSightsPos = Vector( 5.6, -5, 2.14 )
- SWEP.IronSightsAng = Vector(0, 0.8, 0)
- SWEP.Primary.Sound = Sound( "Weapon_M3.Single" )
- SWEP.reloadtimer = 0
- -- This is gonna give players some extra shotgun ammo when purchasing since it can be reloaded.
- function SWEP:WasBought(buyer)
- if IsValid(buyer) then
- buyer:GiveAmmo( 4, "Buckshot" )
- end
- end
- function SWEP:SetupDataTables()
- self:DTVar("Bool", 0, "reloading")
- return self.BaseClass.SetupDataTables(self)
- end
- function SWEP:Reload()
- self:SetIronsights( false )
- --if self.Weapon:GetNetworkedBool( "reloading", false ) then return end
- if self.dt.reloading then return end
- if not IsFirstTimePredicted() then return end
- if self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then
- if self:StartReload() then
- return
- end
- end
- end
- function SWEP:StartReload()
- --if self.Weapon:GetNWBool( "reloading", false ) then
- if self.dt.reloading then
- return false
- end
- if not IsFirstTimePredicted() then return false end
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- local ply = self.Owner
- if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then
- return false
- end
- local wep = self.Weapon
- if wep:Clip1() >= self.Primary.ClipSize then
- return false
- end
- wep:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
- self.reloadtimer = CurTime() + wep:SequenceDuration()
- --wep:SetNWBool("reloading", true)
- self.dt.reloading = true
- return true
- end
- function SWEP:PerformReload()
- local ply = self.Owner
- -- prevent normal shooting in between reloads
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then return end
- local wep = self.Weapon
- if wep:Clip1() >= self.Primary.ClipSize then return end
- self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
- self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
- wep:SendWeaponAnim(ACT_VM_RELOAD)
- self.reloadtimer = CurTime() + wep:SequenceDuration()
- end
- function SWEP:FinishReload()
- self.dt.reloading = false
- self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)
- self.reloadtimer = CurTime() + self.Weapon:SequenceDuration()
- end
- function SWEP:CanPrimaryAttack()
- if self.Weapon:Clip1() <= 0 then
- self:EmitSound( "Weapon_Shotgun.Empty" )
- self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- return false
- end
- return true
- end
- function SWEP:Think()
- if self.dt.reloading and IsFirstTimePredicted() then
- if self.Owner:KeyDown(IN_ATTACK) then
- self:FinishReload()
- return
- end
- if self.reloadtimer <= CurTime() then
- if self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
- self:FinishReload()
- elseif self.Weapon:Clip1() < self.Primary.ClipSize then
- self:PerformReload()
- else
- self:FinishReload()
- end
- return
- end
- end
- end
- function SWEP:Deploy()
- self.dt.reloading = false
- self.reloadtimer = 0
- return self.BaseClass.Deploy(self)
- end
- local function RunIgniteTimer(ent, timer_name)
- if IsValid(ent) and ent:IsOnFire() then
- if ent:WaterLevel() > 0.2 then
- ent:Extinguish()
- elseif CurTime() > ent.burn_destroy then
- ent:SetNotSolid(true)
- ent:Remove()
- else
- -- keep on burning
- return
- end
- end
- timer.Destroy(timer_name) -- stop running timer
- end
- local SendScorches
- if CLIENT then
- local function ReceiveScorches(um)
- local ent = um:ReadEntity()
- local num = um:ReadChar()
- for i=1, num do
- util.PaintDown(um:ReadVector(), "FadingScorch", ent)
- end
- if IsValid(ent) then
- util.PaintDown(ent:LocalToWorld(ent:OBBCenter()), "Scorch", ent)
- end
- end
- usermessage.Hook("flare_scorch", ReceiveScorches)
- else
- -- it's sad that decals are so unreliable when drawn serverside, failing to
- -- draw more often than they work, that I have to do this
- SendScorches = function(ent, tbl)
- umsg.Start("flare_scorch")
- umsg.Entity(ent)
- umsg.Char(#tbl)
- for _, p in pairs(tbl) do
- umsg.Vector(p)
- end
- umsg.End()
- end
- usermessage.Hook("flare_scorch") -- pools it
- end
- local function ScorchUnderRagdoll(ent)
- if SERVER then
- local postbl = {}
- -- small scorches under limbs
- for i=0, ent:GetPhysicsObjectCount()-1 do
- local subphys = ent:GetPhysicsObjectNum(i)
- if IsValid(subphys) then
- local pos = subphys:GetPos()
- util.PaintDown(pos, "FadingScorch", ent)
- table.insert(postbl, pos)
- end
- end
- SendScorches(ent, postbl)
- end
- -- big scorch at center
- local mid = ent:LocalToWorld(ent:OBBCenter())
- mid.z = mid.z + 25
- util.PaintDown(mid, "Scorch", ent)
- end
- function IgniteTarget(att, path, dmginfo)
- local ent = path.Entity
- if not IsValid(ent) then return end
- if CLIENT and IsFirstTimePredicted() then
- if ent:GetClass() == "prop_ragdoll" then
- ScorchUnderRagdoll(ent)
- end
- return
- end
- if SERVER then
- local dur = ent:IsPlayer() and 5 or 10
- -- disallow if prep or post round
- if ent:IsPlayer() and (not GAMEMODE:AllowPVP()) then return end
- ent:Ignite(dur, 100)
- ent.ignite_info = {att=dmginfo:GetAttacker(), infl=dmginfo:GetInflictor()}
- if ent:IsPlayer() then
- timer.Simple(dur + 0.1, function()
- if IsValid(ent) then
- ent.ignite_info = nil
- end
- end)
- elseif ent:GetClass() == "prop_ragdoll" then
- ScorchUnderRagdoll(ent)
- local burn_time = 7.5
- local tname = Format("ragburn_%d_%d", ent:EntIndex(), math.ceil(CurTime()))
- ent.burn_destroy = CurTime() + burn_time
- timer.Create(tname,
- 0.1,
- math.ceil(1 + burn_time / 0.1), -- upper limit, failsafe
- function()
- RunIgniteTimer(ent, tname)
- end)
- end
- end
- end
- function SWEP:ShootFlare()
- local cone = self.Primary.Cone
- local bullet = {}
- bullet.Num = 12
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector( cone, cone, 0 )
- bullet.Tracer = 1
- bullet.Force = 2
- bullet.Damage = self.Primary.Damage * 1.75
- bullet.TracerName = self.Tracer
- bullet.Callback = IgniteTarget
- self.Owner:FireBullets( bullet )
- end
- function SWEP:PrimaryAttack()
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- if not self:CanPrimaryAttack() then return end
- self.Weapon:EmitSound( self.Primary.Sound )
- self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- self:ShootFlare()
- self:TakePrimaryAmmo( 1 )
- if IsValid(self.Owner) then
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
- end
- if ( (game.SinglePlayer() && SERVER) || CLIENT ) then
- self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
- end
- end
- function SWEP:GetHeadshotMultiplier(victim, dmginfo)
- local att = dmginfo:GetAttacker()
- if not IsValid(att) then return 3 end
- local dist = victim:GetPos():Distance(att:GetPos())
- local d = math.max(0, dist - 140)
- -- decay from 3.1 to 1 slowly as distance increases
- return 1 + math.max(0, (2.1 - 0.002 * (d ^ 1.25)))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement