TTT - Multiple Groups with Rainbow Names

Hey there, I’m terrible at lua, all I know is how to change the group names in codes so sorry for being so dumb .-.

Basically I want to have this code so i can have multiple groups with the rainbow name, i tried adding them into the brackets as well as copying the section again with different group names but neither of them worked. Any help will be appreciated.

Here is the code:

It’s the

bit that does the rainbow colour <3

What addon are you using for your scoreboard, if any?

Hey, welcome to FacePunch. This forum is for devs that need help working on things. Here are some resources to help you get started:

Generalized Lua Help ( Links to Wikis, Answers the question of “Where do I post a simple question or DarkRP Specific question”, links to other resources compiled by forum members )
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_general_lua_learning.lua.html

Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_useful_programs_and_notepadpp_upgrades.lua.html

AcecoolDev_Base Skeletonized Dev Base Game-Mode ( Never worry about Include or AddCSLuaFile ever again; comes with New Hooks, Console Commands, Meta-Table Objects, Helper Functions, Extended Functionality, and more! )
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_acecooldev_base_gamemode_info.lua.html

There is already a function that handles rainbow names… HSV to color and back; useful function, cycles through all colors:

If you want rainbow text ( static, but can be made dynamic ): https://dl.dropboxusercontent.com/u/26074909/_server/code/MSGRainbow.lua – Be sure to look at the first link at the top to see photos…

Now… For your question… Do something like this for rainbow name; this lets you set multiple groups to use a rainbow name without needing a huge if, elseif, elseif, else… logic tree…:


// Groups that get rainbow names; all lowercase... If group is non-simple string as shown below you'd need [""] = true instead of just simple_string = true;
local RainbowGroups = {
	[ "non simple string group"] = true;
	admin 		= true;
	donator 	= true;
	superadmin 	= true;
	vip 		= true;
	guest 		= false;
};

// Get player groups, _p should be your player var
local _group = string.lower( _p:GetNWString( "UserGroup" ) );
if ( RainbowGroups[ _group ] ) then
	-- Apply the rainbow code...
end

NWVars are expensive, I’d recommend caching, kind of like what I did in this function: https://dl.dropboxusercontent.com/u/26074909/tutoring/_gm_specific_darkrp/darkrp_customcheck_isvip_via_list_or_group_or_admin_check.lua.html

Hopefully these tutorials and information helps. As always, to view the Lua from any of my tutorials to enable copy/pasting ( HTML doesn’t copy/paste well in terms of HTML / CSS Highlighted Lua ), remove .html from the url.

He didn’t use NWVars anywhere?

Just do something like this:


local ColorGroups = {
   admin = Color( 255, 255, 5 ),
   superadmin = Color( 1, 5, 7 ),
   -- etc.
}

local realtime = CurTime()
local time = realtime - 0.1 
local r = math.abs( math.sin( time * 2 ) * 255 )
local g = math.abs( math.sin( time * 2 + 2 ) * 255 )
local b = math.abs( math.sin( time * 2 + 4 ) * 255 )

function GroupColors()
   if ( string.lower( ply:GetNWString( "usergroup" ) ) == "bantmin" ) then 
      return Color(r,g,b)
   else
      return ColorGroups[ ply:GetNWString( "usergroup" ) ] or Color( 255, 255, 255 )
   end
end

Thanks for the help guys. I’m sorry but I’m going to have to ask what to do with the code that you guys have posted, shall I add it in somewhere? Shall I replace the code that I have with it? Or shall i just replace a certain bit of the code I’m using.

I should probably say that it’s a ‘scoreboardcolours.lua’ that has been placed in garrysmod\lua\autorun.

I’m using TTT-EasyScoreBoard Master, i’m pretty sure it doesn’t effect the name colour.

Yes, it does.

You should see lines similar to this:
[lua]
EZS.Ranks[“member”] = { name = “Member”, color = Color(0, 102, 102), admin = false }
[/lua]

Where it says
[lua]
color = Color(0,102,102)
[/lua]
replace that with
[lua]
color = “rainbow”
[/lua]

But that would do the rank names, I want the player names to be in rainbow. Thanks anyway :smiley:

In hindsight I probably should have made it clear, for that I apologize.

just do
[LUA]namecolor = “rainbow”[/LUA]
instead of color

IsUserGroup; doesn’t that do a compare against the NWVar UserGroup? So, a big stack of elseifs will call it up to n times which is why it is good to grab it once, keep it cached for a minimum time, then compare against a direct-entry table. If the same logic needed to be ran again within the minimum time, it wouldn’t re-obtain the NWVar, but use the cached version…

In that case, he can just replace it with GetNWString. I thought IsUserGroup worked by still calling GetNWString, then seeing if it matched the IsUserGroup string.