Anti Prop Kill

I am looking to add a cars to my server, but i dont want to add them if they will make carDM is there a tutorial or a script to change it to 0

I’ll paste you mine (might be better ways of doing it):

[lua]
function antiPropDamage (victim, attacker)
if (attacker:GetClass() == “prop_physics”) then
return false
else
return true
end
end
hook.Add(“PlayerShouldTakeDamage”, “nopropdamage”,antiPropDamage)
[/lua]

im thinking init.lua? but i want to be sure where should this go to?

init.lua this won’t protect against entities though, you’d need to tell me what the class of the vehicle is:
Like if you use this code:
[lua]
function antiPropDamage (victim, attacker)
print (attacker.GetClass())
if (attacker:GetClass() == “prop_physics”) then
return false
else
return true
end
end
hook.Add(“PlayerShouldTakeDamage”, “nopropdamage”,antiPropDamage)
[/lua]

Then spawn the vehicle and drop it on your head and see what it says in console.
If its prop physics, just take out the print and carry on, if not tell me and I’ll modify the code.

do you mean like?

function antiPropDamage (victim, attacker)
print (attacker.GetClass())
if (attacker:GetClass() == “my vehicle name here?”) then
return false
else
return true
end
end
hook.Add(“PlayerShouldTakeDamage”, “nopropdamage”,antiPropDamage)

What ever the console brings up I’d think, but if you want it to also want prop kill protection you’d need to stick and or in there.

add me on steam please raymond13372009

Done.

I’ve written this:
[lua]
function antiPropDamage (victim, attacker)
if (attacker:IsValid()) then
if (attacker:GetClass() == “prop_physics” or attacker:IsWorld() or attacker:GetClass() == “prop_vehicle_jeep”) then
return false
else
if (attacker:IsPlayer()) then
if (attacker:InVehicle()) then
return false
end
else
return true
end
end
end
end
hook.Add(“PlayerShouldTakeDamage”, “nopropdamage”,antiPropDamage)
[/lua]

To solve this issue, however occasionally if a prop/vehicle hits a player in the right way worldspawn will be called as the attacker and despite with testing attacker:IsWorld() returning true, the player still dies. Any clues?

[FIXED]
Found out via testing worldspawn isn’t a valid entity so it never entered into the if’s.

I wonder if attacker == #worldspawn would work

It was fixed just included
[lua]
if (attacker:IsWorld()) then
return false
end
[/lua] before the is valid ent.

Sorry for necroposting - but that’s really a big problem.
One more modified version - also prevents killing while in vehicle

autorun\server
opropdamage.lua


function antiPropDamage (victim, attacker)
	-- if (attacker:IsWorld()) then return false end
	if (attacker:IsValid()) and (not attacker:IsWorld()) then
		if (attacker:GetClass() == "prop_physics" or attacker:GetClass() == "gmod_wheel" or attacker:GetClass() == "prop_vehicle_jeep") then
			return false
		else
			if (attacker:IsPlayer()) then
				if (attacker:InVehicle()) then
					return false
				end
			--else
				-- return true
			end
		end
	end
end
hook.Add("PlayerShouldTakeDamage","nopropdamage",antiPropDamage)

Just for the record, worldspawn is fall damage and crush damage.

Bel Irkalli, thanks, i forgot one important thing!
You still can be prop-killed when pushed into floor, because damage inflictor will be Worldspawn (fall damage)
you can prevent this by uncommenting “-- if (attacker:IsWorld()) then return false end”, however, that will disable any kind of fall damage