Vehicle Repair - In dire need of help!

Right uh, I’m probably posting this in the wrong section and a thread about this probably exists somewhere. But anywho…

I followed some thread on vehicle damage which provided me with this fine old bit of code.


A simple script by Sven Brimstone (SonofBrim) based off of the similar 2010 script by SinTwins.
Gives cars a set amount of health, sets them on fire and blows them up when that health is depleted.
Comes with some customization.

-- Config Options

defaulthp = 1800		-- Vehicle health
smokepoint = 300	-- Point at which vehicles begin to smoke

timemin = 5			-- Minimum time between the vehicle's health reaching 0 and detonation
timemax = 20		-- Maximum time between the vehicle's health reaching 0 and detonation

smokeeffect = "smoke_burning_engine_01"		-- Vehicle smoke effect
explodeeffect = "explosion_huge_f"				-- Explosion effect
-- Give cars health when they spawn.
hook.Add("PlayerSpawnedVehicle", "VehicleHP", function( ply, ent ) 
	if not ent:IsValid() then return end
	ent:SetHealth( defaulthp )
	ent.Screwed = false -- More or less lets later parts of the code know whether the car needs to be blow up or not.
	ent.Hurt = false

-- Make cars take damage and blow up if they are damaged too much.
hook.Add("EntityTakeDamage", "VehicleHPHook", function( ent, dmginfo ) 
	if not ent:IsVehicle() then return end
		local damage = dmginfo:GetDamage()
		-- Compensate for weird vehicle damage system, make explosives do more damage.
		if dmginfo:IsBulletDamage() then ent:SetHealth(ent:Health() - (10000 * damage)) 
			elseif dmginfo:IsExplosionDamage() then ent:SetHealth(ent:Health() - (8 * damage))
			else ent:SetHealth(ent:Health() - damage) 
		-- This was used for testing purposes, spits out a bunch of damage info to the console.
		-- print(ent:GetAttachments(), dmginfo:GetDamageType(), dmginfo:GetAmmoType(), damage, dmginfo:IsBulletDamage())
		-- Make the vehicle smoke if health gets low.
		if ent:IsValid() and ent:Health() <= smokepoint and ent.Hurt == false then
			local id = ent:LookupAttachment("vehicle_engine")
			ent.Hurt = true -- Let it know that the car is hurt so it doesn't add the effect the next time it gets damaged.
			ParticleEffectAttach( smokeeffect, PATTACH_POINT_FOLLOW, ent, id )
		-- Once health drops to 0 or below, light the car on fire, kick everyone out, and blow it up.
		if ent:IsValid() and ent:Health() <= 0 and ent.Screwed == false then
			ent.Screwed = true -- Let it know that the car is going to blow up and the timer is started (so it doesn't keep on restarting)
			local randomtime = math.random(timemin,timemax)
			ent:Ignite( randomtime, 100 )
			-- Boot the driver out
			if ent:GetDriver():IsValid() then ent:GetDriver():ExitVehicle(ent) end 
			-- Blow it up after a set time.
			timer.Create("CarExplode", randomtime, 1, function() 
				if not ent:IsValid() then return end
				local explosion = ents.Create("env_explosion")
				explosion:SetKeyValue("iMagnitude", "250")
				explosion:Fire("Explode", 0, 0)

-- If a car is going to blow up, don't let players in.
hook.Add("CanPlayerEnterVehicle", "ExplodedVehicles", function(ply, ent, role)
	if ent.Screwed then 
		return false

(inb4 formatting required to make it work as code which I’ll have to edit)

So this is really great and all, very lightweight. But since it’s just this script and nothing else, how would one go about making a swep that could in an ideal world, undo said damage with a delay of some sort?
I’m a giga-newbie when it comes to code and any help you chaps can provide would be lifesaving!


Forgive me for being a complete retard, but how would I do that?

Make a trace, make sure the trace hits a car, then get the cars current health then set it’s health as it’s current health + whatever


I should’ve probably emphasized the fact that I’ve never done this before.
I’ve tweaked little bits of variables in code, but that’s about it.

I’ve told you what you need to do and linked an example of a SWEP. Just look at the wiki pages I have given you and apply that to a SWEP. You wont learn anything if I just make it for you.

So how would I instead of making it throw a prop, do the uh, trace thing? and how would I get that to add health up.

Would 100 Health be relative to the health of the vehicle or would that need to be a max of 1800?

What if the vehicle is on fire/smoking? - How would I disable it from taking action if the car is on fire?

How would I make it stop smoking in the first place?

mane dis b hard ;-;

If you have barely any experience in glua and lua and only “tweaked little bits of variables in code” you probably shouldn’t dive straight into making this. Start off with something simpler?