Help with flashing names.

So, I basically found this code (below) on this thread
Not sure if it works, but say it does. Where would I put the file in? Thanks in advanced!

local flashingRed = Color(0,0,0)
hook.Add("Think", "scoreboardcolors", function()
    local glow = math.abs(math.sin(CurTime() * 2) * 255);
    flashingRed = Color(glow, 0, 0, 255)
hook.Add("TTTScoreboardColorForPlayer", "ScoreboardColors", function(ply)
    if IsValid(ply) and ply:SteamID() == "STEAM_0:0:49420535" then
        return flashingRed

You know, It would be better leaving a comment explaining why this is “dumb”.

I’ll take a stab in the dark as to why, though I can hardly talk for everyone here.

Why make a username flash? it’s just irritating on the eyes.
a glow, or a colour “pulse” of sorts, I’d understand. but flashing? that’s just annoying.

It may look good “on paper”, but these addons are intended for the end user’s enjoyment. and many, many people don’t like flashing text in any capacity.

Problem is, it’s my server. I take the decisions. If it starts bothering the players, I’ll take it out. I just need help with this -.- Is that so hard to ask?

Of course not. I was just chipping in as to why people may think your post was “dumb”, as you wanted feedback. I assumed that’s what you were asking in the second post, rather than your rights to use this script.
In relation to the actual question, no idea. I’ll let someone else help there.

Alright; the reason it was probably rated “dumb” is because it’s using a Think hook, something ran every frame, to update the colors.

If this is for scoreboard flashing names; for example only for admins: put it in function PANEL:Think( ) at most.

Are you familiar with sine/cosine or other trigonometric functions? Are you familiar what other functions do in the code?

I’ll briefly explain, just in case. The sine wave is something that changes -1 to 1 in a smooth wave like function. I’m talking about wave in the literal sense, think of an ocean wave moving across a harbor, the wave doesn’t change in height / width but moves. The movement is along the x axis on a graph.

Depending on the value inside x assuming math.sin( x ), it will make the movement match up with a point on the graph. If you use CurTime( ) as x, or other time functions, you will see a very nice smooth ramp up and ramp down of color when applied to flashing names if done correctly. To make the change occur faster or slower, you multiply time by some number inside math.sin. Example: math.sin( CurTime( ) ) VS math.sin( CurTime( ) * 4 ). The first one would be slow-ish while the second would happen across -1 to 1 more rapidly. If you do it wrong, you’ll not see much change.

Remember the -1 to 1 piece of the puzzle? To change the height of the wave, think the wave is approaching closer to shore, multiply the entire thing. math.sin( Curtime( ) * 4 ) * 50; This allows it to travel from -50 to 50; a 100 unit distance in a smooth fashion. Now, a lot of people use math.abs, absolute value which ensures that only a positive value is returned, this reduces the range to 0-50, a 50 unit range and ensures the negative values are not returned into your function.

For example, say you want the color to go from 0 to 250, you could set the default color to 125 and multiply sin by 125 instead of 50 and then add it to the color value you wish to change; this will add, or subtract up to 125 to the color meaning you have a 250 range. You could possibly use 127.5 and get the full 255 range this way.

Alternatively, and easier to understand as a beginner to sin, multiply math.sin by 255, instead of 50 we talked about before, wrap it in math.abs which prevents - values from being used, and set that as the color you want to change.

This is what the code you provided does except in the instance where I used a multiplier of 4 with time, it uses 2:
[lua]local glow = math.abs(math.sin(CurTime() * 2) * 255);
flashingRed = Color(glow, 0, 0, 255)[/lua]

flashingRed refers to a dynamic color, something that will range from BLACK, 0,0,0,255 to RED, 255, 0,0,255

Have to help a neighbor real quick; if you have any more questions, please ask and please post the code that you’ve tried to integrate this into.

That was a very nice explanation Acecool that even I could understand (and I despise math). Could you possibly explain Cos and Tan in about the same way? Or is that a lot to ask. My apologies if it’s a poor question.