Damage on car fall but already disable damage script not working

Hi all,

So on my server I have this script to disable damage to players:



function DisablePlayerPropDamage(v,a)
	if a:IsValid() and a:GetClass() == "prop_physics" or a:IsValid() and a:GetClass() == "prop_vehicle_jeep" or a:IsValid() and a:GetClass() == "mx_radio" or a:IsValid() and a:GetClass() == "worldspawn" then
		return false
	end
end
hook.Add( "PlayerShouldTakeDamage", "DisablePlayerPropDamage", DisablePlayerPropDamage )


But say I got a car and physgunned it over someones head and dropped it, the car kills them, in console it says:



Computer600 was killed by worldspawn


How would I go about disabling the damage of the car but I still want fall damage.

Thanks,
Computer600

I would hook the GM function that applies damage to players, and print the type of damage they took.
Then update you script to include the damage type.

I would also cleanup your if statement. You should only need one IsValid() check.
it’s also unnecessary but I would use an array to keep the statement tidy and easy to update.

Okay, so I’m trying to test but I’m getting this error:



function arguments expected near ')'


Here’s the testing code:



hook.Add( "EntityTakeDamage", "PrintTheDamageFromSomeone", function( target, dmginfo )
	print( target )
	print( dmginfo:GetAttacker )
end)


you forgot to close your hook.
No I’m wrong, inline function I’m still sleepy. Give me a sec.

Just for simplicity sake separate the function and the hook.



function MyDamageHook(target, dmginfo)
	print( target )
	print( dmginfo:GetAttacker )
end
hook.Add( "EntityTakeDamage", "PrintTheDamageFromSomeone", MyDamageHook)


GetAttacker**()**

(It’s a function)

I tried your code and got the error on line 3 (look at comment on code)



function MyDamageHook(target, dmginfo)
	print( target )
	print( dmginfo:GetAttacker ) -- This line
end
hook.Add( "EntityTakeDamage", "PrintTheDamageFromSomeone", MyDamageHook)


I think there is something wrong with the way I’m calling the attacker, but I’m unsure

EDIT:

Ahh, of course :stuck_out_tongue:

[editline]24th December 2013[/editline]

Okay I found out the damage is worldspawn but now how will I disable it only for cars

When the player gets damaged, you can check the dmginfo for a reference to an entity then check it’s model (hacky) or find some way to tell it’s a car. Check entity class in the wiki and see what you can get from it.

Then have an if statement in that hook, if you get worldspawn damage check and see if it was a car. if it was a car, then return false otherwise return true. (prob best in your player damage function, I don’t know if you can use returns without overriding functions?)

Great stuff! I found that ent:GetModel() return the model of the entity but I can’t seem to find a correct dmginfo function to get the vehicle when they die since it only returns worldspawn

It’s not possible. Worldspawn is worldspawn. The car hits the player, something weird happens between the player and the world and then the player dies, because of worldspawn.

Maybe someone else can explain it better. Only option I can think of is:
[lua]
for _, x in pairs( ents.FindInSphere( ply:GetPos(), 100 ) do

if x:IsVehicle() then

--no damage

end

end
[/lua]

Still it might not work and if it does, not always be accurate.

Thanks :smiley: It works, what hook do you suggest I should use though, currently its PlayerShouldTakeDamage but with that it disables all damage from the player when near a vehicle, what do you suggest?

Use EntityTakeDamage and check if the source is worldspawn, if it is then do the vehicle in a radius check.

So this is the outcome I got:



function DisableCarDamage( ply, dmginfo )
	if dmginfo:GetInflictor() == "worldspawn" then
		for _, x in pairs( ents.FindInSphere( ply:GetPos(), 100 ) ) do
			if x:IsVehicle() then
				dmginfo:ScaleDamage( 0 )
			end
		end
	end
end
hook.Add( "EntityTakeDamage", "RemoveDamageFromCarDamage", DisableCarDamage)


But it doesn’t work :confused:

Change Inflictor to Attacker.

Still not working :confused: still can get killed by it