Garry's Mod Wiki

DamageInfo

  CTakeDamageInfo DamageInfo()

Description

Returns an CTakeDamageInfo object.

This does not create a unique object, but instead returns a shared reference. That means you cannot use two or more of these objects at once.

Issue Tracker: 2771

Returns

Example

Example usage

function TakeDamage( victim, damage, attacker, inflictor ) local dmg = DamageInfo() -- Create a server-side damage information class dmg:SetDamage( damage ) dmg:SetAttacker( attacker ) dmg:SetInflictor( inflictor ) dmg:SetDamageType( DMG_ENERGYBEAM ) victim:TakeDamageInfo( dmg ) end concommand.Add( "kill_this_entity", function( ply, cmd, args ) local target = ply:GetEyeTrace().Entity if ( target:IsVehicle() ) then target = target:GetDriver() -- Convert this to damage the plater inside end -- When target is a player in a vehicle will not get damaged TakeDamage( target, target:Health(), ply, ply:GetActiveWeapon() ) end )