Skip to content

Commit 28971c7

Browse files
author
thegrb93
authored
Merge pull request #1979 from TwistedTail/master
Added e:getPlayerColor() and e:getWeaponColor()
2 parents cfdadd9 + ceb5860 commit 28971c7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lua/entities/gmod_wire_expression2/core/color.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
local Clamp = math.Clamp
66
local floor = math.floor
7+
local Round = math.Round
78

89
local function RGBClamp(r,g,b)
910
return Clamp(r,0,255),Clamp(g,0,255),Clamp(b,0,255)
@@ -84,6 +85,24 @@ e2function void entity:setRenderMode(mode)
8485
duplicator.StoreEntityModifier(this, "colour", { RenderMode = mode })
8586
end
8687

88+
e2function vector entity:getPlayerColor()
89+
if not IsValid(this) then return {0, 0, 0} end
90+
if not this:IsPlayer() then return {0, 0, 0} end
91+
92+
local c = this:GetPlayerColor()
93+
94+
return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) }
95+
end
96+
97+
e2function vector entity:getWeaponColor()
98+
if not IsValid(this) then return {0, 0, 0} end
99+
if not this:IsPlayer() then return {0, 0, 0} end
100+
101+
local c = this:GetWeaponColor()
102+
103+
return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) }
104+
end
105+
87106
--- HSV
88107

89108
--- Converts <hsv> 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]

lua/wire/client/e2descriptions.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ E2Helper.Descriptions["setSkin(e:n)"] = "Sets the skin of an entity"
964964
E2Helper.Descriptions["getSkin(e:)"] = "Gets Es current skin number"
965965
E2Helper.Descriptions["getSkinCount(e:)"] = "Gets Es number of skins"
966966
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)"
967+
E2Helper.Descriptions["getPlayerColor(e:)"] = "Returns the player's model color as a vector (R,G,B)"
968+
E2Helper.Descriptions["getWeaponColor(e:)"] = "Returns the player's weapon color as a vector (R,G,B)"
967969
E2Helper.Descriptions["hsl2rgb(v)"] = "Converts V from the HSL color space to the RGB color space"
968970
E2Helper.Descriptions["hsl2rgb(nnn)"] = "Converts N,N,N from the HSL color space to the RGB color space"
969971
E2Helper.Descriptions["hsv2rgb(v)"] = "Converts V from the HSV color space to the RGB color space"

0 commit comments

Comments
 (0)