• Vehicle Repair - In dire need of help!
    9 replies, posted
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. [Code] --[[==================================================================================================== ===SIMPLE VEHICLE HEALTH SCRIPT=== 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 end) -- 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) end -- 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 ) end -- 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") ParticleEffect(explodeeffect,ent:GetPos(),Angle(0,0,0),nil) explosion:SetPos(ent:GetPos()) explosion:SetOwner(attacker) explosion:Spawn() explosion:SetKeyValue("iMagnitude", "250") explosion:Fire("Explode", 0, 0) ent:Remove() end) end end) -- 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 end end) [/Code] (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!
Use: [url]http://wiki.garrysmod.com/page/Entity/Health[/url] [url]http://wiki.garrysmod.com/page/Entity/SetHealth[/url]
[QUOTE=smithy285;46390502]Use: [url]http://wiki.garrysmod.com/page/Entity/Health[/url] [url]http://wiki.garrysmod.com/page/Entity/SetHealth[/url][/QUOTE] Forgive me for being a complete retard, but how would I do that?
[QUOTE=galloway6204;46390514]Forgive me for being a complete retard, but how would I do that?[/QUOTE] 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
[QUOTE=smithy285;46390547]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[/QUOTE] ...uuh
[QUOTE=galloway6204;46390552]...uuh[/QUOTE] [url]http://wiki.garrysmod.com/page/util/TraceLine[/url] [url]http://wiki.garrysmod.com/page/Chair_Throwing_Gun[/url]
[QUOTE=smithy285;46390567][url]http://wiki.garrysmod.com/page/util/TraceLine[/url] [url]http://wiki.garrysmod.com/page/Chair_Throwing_Gun[/url][/QUOTE] 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.
[QUOTE=galloway6204;46390582]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.[/QUOTE] 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.
[QUOTE=smithy285;46390590]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.[/QUOTE] 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 ;-;
[QUOTE=galloway6204;46390582]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.[/QUOTE] 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?
Sorry, you need to Log In to post a reply to this thread.