When players are dead they get the owner tag?


function ChatTags(ply, Text, Team, PlayerIsDead)

 if ply:IsPlayer() then
  local group = ply:GetUserGroup()
  local nickteamcolor = team.GetColor(ply:Team())
 // tag = ""
 // col = Color(0,0,0,255)
if ply:Alive() then
 if group == "user" then
            tag = UserTag.." " 
			col = UserColor
    //     if (string.sub(Text, 1, 4) == "/ooc") then
	//	 print( "ooc" )
	//		chat.AddText(UserColor, "[User] (OOC) ", nickteamcolor , ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
		//	return true
		//	else
			chat.AddText(UserColor, UserTag.." " , nickteamcolor , ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			return true
	//	end
    end
	
	if group == "vip" || group == "VIP" then
			chat.AddText(VIPColor, VIPTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = VIPTag.." " 
			col = VIPColor
			return true
    end
	
	if group == "moderator"  || group == "Moderator"then
			chat.AddText(ModeratorColor, ModeratorTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = ModeratorTag.." " 
			col = ModeratorColor
			return true
    end
	
	 if group == "admin"  || group == "Admin"then
			chat.AddText(AdminColor, AdminTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = AdminTag.." " 
			col = AdminColor
			return true
    end
	
	
	 if group == "superadmin" || group == "Superadmin" || group == "SuperAdmin"  then
			chat.AddText(SuperAdminColor, SuperAdminTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = SuperAdminTag.." "
			col = SuperAdminColor
			return true
    end
	
	if group == "owner" || group == "Owner" then
			chat.AddText(OwnerColor, OwnerTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = OwnerTag.." " 
			col = OwnerColor
			return true
    end
	
	if group == "trialadmin" || group == "Trialadmin" then
			chat.AddText(TrialColor, TrialTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = TrialTag.." " 
			col = TrialColor
			return true
    end
	
	if group == "coowner" || group == "Coowner" then
			chat.AddText(CoownerColor, CoownerTag.." " , nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
			tag = CoownerTag.." " 
			col = CowonerColor
			return true
    end
		
    end
   
   if !ply:Alive() then
   chat.AddText(Color(30,30,30,255), "[DEAD] ",col, tag, nickteamcolor,  ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
   return true
   end
   
   
 end
 

end
hook.Add("OnPlayerChat", "DaedricChatTags", ChatTags)

Screenshot of the glitch in action:

Note that this only happens when people chat while dead, and it always defaults to giving them the owner tag.

Can anybody help me on this?

For the love of God, look up what elseif and string.lower is.

I’m sorry I’m not good at scripting :frowning: I’m not really sure what you mean.

Doing an || statement for each group is pointless when you could just do string.lower and get the lowercase string immediately. Also, you don’t have to make a bunch of separate if-statements, but instead, link them with elseif. Google for the specific syntax.

I diddn’t code this :frowning: I’m modifying it.

Why the hell are you checking if the player is alive so many times? It makes no sense, this has to be the messiest script I have ever seen.
Also hint hint one of your live checks may be fucking it up, but I honestly can’t tell because I’m on mobile and so nothing is indented properly.

As I stated before I did not code this. I cannot code at all. I could not even begin to make a script like this…

I feel whoever created this is on the same boat as you, when I get on my PC I’ll be able to tell you the problem.

Alright thank you very much :slight_smile:

Messy and inefficient code aside, simply changing the order of your logic should work, by checking if the player is dead first.

[lua]
if !ply:Alive() then
chat.AddText(Color(30,30,30,255), "[DEAD] ",col, tag, nickteamcolor, ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), Text)
return true
end

if ply:Alive() then
[/lua]

Here is my attempt using a lookup table to eliminate all of the if/elseifs.

I’ve tested it on my server using my own colors/tags for testing and it seems to work fine.



local tags = {
    user       = { Color = UserColor,       Tag = UserTag       },
    vip        = { Color = VIPColor,        Tag = VIPTag        },
    moderator  = { Color = ModeratorColor,  Tag = ModeratorTag  },
    trialadmin = { Color = TrialColor,      Tag = TrialTag      },
    admin      = { Color = AdminColor,      Tag = AdminTag      },
    superadmin = { Color = SuperAdminColor, Tag = SuperAdminTag },
    coowner    = { Color = CoownerColor,    Tag = CoownerTag    },
    owner      = { Color = OwnerColor,      Tag = OwnerTag      },
}



local color_dead = Color( 30, 30, 30 )



function ChatTags( ply, text, isTeam, isDead )

    if ( IsValid( ply ) ) then -- ignores console's chat

        local tagData = tags[ ply:GetUserGroup():lower() ] or tags[ 'user' ] -- default to 'user' if they aren't in a valid usergroup
        
        chat.AddText( isDead and color_dead or nil, isDead and "[DEAD] " or nil, tagData.Color, tagData.Tag .. " ", ply, color_white, ": " .. text )
        
        return true

    end
    
end
hook.Add( "OnPlayerChat", "DaedricChatTags", ChatTags )


If you give it a try and have any issues, feel free to post them / PM me and I’ll help further.

There is an issue with this



[ERROR] addons/chattags2/lua/autorun/cl_chat_tags.lua:24: attempt to concatenate field 'Tag' (a nil value)
  1. fn - addons/chattags2/lua/autorun/cl_chat_tags.lua:24
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183


That’s because you have to change the table values to what you want; UserTag is just a placeholder.

I just assumed that you had all of those tags and colors defined already. For example, using them as globals from a different file, or creating them somewhere before the code you pasted. I just based this on the image you posted that shows you **do **have the Owner tag defined.

Do you mind showing the bit of code where all of the tags and colors are created?

Based on the line number he probably just copied over the entire file with your code.

The tags and colors could have been defined in a different file, which is the likely case considering the screenshot BlushBerry provided that shows at least OwnerColor/OwnerTag are defined.

Client:


local tags = {
    user       = { Color = UserColor,       Tag = UserTag       },
    vip        = { Color = VIPColor,        Tag = VIPTag        },
    moderator  = { Color = ModeratorColor,  Tag = ModeratorTag  },
    trialadmin = { Color = TrialColor,      Tag = TrialTag      },
    admin      = { Color = AdminColor,      Tag = AdminTag      },
    superadmin = { Color = SuperAdminColor, Tag = SuperAdminTag },
    coowner    = { Color = CoownerColor,    Tag = CoownerTag    },
    owner      = { Color = OwnerColor,      Tag = OwnerTag      },
}



local color_dead = Color( 30, 30, 30 )



function ChatTags( ply, text, isTeam, isDead )

    if ( IsValid( ply ) ) then -- ignores console's chat

        local tagData = tags[ ply:GetUserGroup():lower() ] or tags[ 'user' ] -- default to 'user' if they aren't in a valid usergroup
        
        chat.AddText( isDead and color_dead or nil, isDead and "[DEAD] " or nil, tagData.Color, tagData.Tag .. " ", ply, color_white, ": " .. text )
        
        return true

    end
    
end
hook.Add( "OnPlayerChat", "DaedricChatTags", ChatTags )

Tags I think:



UserColor = Color(0,255,0, 255)
VIPColor = Color(255,255,0, 255)
ModeratorColor = Color(0,0,255, 255)
AdminColor = Color(255,128,64, 255)
SuperAdminColor = Color(255,0,0, 255)
OwnerColor = Color(255,100,150, 255)
TrialColor = Color(0,240,240, 255)
CoownerColor = Color(146,36,255, 255)

UserTag = "[User]"
VIPTag = "[VIP]"
ModeratorTag = "[Moderator]"
AdminTag = "[Admin]"
SuperAdminTag = "[SuperAdmin]"
OwnerTag = "[Owner]"
TrialTag = "[Trial Admin]"
CoownerTag = "[Co-Owner]"


server:


AddCSLuaFile( "cl_chat_tags.lua"  )
AddCSLuaFile( "customizer.lua"  )

Thank you for the information, BlushBerry.

I’ve tested my script with your tag/colors and it appears to work fine for the each of the user groups.

My next guess is that you may be loading the cl_chat_tags.lua file prior to the colors and tags being created.

Does your customizer.lua file contain the colors and tags you posted?

If so, try switching the order that you load the scripts, i.e.:


AddCSLuaFile( "customizer.lua"  ) -- load tag/colors first
AddCSLuaFile( "cl_chat_tags.lua"  ) -- now load the OnPlayerChat hook function to use them


I will give it a try give me one moment to lock up my server.

[editline]24th August 2014[/editline]

When I switched those around this came up



[ERROR] addons/chattags2/lua/autorun/cl_chat_tags.lua:24: attempt to concatenate field 'Tag' (a nil value)
  1. fn - addons/chattags2/lua/autorun/cl_chat_tags.lua:24
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183


My mistake, I didn’t even think to ask about the **order they are being included on the client. Switching the AddCSLuaFile part won’t really have any effect.

Can you first absolutely confirm that the colors and tags you posted are being created in the customizer.lua file? If you can, please try to find the spot in the client files (maybe something like cl_init.lua?) where there is something like this:


include( "cl_chat_tags.lua" )
include( "customizer.lua" )

If it’s loading them in that exact order, you’ll need to switch them so customizer.lua is *included *first.

I apologize if I’m barking up the entirely wrong tree. I’m just trying to go off of what I can tell.

The whole problem just appears to be the script loading order. If the tags and colors aren’t created before the cl_chat_tags.lua script loads, it’ll cause that error you are getting because they didn’t exist at that time.