Weapon Overheat

Hello, i want to know if anybody know how i can make a Weapon that kan Overheat like i Fire 20 Rounds and the Weapon can not shoot for the next 5 Secounds

Could have variables like

SWEP.Overheated = false
SWEP.OverheatProgress = 0

Then have it so SWEP.OverheatProgress is in the SWEP:Think() function like this:

function SWEP:Think()

     local coolingSpeed = 2 --How fast to cool down
     self.OverheatProgress = math.max(self.OverheatProgress - FrameTime()*coolingSpeed, 0) --This will always run, so you can burst fire to avoid overheating

     if(self.Overheated) then

          if(self.OverheatProgress == 0) then

               self.Overheated = false --Resets it

          end

     end

end

And finally set it so that every time you fire a bullet the self.OverheatProgress rises and once it’s over a certain number you set self.Overheated to true.

If you want to add special effects or sounds you would add them by checking if self.Overheated is set to true

Thx for your help but do you know how i can do it with the thing like every shot the Progess goes up?

Whenever the weapon is using the ShootBullet() or FireBullets() function you add this right after:

self.OverheatProgress = self.OverheatProgress + 1

if(self.OverheatProgress >= 30) then

     self.Overheated = true

end

Make sure to wrap everything inside of a

if(self.Overheated == false) then

statement, so it doesn’t actually shoot bullets once it’s in the overheated state.

Like this (Sry if i am annoying you)

function SWEP:Think(...)
BaseClass.Think(self, ...)

local coolingSpeed = 5 --How fast to cool down
self.OverheatProgress = math.max(self.OverheatProgress - FrameTime()*coolingSpeed, 0) --This will always run, so you can burst fire to avoid overheating

if(self.Overheated == false) then

    if (self.Weapon:ShootBullet( DMG_BULLET, 1, 1, self.Primary.GetAmmo(), 1, 5)) then
 	    self.OverheatProgress = self.OverheatProgress + 1
    end

    if(self.OverheatProgress >= 10) then
	    self.Overheated = true
	end

end

if (self.Overheated == true) then
	print("Overheated")
end

end

Sorry, it turns out it’s a bit more complicated than I made it look.
I’ve been working on a SWEP to demonstrate it but I can’t finish it today.
Tomorrow I’ll show you.

Its ok thx you helping me alot!

Took me some time to complete it, but here’s an example!
I had trouble synching client with server, IsFirstTimePredicted() fixed it for me.
Just copy all of this in a .lua file and drop it in the lua/weapons folder, you’ll find the weapon in the ‘Other’ tab
I went a bit overboard, I added an aiming function and some visual/sound clues for when the weapon is overheating.

AddCSLuaFile()

SWEP.PrintName = "Overheating SMG"
SWEP.Spawnable = true

SWEP.ViewModel = Model("models/weapons/c_smg1.mdl")
SWEP.WorldModel = Model("models/weapons/w_smg1.mdl")
SWEP.UseHands = true

SWEP.Primary.ClipSize = 50
SWEP.Primary.DefaultClip = 300
SWEP.Primary.BulletsPerSecond = 20
SWEP.Primary.Damage = 4
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "SMG1"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

SWEP.UseAmmo = true

SWEP.OverheatingSpeed = 40
SWEP.CoolingSpeed = 5 --Seconds

SWEP.Overheated = false
SWEP.OverheatProgress = 0
SWEP.Aiming = false


function SWEP:Initialize()

	self:SetHoldType("smg")

end

function SWEP:Reload()

	self.NextReload = self.NextReload || CurTime() --If the variable doesn't exist, we create it by setting it to CurTime()

	if(self.Weapon:Clip1() < self.Primary.ClipSize && self:HasAmmo()) then

		if(self.NextReload <= CurTime()) then

			self.Owner:AnimRestartGesture(GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_HL2MP_GESTURE_RELOAD_SMG1, true) --Makes the player play out the reload animation
			self:DefaultReload(ACT_VM_RELOAD) --This does the reload and plays the viewmodel animation as well
			self:EmitSound("weapons/smg1/smg1_reload.wav", 60, 100, 0.8, CHAN_WEAPON)

			self.NextReload = CurTime() + 2
			self:SetNextPrimaryFire(CurTime() + 2)

		end

	end

