Garry's Mod Wiki

Revision Difference

Entity:SetColor#526535

<function name="SetColor" parent="Entity" type="classfunc"> <description>Sets the color of an entity.</description> <description>Sets the color of an entity. Some entities may need a custom render mode set for transparency to work. See example 2.</description> <realm>Shared</realm> <args> <arg name="color" type="table" default="Color(255, 0, 255, 255)">The color to set. Uses the <page>Color</page>.</arg> </args> </function> <example> <description>Loop through all players, make them black</description> <code> local colBlack = Color( 0, 0, 0, 255 ) -- Creates a black color for key, ply in pairs(player.GetAll()) do -- Loop through all players on the server ply:SetColor(colBlack) -- Sets the players color to colBlack end </code> </example> <example> <description>Creates a wooden crate at 0,0,0 and turns it a transparent green</description> <code> local ent = ents.Create("prop_physics") ent:SetPos(Vector(0,0,0)) ent:SetModel("models/props_junk/wood_crate001a.mdl") ent:Spawn() ent:SetColor( Color( 0, 255, 0, 230 ) ) ent:SetRenderMode( RENDERMODE_TRANSALPHA ) -- You need to set the render mode on some entities in order for the color to change ent:SetRenderMode( RENDERMODE_TRANSCOLOR ) -- You need to set the render mode on some entities in order for the color to change </code> </example>