Possibility to code health and damage per vehicle hitbox set?
7 replies, posted
I suppose my first question should be is this even possible? I want to believe it can be done with the right combination of declaring health for a location (front, right/left sides, turret) then adding lines that amount to 'if hitboxset = Front then' do the damage to that locations health.
I also want to differentiate between damage to the locations such as 'if dmg:IsExplosionDamage() then do the amount of damage or 'if dmg:IsBulletDamage() then ScaleDamage by 0.3 or whatever I figure out small arms fire to be again. As you can see I've explored this a little but I'm not sure how to bring it all together or pharse it into lua language properly.
if there's seperate hitboxes for the said model or you're willing to go through the trouble to re-code the car's entity for custom hitboxes than yes its possible
What you might be able to do is create an invisible entity on certain parts of the vehicle that takes the damage, and after damage has reached maximum capacity make it so the car does whatever you want it to do.
Also these might be helpful to get specific points of the vehicle entity, these can basically find the surface area of the entity, you can spend time toying with them to find a specific point you want to attach the damage entity to or something.
Entity/OBBMins
Entity/OBBMaxs
@GorkemF Thank you for confirming that it's possible. I'd just gotten done making sure my custom hit boxes made it in game before I realized it might get tricky to code what I was wanting to do.
@Braindawg That's actually rather brilliant! I could maybe even attach them the same way the turret entity is attached. Then I think something like:
if self.Health < 0 then
self:SetNetworkedBool("KillVehicle", true)
and when received by the vehicle
if self:GetNetworkedBool("KillVehicle") then
self.CarHealth = 0
If I get fancy maybe I could have the 'damage entity' spawn a turret gib while having the vehicle remove the turret entity if just the turret loses all it's heath.
if you wanted to get super extra fancy, you could add entities to the individual tires, and once they take enough damage change the weight of them to weigh down certain wheels, giving a blown-out tire effect.
Also, I'm pretty sure I'm wrong but there might be multiple bodygroups for the default jeep, with and without the Gauss Gun. If not then removing the Gauss Gun entity from the car itself probably wouldn't be hard anyway.
(also use self.Health <= 0 to avoid glitches if health manages to hit exactly 0)
If anybody wants to poke around I just uploaded a new zip at J Edgar Hovercraft SCar | Garry's Mod 13 Works In Progress. Requires SCars Slim. So I've worked out all the errors relating to what I wrote as far as fussing about 'end expected to close argument' and other console errors. Still not working as far as health per hitbox set though. I've just started working toward making the .mdls that will have the hitboxes for the second solution of attaching entities.
And warning: firing the missile with second fire will fuss about null physics because I disabled the physics on the rocket when it was blowing up as soon as fired.
Worked it out I believe. At the top of the files I have to start with:
ENT.HealthFront = 3267
ENT.HealthRight = 2178
ENT.HealthLeft = 2178
ENT.HealthRear = 1485
ENT.HealthTurret = 2673
to define the names and health totals. Then some point after Initialization add the code that tells it to update those health numbers
function ENT:UpdateVehicleHealthShared()
if self.CarHealth < 0 then self.CarHealth = 0 end
self:SetNetworkedFloat( "VehicleHealth", self.CarHealth )
if self.HealthFront < 0 then self.CarHealth = 0 end
self:SetNetworkedFloat( "FrontHealth", self.HealthFront )
if self.HealthRight < 0 then self.CarHealth = 0 end
self:SetNetworkedFloat( "RightHealth", self.HealthRight )
if self.HealthLeft < 0 then self.CarHealth = 0 end
self:SetNetworkedFloat( "LeftHealth", self.HealthLeft )
if self.HealthRear < 0 then self.CarHealth = 0 end
self:SetNetworkedFloat( "RearHealth", self.HealthRear )
if self.HealthTurret < 0 then self.CarHealth = 0 end
self:SetNetworkedFloat( "TurretHealth", self.HealthTurret )
Then immediately after that the function telling it how to handle damage:
function ENT:OnTakeDamage(dmg)
local Damage = 0
local attacker = dmg:GetAttacker( )
local HitboxFront = self:GetHitboxSet(Front)
local HitboxRight = self:GetHitboxSet(RightSide)
local HitboxLeft = self:GetHitboxSet(LeftSide)
local HitboxRear = self:GetHitboxSet(Rear)
local HitboxTurret = self:GetHitboxSet(Turret)
self:TakePhysicsDamage(dmg)
if attacker != self:GetDriver() then
if dmg:IsExplosionDamage() then
Damage = dmg:GetDamage()
else
Damage = (dmg:GetDamage()) / 33
end
if self.CanTakeDamage == 1 then
if HitboxTurret then
self.HealthTurret = self.HealthTurret - Damage
self:UpdateVehicleHealthShared()
elseif HitboxFront then
self.HealthFront = self.HealthFront - Damage
self.UpdateVehicleHealthShared()
elseif HitboxLeft then
self.HealthLeft = self.HealthLeft - Damage
self.UpdateVehicleHealthShared()
elseif HitboxRight then
self.HealthRight = self.HealthRight - Damage
self.UpdateVehicleHealthShared()
elseif HitboxRear then
self.HealthRear = self.HealthRear - Damage
self.UpdateVehicleHealthShared()
end
end
end
end
Testing it should have taken three hits from it's own main weapon to kill in the rear location. Took four or five but that just means I need to tweak more somewhere. If it had been using the default 200 SCar health one hit would have blew it. Just leaves figuring out how to tell it to remove the turret without removing the whole vehicle at turret death. I tried self.tower:Remove() but that caused the whole vehicle to just blip out of existence. Maybe I have to specify it like I had to specify GetHitboxSet(name of set) to make the locations work.
@Braindawg
Ping to thank you for giving what's turned into the working solution. I never could get anything but the front to register hits with hitbox groups on the main body model. Once I attached separate entities for the sides and rear with the correct group names, then it started to register the shots. Even the correct amount of shots to kill. Now I just need to find out why one of the entities doesn't remove on destruction/undo and it's perfect.
Sorry, you need to Log In to post a reply to this thread.