I've looked far and wide, from Workshop to Garrysmod.org and even developed one from existing code (which is shit, you'll see) but can not seem to get destructible car script to work. I've seen and contacted numerous servers which have this feature, and they all denied me, all I need is a script which will remove the car after enough damage is taken.
My current code only works after an RPG hit (I've tried turrets and other weapons for long periods of time and nothing), if you can fix it or let me use yours, I'd greatly appreciate it!
[CODE]local CarExploSound = {
Sound("ambient/explosions/explode_1.wav"),
Sound("ambient/explosions/explode_2.wav"),
Sound("ambient/explosions/explode_3.wav"),
Sound("ambient/explosions/explode_4.wav"),
Sound("ambient/explosions/explode_8.wav"),
Sound("ambient/explosions/explode_9.wav") }
if !ConVarExists("CarDamageMul") then
CreateConVar("CarDamageMul", '21', FCVAR_NOTIFY)
end
if !ConVarExists("CarSimpleEffect") then
CreateConVar("CarSimpleEffect", '0', FCVAR_NOTIFY)
end
if !ConVarExists("CarDebrisEffect") then
CreateConVar("CarDebrisEffect", '0', FCVAR_NOTIFY)
end
function CarRemoved(ent)
if ent:IsVehicle() then
ent.CarHealth = nil
end
end
hook.Add("EntityRemoved", "CarRemoved", CarRemoved)
function Explode(ent, inflictor)
local explo = ents.Create("env_explosion")
explo:SetOwner(inflictor)
explo:SetPos(ent:GetPos())
explo:SetKeyValue("iMagnitude", "200")
explo:SetKeyValue("spawnflags", "66")
explo:Spawn()
explo:Activate()
explo:Fire("Explode", "", 0)
local physExplo = ents.Create( "env_physexplosion" )
physExplo:SetOwner( inflictor )
physExplo:SetPos( ent:GetPos() )
physExplo:SetKeyValue( "Magnitude", "5000" ) -- Power of the Physicsexplosion
physExplo:SetKeyValue( "radius", "1000" ) -- Radius of the explosion
physExplo:SetKeyValue( "spawnflags", "10" )
physExplo:Spawn()
physExplo:Fire( "Explode", "", 0.02 )
local exp = ents.Create( "env_ar2explosion" )
exp:SetPos( ent:GetPos() )
exp:Spawn()
exp:Activate()
exp:Fire( "Explode", "", 0 )
local effectdata = EffectData()
effectdata:SetOrigin( ent:GetPos() )
util.Effect( "HelicopterMegaBomb", effectdata ) -- Big flame
ent:EmitSound(CarExploSound[math.random(#CarExploSound)], 100, math.random(90, 120), 150)
NextExplo = CurTime() + 0.01
ent:Remove()
end
function CarTakeDamage(ent, dmginfo )
if GetConVarNumber("CarDamageMul") == 0 then return end
if ent:IsValid() and ent.CarHealth then
local amount = dmginfo:GetDamage()
local inflictor = dmginfo:GetInflictor()
ent.CarHealth = ent.CarHealth - ( amount * GetConVarNumber("CarDamageMul") )
local dmgtype = dmginfo:GetDamageType()
if ent.CarHealth < 1 or dmginfo:IsExplosionDamage() and ent:IsValid() then
if ent:GetClass() == "prop_vehicle_jeep" or ent:GetClass() == "prop_vehicle_airboat" then
Explode(ent, inflictor)
else
ent:Remove()
end
end
end
end
hook.Add("EntityTakeDamage", "CarTakeDamage", CarTakeDamage )
//function GAMEMODE:OnEntityCreated( ent )
//if ent:IsVehicle() and ent:Health() == 0 then
// ent.CarHealth = "1000"
// ent.MaxCarHealth = "1000"
//end
//end
function CarSpawnHealthValue(ent)
if ent:IsVehicle() and ent:Health() == 0 then
ent.CarHealth = "1000"
ent.MaxCarHealth = "1000"
end
end
hook.Add("OnEntityCreated", "CarSpawnHealthValue", CarSpawnHealthValue )[/CODE]
Sorry, you need to Log In to post a reply to this thread.