mIRC Homepage
Posted By: Neo Script to generate random Twitch user name color - 07/12/16 05:56 AM
I am curious if anyone knows how to write a script that would generate a random color for one's username every time they type something into chat on Twitch.Tv. I've seen this before but am unsure of how it is accomplished. Any suggestions would be great!
Do you want a random color from Twitch's predetermined colors (not Prime/Turbo user) or a random color from a hex code (Prime/Turbo user)?
A random color from a hex code (Prime/Turbo user) is what I'm looking for.
Assuming that you are logged into mIRC on your Twitch account, and that you are using another way to chat in the channel that is not the same copy of mIRC that this script it on, this will do the trick. Every time that you type anything in chat, your login on mIRC will try to change your color for you.

Code:
ON *:TEXT:*:#: {
  IF ($nick == $me) {
    VAR %hex 0 1 2 3 4 5 6 7 8 9 A B C D E F
    MSG $chan .color $chr(35) $+ $gettok(%hex,$rand(1,16),32) $+ $gettok(%hex,$rand(1,16),32) $+ $gettok(%hex,$rand(1,16),32) $+ $gettok(%hex,$rand(1,16),32) $+ $gettok(%hex,$rand(1,16),32) $+ $gettok(%hex,$rand(1,16),32)
  }
}
Just for clarity: When sending a message to twitch, is that message originating from within your web browser or from an mIRC instance?

If from the webbrowser, this is not the site/program to do such.

If from mIRC you can use the following:
Code:
;; when text is input in a channel window
on *:INPUT:#:{
  ;; if ctrl+enter was NOT used
  ;; the text isn't being pasted in
  ;; the text doesn't start with /
  ;; the text doesn't start with a user defined command character
  if (!$ctrlenter && !$inpaste && /* !iswm $1 && $comchar $+ * !iswm $1) {
    
    ;; pick a random 16bit color, then convert it to a 6-character hex value
    var %color = $chr(35) $+ $base($rand(0, 16777215), 10, 16, 6)

    ;; msg the channel with the color change
    msg $chan .color %color
  }
}
That's awesome! Works great I appreciate it. One other question though, if I only wanted the script to randomly choose from a list of specific hex codes such as (#000000, #FF00FF, #00FFFF, #FFFF00, and #FFFFFF) how would I accomplish this? Thanks!
Originally Posted By: Neo
That's awesome! Works great I appreciate it. One other question though, if I only wanted the script to randomly choose from a list of specific hex codes such as (#000000, #FF00FF, #00FFFF, #FFFF00, and #FFFFFF) how would I accomplish this? Thanks!

Just change/add the six character hex codes in the VAR.

Code:
ON *:TEXT:*:#: {
  IF ($nick == $me) {
    VAR %hex 000000 FF00FF 00FFFF FFFF00 FFFFFF
    MSG $chan .color $chr(35) $+ $gettok(%hex,$rand(1,$numtok(%hex,32)),32)
  }
}
Can you get ban for using this script on Twitch with your Twitch.tv account?
Originally Posted By: Artiiz
Can you get ban for using this script on Twitch with your Twitch.tv account?


No idea. I doubt it, although it would not surprise me though as I would imagine the nickname color system was never meant to be used this way.

Anyways, I was bored, I took the code a tiny step further and now it will never repeat your current color by chance when changing colors. You'll need Twitch msgtags enabled for it to work.

Code:
ON *:TEXT:*:#: {
  IF ($nick == $me) {
    VAR %hex 000000 FF00FF 00FFFF FFFF00 FFFFFF
    VAR %hex $remtok(%hex,$remove($msgtags(color).key,$chr(35)),0,32)
    MSG $chan .color $chr(35) $+ $gettok(%hex,$rand(1,$numtok(%hex,32)),32)
  }
}
Is there anyway to make it so it doesn't repeat a color (color range) within like 10 lines of text? Just trying to make it more colorful, less colors that are almost the same would be nice.

Kind Regards,
-JumboPaperClip
© mIRC Discussion Forums