EntityTakeDamage in vehicle

Hello.
Excuse me for any grammatical errors.
I’m having some problem with this code:



hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function()
	if ( target:IsVehicle() ) then

		local ply = target:GetDriver()
		if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then
			dmginfo:SetDamage( dmginfo:GetDamage() / 2 )
			ply:TakeDamageInfo( dmginfo )
			dmginfo:SetDamage( 0 )

		end

	end
end)


I didn’t create it, I copied it by wiki.garrysmod.org: http://wiki.garrysmod.com/page/GM/EntityTakeDamage

When I shoot a car with a player inside, if the player has the armor then only the armor will damage, but If the player hasn’t the armor, anything happens.

I already tried to edit the code using ply:SetHealth() But anything changes…
Someone can help me?

That’s just how TakeDamageInfo works. You can always set the Health yourself. If it isn’t working, post what you tried

Something like this

hook.Add(“EntityTakeDamage”, “PlayerInVehicleDamaged”, function( target, dmginfo )
if ( target:IsVehicle() ) then

	local ply = target:GetDriver()
	if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then
            damage = dmginfo:GetDamage()
            ply:SetHealth( ply:Health() - damage )
            ply:SetArmor( ply:Armor() - damage )

	end

end

end)

That won’t work because neither target nor dmginfo are parameters you specified. Also, you defined damage as global.

Sorry Posted on wrong thread :smiley:

I’m sorry, I wrote it here, the original code, hasn’t this error.
I edited the post.

Anyone else?

GM:EntityTakeDamage
As the wiki says, try returning true

Excuse me for the delay.

Have I to do something like that?:




hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function( target, dmginfo )
return true
if ( target:IsVehicle() ) then

local ply = target:GetDriver()
if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then
damage = dmginfo:GetDamage()
ply:SetHealth( ply:Health() - damage )
ply:SetArmor( ply:Armor() - damage )
end
end


end)



Do you even know how return works?
That wont work.
Do you even read?



hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function()
	if ( target:IsVehicle() ) then

		local ply = target:GetDriver()
		if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then
			return true
		end

	end
end)


try that.

re-excuse me for the delay.
No, it doesn’t work…
I don’t know how can I make it, can someone help me?