Tocolor: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Added a proper example) |
||
Line 20: | Line 20: | ||
==Example== | ==Example== | ||
This example displays the text "Tuna" in small at the top left side of your screen. The color of this text can be changed using | This example displays the text "Tuna" in small at the top left side of your screen. The color of this text can be changed using the command /tunaColor. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local tunaColor = tocolor(255, 0, 0, 255) -- Default color | |||
-- This function draws the text | -- This function draws the text | ||
function | local function drawTuna() | ||
dxDrawText("Tuna", | dxDrawText("Tuna", 5, 5, 100, 100, tunaColor) | ||
end | end | ||
addEventHandler("onClientRender", root, | addEventHandler("onClientRender", root, drawTuna) | ||
-- | --This function handles the /tunaColor command, allowing players to set the color of tuna | ||
function | local function tunaColorCommand(command, red, green, blue, alpha) | ||
red, green, blue, alpha = tonumber(red), tonumber(green), tonumber(blue), tonumber(alpha) -- Convert all the args to numbers. NOTE: tonumber will return false if the arg is not provided/is not valid. | |||
-- Remind the user of the proper syntax if they failed to provide all the args | |||
if not red or not green or not blue then | |||
outputChatBox("* USAGE: /tunaColor [red] [green] [blue] [alpha]", 255, 0, 0) | |||
return | |||
outputChatBox(" | |||
end | end | ||
-- Make the alpha arg optional | |||
if not alpha then | |||
alpha = 255 | |||
end | |||
-- Update the color | |||
tunaColor = tocolor(red, green, blue, alpha) | |||
end | end | ||
addCommandHandler(" | addCommandHandler("tunaColor", tunaColorCommand) | ||
-- Example /setcoloroftuna 255 0 0 255 - for red. | -- Example /setcoloroftuna 255 0 0 255 - for red. | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 02:14, 6 March 2012
This function retrieves the hex number of a specified color, useful for the dx functions.
Syntax
int tocolor ( int red, int green, int blue [, int alpha = 255] )
Required Arguments
- red: The amount of red in the color (0-255).
- green: The amount of green in the color (0-255).
- blue: The amount of blue in the color (0-255).
Optional Arguments
- alpha: The amount of alpha in the color (0-255).
Returns
Returns a single value representing the color.
Example
This example displays the text "Tuna" in small at the top left side of your screen. The color of this text can be changed using the command /tunaColor.
local tunaColor = tocolor(255, 0, 0, 255) -- Default color -- This function draws the text local function drawTuna() dxDrawText("Tuna", 5, 5, 100, 100, tunaColor) end addEventHandler("onClientRender", root, drawTuna) --This function handles the /tunaColor command, allowing players to set the color of tuna local function tunaColorCommand(command, red, green, blue, alpha) red, green, blue, alpha = tonumber(red), tonumber(green), tonumber(blue), tonumber(alpha) -- Convert all the args to numbers. NOTE: tonumber will return false if the arg is not provided/is not valid. -- Remind the user of the proper syntax if they failed to provide all the args if not red or not green or not blue then outputChatBox("* USAGE: /tunaColor [red] [green] [blue] [alpha]", 255, 0, 0) return end -- Make the alpha arg optional if not alpha then alpha = 255 end -- Update the color tunaColor = tocolor(red, green, blue, alpha) end addCommandHandler("tunaColor", tunaColorCommand) -- Example /setcoloroftuna 255 0 0 255 - for red.
See Also
- createTrayNotification
- downloadFile
- getDevelopmentMode
- getKeyboardLayout
- getLocalization
- isShowCollisionsEnabled
- isShowSoundEnabled
- isTransferBoxAlwaysVisible
- isTransferBoxVisible
- isTrayNotificationEnabled
- setClipboard
- setDevelopmentMode
- setTransferBoxVisible
- setWindowFlashing
- showCol
- showSound
- Shared
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace