Garry's Mod Wiki

Revision Difference

Entity:GetMaterialType#515449

<function name="GetMaterialType" parent="Entity" type="classfunc">⤶ <description>Returns the surface material of this entity.</description>⤶ <realm>Server</realm>⤶ <rets>⤶ <ret name="" type="number">Surface material. See <page>MAT</page></ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>Prints the MAT_ enum name for every prop on the map.</description>⤶ <code>⤶ local function BackwardsEnums( enumname ) -- Helper function to build our table of values.⤶ local backenums = {}⤶ ⤶ for k, v in pairs( _G ) do⤶ if type( k ) == "string" 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 k, v in pairs( ents.GetAll() ) do⤶ if validclasses[ v:GetClass() ] then⤶ print( v:GetModel(), MAT[ v:GetMaterialType() ] or "UNKNOWN" )⤶ end⤶ end⤶ </code>⤶ <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <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⤶ ...⤶ </output>⤶ ⤶ </example>