end

function SWEP:PrimaryAttack()

	if(self.Overheated == false) then

		if(self.Weapon:Clip1() > 0) then

			self:ShootBullet(self.Primary.Damage, 1, 0.03 * (self.Aiming && 0.5 || 1), self.Primary.Ammo, 10) --Third variable is the spread, if you're aiming with right-click it's narrower

			self:EmitSound("weapons/smg1/smg1_fire1.wav", 85, 100 - (self.OverheatProgress*3)^3, 0.5, CHAN_WEAPON) --Third variable is the pitch, I'm pitching it down when it's close to overheating
			self:ShootEffects(self)

			self:TakePrimaryAmmo(1)

			if (IsFirstTimePredicted()) then --Without this, the client will run the code multiple times and the variable won't be synched with the server

				self.OverheatProgress = math.min(self.OverheatProgress + 1/self.OverheatingSpeed, 1) --Won't go past '1'

				if(self.OverheatProgress == 1) then

					self.Overheated = true
					self:EmitSound("ambient/fire/ignite.wav", 50, 200, 0.7, CHAN_WEAPON)

				end

			end

		else

			self:EmitSound("weapons/pistol/pistol_empty.wav", 50, 100, 0.5, CHAN_WEAPON)

		end

	end

	self:SetNextPrimaryFire(CurTime() + 1/self.Primary.BulletsPerSecond)

end

function SWEP:SecondaryAttack()

	if(IsFirstTimePredicted()) then

		self.Aiming = !self.Aiming --Toggle the aim

		self:SetNextSecondaryFire(CurTime() + 0.5)

	end

end

function SWEP:Think()

	if(IsFirstTimePredicted()) then

	     self.OverheatProgress = math.max(self.OverheatProgress - FrameTime()*(1/self.CoolingSpeed), 0) --This will always run, so you can burst fire to avoid overheating

	     if(self.Overheated) then

	          if(self.OverheatProgress == 0) then

	               self.Overheated = false --Resets it

				self:EmitSound("items/ammo_pickup.wav", 50, 200, 0.7, CHAN_WEAPON)

	          end

	     end

	end

end

function SWEP:CalcViewModelView(viewModel, oldEyePos, oldEyeAng, eyePos, eyeAng)

	self.AimApproach = self.AimApproach || 0

	local aimSpeed = 3

    viewModel:SetColor(Color(255, 255 - self.OverheatProgress*255, 255 - self.OverheatProgress*255, 255)) --Becomes red when overheating

    if(self.Aiming) then

	    self.AimApproach = math.Approach(self.AimApproach, 1, FrameTime()*aimSpeed) --Smooths in the aiming animation

	    eyePos = oldEyePos - (oldEyeAng:Right()*6.41 + oldEyeAng:Forward()*8 - oldEyeAng:Up()*1.04)*self.AimApproach

    else

	    self.AimApproach = math.Approach(self.AimApproach, 0, FrameTime()*aimSpeed) --Smooths out the aiming animation

	    eyePos = eyePos - (oldEyeAng:Right()*6.41 + oldEyeAng:Forward()*8 - oldEyeAng:Up()*1.04)*self.AimApproach

    end

    return eyePos, eyeAng

end

WOW. Thx for your help! This is amazing! But now i have one question do you know how complicatet it is to implemet this on a TFA weapon?

Not hard but very time consuming since I’d have to pick it all apart, the first file I checked was more than 10 times the size of the gun I posted here and I can see hundreds of files.
It’s easy to implement on just a gun, it’s hard to implement on an entire weapon base and make sure it works consistently.

Do you think that it is Possible to add this Stuff you have coded like that the Weapon gets Overheated on a Single weapon?

Ye

Sry if a am annoying but do you know how? Because with the Primary Attack Function the Weapon won’t shoot.

(You don’t have to make another TFA swep xD)

Provide me with the code and I’ll implement it.

