Vehicle explosion script?

I’ve been thinking about creating a script of which sets health of 500 HP to any entity that belongs the vehicle class, and when it drains down to zero and below, the vehicle entity explodes in the scale of a HL2 grenade, and the vehicle is un-enterable and it is painted in black. I’ve been thinking and i don’t even know where to start. Any tips/suggestions? Thanks.

I think the Nuke 4 pack has an exploding car, why not check out some of it’s code for a starting place. The only way I can imagine painting the car black is to change the material, so look into how glua handle’s that.

[editline]7th June 2013[/editline]

You could always darken it by changing it’s color.

I actually meant to change it’s color to solid black. Also, i dont think the vehicle is drivable, its simply a bomb with a differend model… Not really related

Bump


DefaultVehicleHP = 50
DeafultCleanupTime = 180
hook.Add("EntityTakeDamage", "VehicleHPHook", function( ent, dmginfo )
	if not ent:IsVehicle() then
		return 
	end
	if not ent.HP then
		ent.HP = DefaultVehicleHP
	end
	ent.HP = ent.HP - dmginfo:GetDamage() * 100
	if ent.HP <= 0 and not ent.Destroyed then
		ent.Destroyed = true
		ent:SetColor(Color(0,0,0,255))
		local ExplodeTime = math.random(5,30)
		ent:Ignite(ExplodeTime,100)
		--[[if ent:GetDriver():IsPlayer() then
			ent:GetDriver():ExitVehicle()
		end
		if ent:GetPassenger():IsPlayer() then
			ent:GetPassenger():ExitVehicle()
		end
		--]]
		timer.Simple(ExplodeTime, function()
			if not ent then return end
			local explosion = ents.Create("env_explosion")
			explosion:SetPos(ent:GetPos())
			explosion:SetOwner(attacker)
			explosion:Spawn()
			explosion:SetKeyValue("iMagnitude", "1000")
			explosion:Fire("Explode", 0, 0)	
			if ent:GetDriver():IsPlayer() then
				ent:GetDriver():Kill()
			end
			if ent:GetPassenger():IsPlayer() then
				ent:GetPassenger():Kill()
			end
			timer.Simple(DeafultCleanupTime, function()
				if not ent then return end
				ent:Remove()
			end)
		end)
	end
end)

hook.Add("CanPlayerEnterVehicle", "ExplodedVehicles", function(ply, vehicle, role)
	if vehicle.Destroyed then 
		return false
	end
end)

I didn’t make this, but here you go…