Some questions about a clan tag manager I'm thinking up

Basically, I’m trying to create a program that will take a “tag” (clan tag, etc) and make sure its applied to the clients of the associated user group (and no other clients). I’ve hashed out some code, but I’m sure I’ve got mistakes, so I’m more or less ready to release what I have and take the brunt of the “yur dum” comments now. Basically, if anyone has any thoughts as to mistakes I made, better methods for what they see, or can otherwise fill me in on questions I raise in my code’s comments, I would be grateful.

-Multi line comments don’t work in this syntax highlighter? I broke them up.
-I’m very new to lua. Would like confirmation I’m doing the tables in a way that makes sense, and for k,v in ipairs in a way that makes sense. Would something else work better?
if ( SERVER ) then
local LocalPlayer() = ply() – did I do this right? Serious lua newbie

-- put each user group as its own key in the groups table here. This default example includes the default "superadmin" and "admin" groups, and a custom "regular" group. 
    -- Include every group you have a tag for. You can also include a "group" for bots- name the group "BOT". Bots will automatically get this "[BOT]" tag. 
    -- If no "Bot" group or tag is present, no tag will append to the bot's name.
local groups = { 
		superadmin = { 
			tag = {"[SUPER]"}} -- the tag is [SUPER]. It's in quotes to denote that it is a string.
		admin = {
			tag = {"[ADMIN]"}}
		regular = {
			tag = {"[REG]"}}
		BOT = { -- The "BOT" group. If you don't want or need a bot group, just leave delete this line and the next line.
			tag = {"[BOT]"}}
			-- get the ULib users.txt file.

function getuserstxt() 
	userfile = file.Read( "Ulib/users.txt" )

-- update the users.txt file. For now I'm hooking "PlayerConnect" because I need to find a better hook (maybe SetUserGroup? Can I hook SetUserGroup? Any suggestions?)
hook.Add( "PlayerConnect", "GettheUsers", getuserstxt ) 

--create a table from the SteamIDs listed in the users.txt file. Found this at
function createuserstable ()
	for key, tab in pairs( userfile ) do
		for name, steamid in pairs( tab ) do
            SteamIDs[ steamid ] = {}
			SteamIDs[ steamid ].name = name
			SteamIDs[ steamid ].group = key
-- create the table of SteamIDs and groups to check against. Probably need a better hook than "PlayerAuthed". Any suggestions?
hook.Add( "PlayerAuthed", "CreateUsersTable", createuserstable )

-- Check the name. We'll try to add some fancy schmancy pattern stuff if we can figure it out. Hooray patterns and regular expressions!
function checkname()
	-- loop all players
	for _, ply in ipairs ( player.GetAll() )do
		if ply.IsBot() then
			-- find if their is a bot group and tag
			for k, v in ipairs do
				if goups[k] == "BOT" then
					-- concatenate the bot's name and the bot tag. 
					ply.Nick() = ply.Nick() .. tostring( groups[k].tag )

– need to loop through each group in the groups table here and check if the player’s usergroup matches a group listed in the table.
else for k, v in pairs do
– Can the first group in the groups table be referred to as groups[1]? Will that return “superadmin” in my example table?
if ply:IsUserGroup == goups[v] then
– do some string.find and string.gsub magic here to add/remove tags as necessary.
– I’ll have to make sure a user from one “taggable” group isn’t wearing tags from another group. I also have to worry about inherited groups
–(superadmins getting admin tags because they appear later in the “groups” table).
– Probably mandate that groups go from lowest inheritance to highest in the groups table to navigate that, make it not my problem.
– Otherwise I’ll have to break out of the loop as soon as I know they have no wrong tags and one appropriate tag on.

-- once again, hooking PlayerInitialSpawn because I don't know a better thing. Anything better to hook, in your opinion? I don't know, I'm a lua newbie.
hook.Add( "PlayerInitialSpawn", "CheckName", checkname )


You need to read up on using for-loops, especially the ones where you are using ipairs/pairs. The syntax is:

[lua]for key, value in pairs(table) do end[/lua]


  • there is no LocalPlayer() when you are using (SERVER), thats client side only.
  • the syntax for IsUserGroup is:


… returning a boolean.

I am at work at the moment, but I will have a closer look at this when I get home.