Garry's Mod Wiki

Entity:GetMaterialType

  number Entity:GetMaterialType()

Description

Returns the surface material type of this entity.

This can be approximated clientside via util.GetModelInfo.

Internally, all this does is return gamematerial of the surface property on the first physics object of the entity. You can do this yourself using PhysObj:GetMaterial and util.GetSurfaceData.

Returns

1 number with MAT enum
Surface material type.

Example

Prints the MAT_ enum name for every prop on the map.

local function BackwardsEnums( enumname ) -- Helper function to build our table of values. local backenums = {} for k, v in pairs( _G ) do if isstring(k) and string.find( k, "^" .. enumname ) then backenums[ v ] = k end end return backenums end local MAT = BackwardsEnums( "MAT_" ) local validClasses = { prop_physics = true, prop_physics_multiplayer = true, prop_dynamic = true } for _, v in ipairs( ents.GetAll() ) do if validClasses[ v:GetClass() ] then print( v:GetModel(), MAT[ v:GetMaterialType() ] or "UNKNOWN" ) end end
Output:
models/props_interiors/furniture_couch01a.mdl MAT_DIRT models/props/cs_office/offinspd.mdl MAT_GLASS models/props/cs_office/offinspf.mdl MAT_GLASS models/props_wasteland/controlroom_desk001b.mdl MAT_METAL models/props_junk/wood_crate002a.mdl MAT_WOOD models/props_junk/wood_crate002a.mdl MAT_WOOD models/props_junk/wood_crate001a_damaged.mdl MAT_WOOD models/props_wasteland/controlroom_desk001a.mdl MAT_METAL models/props_wasteland/controlroom_chair001a.mdl MAT_METAL models/props_c17/tools_wrench01a.mdl MAT_METAL models/props/cs_office/radio.mdl MAT_COMPUTER models/props_junk/pushcart01a.mdl MAT_METAL models/props_wasteland/kitchen_shelf001a.mdl MAT_METAL models/props_wasteland/cafeteria_table001a.mdl MAT_WOOD models/props_c17/furniturecouch001a.mdl MAT_DIRT models/props_c17/furnituretable003a.mdl MAT_WOOD models/combine_gate_vehicle.mdl UNKNOWN models/props_junk/sawblade001a.mdl MAT_METAL models/props/cs_office/offinspf.mdl MAT_GLASS models/props_junk/wood_crate001a.mdl MAT_WOOD ...