1 Like
SWEP.Gun							= ("gun_base")
if (GetConVar(SWEP.Gun.."_allowed")) != nil then
if not (GetConVar(SWEP.Gun.."_allowed"):GetBool()) then SWEP.Base = "tfa_blacklisted" SWEP.PrintName         
= SWEP.Gun return end
end
SWEP.Base							= "tfa_gun_base"
SWEP.Category						= "Test Overheat Weapon"
SWEP.Manufacturer 					= " Overheat Weapon"
SWEP.Author							= "None"
SWEP.Contact						= ""
SWEP.Spawnable						= true
SWEP.AdminSpawnable					= true
SWEP.DrawCrosshair					= true
SWEP.DrawCrosshairIS 				= false
SWEP.PrintName						= "K-16 Bryar"
SWEP.Type							= "Galactic Blaster Pistol"
SWEP.DrawAmmo						= true
SWEP.data 							= {}
SWEP.data.ironsights				= 1
SWEP.Secondary.IronFOV				= 75
SWEP.Slot							= 1
SWEP.SlotPos						= 100

SWEP.FiresUnderwater 				= true

SWEP.IronInSound 					= nil
SWEP.IronOutSound 					= nil
SWEP.CanBeSilenced					= false
SWEP.Silenced 						= false
SWEP.DoMuzzleFlash 					= false
SWEP.SelectiveFire					= false
SWEP.DisableBurstFire				= false
SWEP.OnlyBurstFire					= false
SWEP.DefaultFireMode 				= "Single"
SWEP.FireModeName 					= nil
SWEP.DisableChambering 				= true

SWEP.Primary.ClipSize				= 15
SWEP.Primary.DefaultClip			= 15*5
SWEP.Primary.RPM					= 145
SWEP.Primary.RPM_Burst				= 145
SWEP.Primary.Ammo					= "ar2"
SWEP.Primary.AmmoConsumption 		= 1
SWEP.Primary.Range 					= 32000
SWEP.Primary.RangeFalloff 			= -1
SWEP.Primary.NumShots				= 1
SWEP.Primary.Automatic				= false
SWEP.Primary.RPM_Semi				= nil
SWEP.Primary.BurstDelay				= 0.2
SWEP.Primary.Sound 					= Sound ("w/m57.wav");
SWEP.Primary.ReloadSound 			= Sound ("w/pistols.wav");
SWEP.Primary.PenetrationMultiplier 	= 0
SWEP.Primary.Damage					= 20
SWEP.Primary.HullSize 				= 0
SWEP.DamageType 					= nil

SWEP.DoMuzzleFlash 					= false

SWEP.FireModes = {
"Single"
}

SWEP.IronRecoilMultiplier			= 0.44
SWEP.CrouchRecoilMultiplier			= 0.33
SWEP.JumpRecoilMultiplier			= 1.3
SWEP.WallRecoilMultiplier			= 1.1
SWEP.ChangeStateRecoilMultiplier	= 1.18
SWEP.CrouchAccuracyMultiplier		= 0.7
SWEP.ChangeStateAccuracyMultiplier	= 1
SWEP.JumpAccuracyMultiplier			= 2.6
SWEP.WalkAccuracyMultiplier			= 1.18
SWEP.NearWallTime 					= 0.25
SWEP.ToCrouchTime 					= 0.1
SWEP.WeaponLength 					= 35
SWEP.SprintFOVOffset 				= 12
SWEP.ProjectileVelocity 			= 9

SWEP.ProjectileEntity 				= nil
SWEP.ProjectileModel 				= nil

SWEP.ViewModel						= "models/bf2017/c_scoutblaster.mdl"
SWEP.WorldModel						= "models/bf2017/w_scoutblaster.mdl"
SWEP.ViewModelFOV					= 75
SWEP.ViewModelFlip					= false
SWEP.MaterialTable 					= nil
SWEP.UseHands 						= true
SWEP.HoldType 						= "pistol"

SWEP.ShowWorldModel = false

SWEP.BlowbackEnabled 				= true
SWEP.BlowbackVector 				= Vector(0,-2.5,-0.05)
SWEP.BlowbackCurrentRoot			= 0
SWEP.BlowbackCurrent 				= 0
SWEP.BlowbackBoneMods 				= nil
SWEP.Blowback_Only_Iron 			= true
SWEP.Blowback_PistolMode 			= false
SWEP.Blowback_Shell_Enabled 		= false
SWEP.Blowback_Shell_Effect 			= "None"

