Need help with some code

Ok, Im trying to prevent CDM in my DarkRP but I can’t get it to work.

function GM:PlayerShouldTakeDamage( pl, car )
if pl:IsPlayer() then
if car:IsVehicle(prop_vehicle_jeep) then
return false
end

Can you help?

First of all, do you get any errors?

No, but it just doesn’t work.

Untested, but should work as far as I know. (I don’t think the IsVehicle function takes any arguments)
[lua]
hook.Add(“PlayerShouldTakeDamage”, function(victim, attacker)
if victim:IsPlayer() and attacker:IsVehicle() then return false
end)
[/lua]

Alright I’ll test it, thank you.

[editline]21st August 2014[/editline]

It didn’t work :expressionless:

Try this.
[lua]
hook.Add(“PlayerShouldTakeDamage”, “RandomHookName”, function(victim, attacker)
if victim:IsPlayer() and attacker:IsVehicle() then
return false
end
end)
[/lua]

Please post errors if you get any or it will be very hard to help you out.

Edit: Ops forgot something :v:

Im not getting any errors, but it just isn’t working. I’m using TDM cars if that helps any.



local function AntiPropKill(victim, attacker)  
    if(not attacker:IsPlayer()) then
        if (attacker:GetClass() == "prop_physics" or attacker:GetClass() == "prop_dynamic" or attacker:GetClass() == "prop_vehicle_jeep") then
        return false  
        end
    end
end
   
hook.Add( "PlayerShouldTakeDamage", "AntiPropKill", AntiPropKill)


Mitigates most prop/vehicle damage, provided that the prop doesn’t fall directly on them (then it’s the world that kills them(?) code_gs has a better script but I can’t find it right now.)

I’m pretty sure the attacker will never be the vehicle. correct me if i am wrong though.