From ceb586028a726567992b2e3bec8e3231504c6efd Mon Sep 17 00:00:00 2001 From: TwistedTail <8784231+TwistedTail@users.noreply.github.com> Date: Fri, 13 Sep 2019 17:51:44 -0300 Subject: [PATCH] Added e:getPlayerColor() and e:getWeaponColor() --- .../gmod_wire_expression2/core/color.lua | 19 +++++++++++++++++++ lua/wire/client/e2descriptions.lua | 2 ++ 2 files changed, 21 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/color.lua b/lua/entities/gmod_wire_expression2/core/color.lua index 78a658190b..19499ceef6 100644 --- a/lua/entities/gmod_wire_expression2/core/color.lua +++ b/lua/entities/gmod_wire_expression2/core/color.lua @@ -4,6 +4,7 @@ local Clamp = math.Clamp local floor = math.floor +local Round = math.Round local function RGBClamp(r,g,b) return Clamp(r,0,255),Clamp(g,0,255),Clamp(b,0,255) @@ -84,6 +85,24 @@ e2function void entity:setRenderMode(mode) duplicator.StoreEntityModifier(this, "colour", { RenderMode = mode }) end +e2function vector entity:getPlayerColor() + if not IsValid(this) then return {0, 0, 0} end + if not this:IsPlayer() then return {0, 0, 0} end + + local c = this:GetPlayerColor() + + return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) } +end + +e2function vector entity:getWeaponColor() + if not IsValid(this) then return {0, 0, 0} end + if not this:IsPlayer() then return {0, 0, 0} end + + local c = this:GetWeaponColor() + + return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) } +end + --- HSV --- Converts from the [http://en.wikipedia.org/wiki/HSV_color_space HSV color space] to the [http://en.wikipedia.org/wiki/RGB_color_space RGB color space] diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 5f3b634e5f..f3fd9ed6cd 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -962,6 +962,8 @@ E2Helper.Descriptions["setSkin(e:n)"] = "Sets the skin of an entity" E2Helper.Descriptions["getSkin(e:)"] = "Gets Es current skin number" E2Helper.Descriptions["getSkinCount(e:)"] = "Gets Es number of skins" E2Helper.Descriptions["setRenderMode(e:n)"] = "Sets the render mode of the entity (0 = Normal, 1 = TransColor, 2 = TransTexture, 3 = Glow, 4 = TransAlpha, 5 = TransAdd, 6 = Enviromental, 7 = TransAddFrameBlend, 8 = TransAlphaAdd, 9 = WorldGlow, 10 = None)" +E2Helper.Descriptions["getPlayerColor(e:)"] = "Returns the player's model color as a vector (R,G,B)" +E2Helper.Descriptions["getWeaponColor(e:)"] = "Returns the player's weapon color as a vector (R,G,B)" E2Helper.Descriptions["hsl2rgb(v)"] = "Converts V from the HSL color space to the RGB color space" E2Helper.Descriptions["hsl2rgb(nnn)"] = "Converts N,N,N from the HSL color space to the RGB color space" E2Helper.Descriptions["hsv2rgb(v)"] = "Converts V from the HSV color space to the RGB color space"