SWEP.Tracer							= 0
SWEP.TracerName 					= "rw_sw_laser_purple"
SWEP.TracerCount 					= 1
SWEP.TracerLua 						= false
SWEP.TracerDelay					= 0.01
SWEP.ImpactEffect 					= "rw_sw_impact_purple"
SWEP.ImpactDecal 					= "FadingScorch"

SWEP.VMPos = Vector(0.6, -9, -01.1)
SWEP.VMAng = Vector(0,0,0)

SWEP.IronSightTime 					= 0.3
SWEP.Primary.KickUp					= 0.35
SWEP.Primary.KickDown				= 0.15
SWEP.Primary.KickHorizontal			= 0.055
SWEP.Primary.StaticRecoilFactor 	= 0.5
SWEP.Primary.Spread					= 0.025
SWEP.Primary.IronAccuracy 			= 0.005
SWEP.Primary.SpreadMultiplierMax 	= 1.5
SWEP.Primary.SpreadIncrement 		= 0.3
SWEP.Primary.SpreadRecovery 		= 0.98
SWEP.DisableChambering 				= true
SWEP.MoveSpeed 						= 1
SWEP.IronSightsMoveSpeed 			= 0.8

SWEP.IronSightsPos = Vector(-4.85, -6, 2)
SWEP.IronSightsAng = Vector(0, 0, 0)
SWEP.RunSightsPos = Vector(2, -9.5, -15)
SWEP.RunSightsAng = Vector(39, -0.5, -2)
SWEP.InspectPos = Vector(8, -4.8, -3)
SWEP.InspectAng = Vector(11.199, 38, 0)

SWEP.ViewModelBoneMods = {
    ["v_scoutblaster_reference001"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, -0.3, 0), angle =                 
Angle(0, 0, 0) }
}

SWEP.VElements = {
["k16"] = { type = "Model", model = "models/hauptmann/star wars/weapons/bryar_pistol.mdl", bone =     
"v_scoutblaster_reference001", rel = "", pos = Vector(-0, -05, -05.3), angle = Angle(0, 90, 0), size = Vector(1.05, 
1.05, 1.05), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} 
},
}

SWEP.WElements = {
["k16"] = { type = "Model", model = "models/hauptmann/star wars/weapons/bryar_pistol.mdl", bone = 
"ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(8.3, 1.75, 3.25), angle = Angle(0, 0, 180), size = Vector(1, 1, 
1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}

SWEP.Animations = { --Override this after SWEP:Initialize, for example, in attachments
["reload"] = {
	["type"] = TFA.Enum.ANIMATION_ACT, --Sequence or act
	["value"] = ACT_VM_RELOAD_EMPTY,
	["enabled"] = true
},
["reload_empty"] = {
	["type"] = TFA.Enum.ANIMATION_ACT, --Sequence or act
	["value"] = ACT_VM_RELOAD_EMPTY
},
["reload_silenced"] = {
	["type"] = TFA.Enum.ANIMATION_ACT, --Sequence or act
	["value"] = ACT_VM_RELOAD_EMPTY,
	["enabled"] = true
},
}

SWEP.Overheated = false
SWEP.OverheatProgress = 0

SWEP.ThirdPersonReloadDisable		=false
SWEP.Primary.DamageType 			= DMG_BULLET
SWEP.DamageType 					= DMG_BULLET
SWEP.RTScopeAttachment				= -1
SWEP.Scoped_3D 						= false
SWEP.ScopeReticule 					= "#sw/visor/sw_ret_redux_red" 
SWEP.Secondary.ScopeZoom 			= 8
SWEP.ScopeReticule_Scale 			= {1,1}
if surface then
    SWEP.Secondary.ScopeTable = nil --[[
	    {
		    scopetex = surface.GetTextureID("scope/gdcw_closedsight"),
		    reticletex = surface.GetTextureID("scope/gdcw_acogchevron"),
		    dottex = surface.GetTextureID("scope/gdcw_acogcross")
	    }
    ]]--
end
DEFINE_BASECLASS( SWEP.Base )

Here

Sorry mate, this uses the TFA gun base, there isn’t any actual function running, just lots of variables defining what the weapon should be.
I would have to redo the gun base itself to add this functionality.

1 Like