AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Convert to hex (https://forums.alliedmods.net/showthread.php?t=60571)

purple_pixie 09-07-2007 11:43

Convert to hex
 
I couldn't find any natives for converting a decimal number to hex.

I have an RGB value that would be a lot happier as a hex value ( for showing in an MOTD window) and I was wondering if there's an easy way.

I could do write an rgb_to_hex() function, but if there's an obvious way I don't know about then I'd feel like a tool.

EDIT: Well since I didn't find one, anyone who reads this hoping for an answer can use this:
Code:
stock rgb_to_hex(r,g,b,output[8]) {     new letter1,letter2 ;     letter1=r/16     letter2=r%16     output[0]=36 // $ sign     output[1]=( letter1 < 10 ) ? letter1+48 : letter1+55     output[2]=( letter2 < 10 ) ? letter2+48 : letter2+55     letter1=g/16     letter2=g%16     output[3]=( letter1 < 10 ) ? letter1+48 : letter1+55     output[4]=( letter2 < 10 ) ? letter2+48 : letter2+55     letter1=b/16     letter2=b%16     output[5]=( letter1 < 10 ) ? letter1+48 : letter1+55     output[6]=( letter2 < 10 ) ? letter2+48 : letter2+55     output[7]=0 }
I think it works ... it seems fine for my testing.

It seems weird to have the string one character too long, but AMX gets a tad confused if you don't terminate your strings in my experience.


All times are GMT -4. The time now is 16:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.