Below is the current list of Lua functions and enums available for developers to use to integrate GChroma with their addons.
Before you start developing for GChroma, take note of the following:
- Make sure your addon doesn't interfere with other addons. GChroma has no way of knowing what addon is supposed to take priority, so it will always override the current color grid with the one that was called last. If at all possible, it is recommended you call a function from the last addon to use the grid to make sure colors are restored. You should only do this if you have a way of knowing whether or not that addon is installed, otherwise players who don't have it will get errors.
- Avoid running resource-intensive functions in loops, specifically
gchroma.CreateEffect()
andgchroma.SendFunctions()
. Failure to do so may result in the SDK taking a long time to process the changes. Looping timers or cooldowns with a time of at least 0.1 seconds should be used if you plan on rapidly changing colors.
These functions are available on both the client and server, though for best performance it's recommended that you use the them client-side whenever possible.
Sets the specified device to a solid color. Individual LEDs cannot be changed with this function.
-
number
device - Device ID. See enums section below for available devices. -
vector
color - Color to set the device. Must be a vector. Usegchroma.ToVector()
if you need to convert an existing color table to a vector. Usingcolor:ToVector()
will cause the LEDs to be extremely dim since it uses a range of 0-1 instead of 0-255.
Sets the color of all available devices to blue.
if gchroma then --If your addon isn't exclusively made for GChroma, add this check to avoid errors
gchroma.SetDeviceColor( GCHROMA_DEVICE_ALL, Vector( 0, 0, 255 ) )
gchroma.CreateEffect()
end
Sets the color of all available devices to the color of the entity that the client has used.
--Assume this function is in a shared file
function ENT:Use( ply )
if CLIENT and gchroma then
gchroma.SetDeviceColor( gchroma, GCHROMA_DEVICE_ALL, gchroma.ToVector( self:GetColor() ) )
gchroma.CreateEffect()
end
end
Sets the color of the specified device LED. If you are setting the color for a keyboard or mouse, you can use their respective LED enums and set the col argument to 0. If you are using a different device, see the Chroma LED Profiles for what row and column you should use.
-
number
device - Device ID. See enums section below for available devices. Note that the GCHROMA_DEVICE_ALL enum will NOT work with this function. -
vector
color - Color to set the device. Must be a vector. Usegchroma.ToVector()
if you need to convert an existing color table to a vector. Usingcolor:ToVector()
will cause the LEDs to be extremely dim since it uses a range of 0-1 instead of 0-255. -
number
row - Row of the device LED. -
number
col - Column of the device LED.
Sets the mouse scroll wheel color to blue.
if gchroma then
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_MOUSE, Vector( 0, 0, 255 ), GCHROMA_MOUSE_SCROLLWHEEL, 0 )
gchroma.CreateEffect()
end
--This does the same thing as above, but uses the grid system instead of enums
if gchroma then
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_MOUSE, Vector( 0, 0, 255 ), 2, 3 )
gchroma.CreateEffect()
end
Sets the W key on the keyboard to red.
if gchroma then
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_KEYBOARD, Vector( 255, 0, 0 ), GCHROMA_KEY_W, 0 )
gchroma.CreateEffect()
end
Sets the top left corner of the mousepad to green.
if gchroma then
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_MOUSEPAD, Vector( 0, 255, 0 ), 0, 0 )
gchroma.CreateEffect()
end
Resets the colors of the specified device to 0, 0, 0.
number
device - Device ID. See enums section below for available devices.
Converts a Lua color table into a vector so that it can be used in the GChroma color functions.
color
color - Color table to be converted.
Creates a new effect by applying the changes made using the other functions. This is always required when you are finished modifying colors.
Sets all 4 corners of the mouse pad to green.
if gchroma then
local grid = { 0, 4, 10, 14 }
for k,v in pairs( grid ) do
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_MOUSEPAD, GCHROMA_COLOR_GREEN, v, 0 )
end
gchroma.CreateEffect()
end
Converts a Garry's Mod key into a GChroma key. May not work for every key.
number
key - Garry's Mod key to be converted.
Sets the color of the key bound to voice chat to green.
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_KEYBOARD, Vector( 0, 255, 0 ), gchroma.KeyConvert( input.GetKeyCode( input.LookupBinding( "voicerecord" ) ) ), 0 )
Server-side version of gchroma.CreateEffect()
. Sends a net message to the player to apply the changes made using the other functions.
player
ply - Player who will receive the effects
Sets the color of all available devices to blue.
for k,v in ipairs( player.GetAll() ) do --This sends the message to all players for the example, but generally you should avoid doing this since the majority of players likely won't be able to use it
gchroma.SetDeviceColor( GCHROMA_DEVICE_ALL, Vector( 0, 0, 255 ) )
gchroma.SendFunctions( v )
end
Resets all devices and sets the W key to red and S key to green.
function ENT:Use( activator, caller )
gchroma.ResetDevice( GCHROMA_DEVICE_ALL )
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_KEYBOARD, GCHROMA_COLOR_RED, GCHROMA_KEY_W, 0 )
gchroma.SetDeviceColorEx( GCHROMA_DEVICE_KEYBOARD, GCHROMA_COLOR_GREEN, GCHROMA_KEY_S, 0 )
gchroma.SendFunctions( activator )
end
All hooks are client-side only and return the values of the functions associated with them.
Gets called when the module is first loaded. Does not get called if the module fails to load.
Gets called when a color is set.
number
device - Type of device that had its color changedvector
color - Color that was set as a vector[number]
row - Row of the color grid, only available when usingSetDeviceColorEx
[number]
col - Column of the color grid, only available when usingSetDeviceColorEx
Gets called when a device's color gets reset.
number
device - Type of device that had its color changed
Gets called when an effect is created.