[DarkRP] Chat Prefixes Updated And Fixed For Gmod 13

Originally created by : !!!WARLOCK!!!
Fixed and recoded by : Tabrune
I will remove this per the original author’s request.

Version 1:
Updated for DarkRP 2.4.3.

About
Prefix Chat Tags that work with DarkRP using ULX ranks. (admin,moderator,user,etc.)

How to Install
Ctrl+F to this line “local function AddToChat(msg)”

Replace your old local function AddToChat(msg)"

Making custom tags
rank_str is the prefix shown before the players name, rank_col and bracket_col are colors obviously (RGB).

Example
[Owner]Tabrune: Yo
OwnerTabrune: YOOO
OwnerTabrune: CAN YOU HEAR ME YET?

The Code



-- DarkRP ULX Prefixes originally created by Warlock, fixed and recoded by Tabrune.
-- rank_str is the prefix shown before the players name, rank_col and bracket_col are colors obviously (RGB).
local function AddToChat(msg)
	local col1 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

	local name = msg:ReadString()
	local ply = msg:ReadEntity()
	ply = IsValid(ply) and ply or LocalPlayer()

	if name == "" or not name then
		name = ply:Nick()
		name = name ~= "" and name or ply:SteamName()
	end

	local col2 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

	local text = msg:ReadString()
    local rank_str, rank_col, bracket_col
	if ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("owner") then
        rank_str = "Owner"
        rank_col = Color( 0, 0, 232 )
        bracket_col = Color( 0, 0, 232)
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("developer") then
        rank_str = "DEV"
        rank_col = Color( 0, 0, 0 )
        bracket_col = Color( 0, 0, 0 )	
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("superadmin") then
        rank_str = "Super-Admin"
        rank_col = Color( 232, 0, 0 )
        bracket_col = Color( 232, 0, 0 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("admin") then
        rank_str = "Admin"
        rank_col = Color( 25, 25, 112 )
        bracket_col = Color( 25, 25, 112 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("moderator") then
        rank_str = "Mod"
        rank_col = Color( 0, 101, 0 )
        bracket_col = Color( 0, 101, 0 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("donor") then
        rank_str = "Donor"
        rank_col = Color( 245 ,222 ,179 )
        bracket_col = Color( 245, 222, 179 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("golddonor") then
        rank_str = "Gold"
        rank_col = Color( 255, 215, 0 )
        bracket_col = Color( 255, 215, 0 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("silverdonor") then
        rank_str = "Silver"
        rank_col = Color( 128, 128, 128 )
        bracket_col = Color( 128, 128, 128 )
    elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("respected") then
        rank_str = "VIP"
        rank_col = Color( 219, 169, 18 )
        bracket_col = Color( 219, 169, 18 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("user") then
        rank_str = "Player"
        rank_col = Color( 255, 255, 255 )
        bracket_col = Color( 255, 255, 255 )
    else
        rank_str = ""
        rank_col = Color( 255, 255, 255 )
    end
	if text and text ~= "" then
		chat.AddText(bracket_col, bracket_col  and " [" or "", rank_col, rank_str, bracket_col, bracket_col and "] " or "", col1, name, col2, ": "..text)
		if IsValid(ply) then
			hook.Call("OnPlayerChat", nil, ply, text, false, not ply:Alive())
		end
	else
		chat.AddText(col1, name)
		hook.Call("ChatText", nil, "0", name, name, "none")
	end
	chat.PlaySound()
end

Awesome thanks man

Thanks, maybe not everyone on facepunch is an asshole.

No problem… People WANT and NEEDED these they’re just to unappreciative and inconsiderate to say a simple thanks for hard work… You saved me a couple bucks… That’s for sure! :slight_smile:

Can I suggest just uploading the changed code, not the whole 600+ lines of cl_init.lua Dark RP.

Thank you for putting my name on it, i forgot about my addons, i had good addons but i don’t feel good porting them, i forgot lua sadly :frowning: i started working on C#, maybe a day i will get back to it, also thank you for porting it.

I get this error?

[ERROR] gamemodes/darkrp/entities/entities/darkrp_laws/cl_init.lua:42: attempt to call method ‘TextWrap’ (a nil value)

  1. Function - gamemodes/darkrp/entities/entities/darkrp_laws/cl_init.lua:42
  2. unknown - lua/includes/modules/usermessage.lua:87

and when I become a hobo or cop, i get this error…

[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:143: attempt to call method ‘TextWrap’ (a nil value)

Agenda - gamemodes/darkrp/gamemode/client/hud.lua:143
DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:218
unknown - gamemodes/darkrp/gamemode/client/hud.lua:328
[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:143: attempt to call method ‘TextWrap’ (a nil value)

Agenda - gamemodes/darkrp/gamemode/client/hud.lua:143
DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:218
unknown - gamemodes/darkrp/gamemode/client/hud.lua:328
[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:143: attempt to call method ‘TextWrap’ (a nil value)

Agenda - gamemodes/darkrp/gamemode/client/hud.lua:143
DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:218
unknown - gamemodes/darkrp/gamemode/client/hud.lua:328

I posted on DarkRP github, they said I fucked up, as its down to cl_init.lua

This is the problem will replacing the entire file, it will only work on that specific version of cl_init.lua - you should mark which revision this edit is targeted to or add instructions to find the function that needs to be replaced.

I just took the code, and put it into my… The actual added code works amazing… However the WHOLE file is outdated, as KillerLUA said.

-P.S KillerLUA ftw! (Big fan of your mods/addons)

Okay, I will edit the above post and just post the updated line as a snippet of the code, thank you for informing me of this issue!

Is there anywhere specific we need to add the code?

I think, this better:

How to Install
Just put in lua/autorun/ folder.

Making custom tags
Use AddPrefix function, (group, print name, rank color, bracket color).

The Code



-- DarkRP ULX Prefixes originally created by Warlock, fixed and recoded by Tabrune and modify by men232.
-- rank_str is the prefix shown before the players name, rank_col and bracket_col are colors obviously (RGB).
if SERVER then
	AddCSLuaFile();
	return;
end;

local stored = {};
local meta = FindMetaTable( "Player" );
local haveNiceFunc = meta.GetUserGroup != nil;

local function AddPrefix( group, name, color, bracket_col )
	if (group and name and color) then
		stored[group] = { name = name, color = color, bracket_col = bracket_col };
	end;
end;

local function AddToChat(msg)
	local col1 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

	local name = msg:ReadString()
	local ply = msg:ReadEntity()
	ply = IsValid(ply) and ply or LocalPlayer()

	if name == "" or not name then
		name = ply:Nick()
		name = name ~= "" and name or ply:SteamName()
	end

	local col2 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

	local text = msg:ReadString()
    local rank_str, rank_col, bracket_col
	
	if (IsValid(ply) and ply:IsPlayer()) then
		if (!haveNiceFunc) then
			for group, v in pairs(stored) do
				if (ply:IsUserGroup(group)) then
					rank_str = v.name;
					rank_col = v.color;
					bracket_col = v.bracket_col or v.color;
					break;
				end;
			end;
		else
			local group = ply:GetUserGroup();
			local v = stored[group];
			if (v) then
				rank_str = v.name;
				rank_col = v.color;
				bracket_col = v.bracket_col or v.color;
			else
				rank_str = "";
				rank_col = Color( 255, 255, 255 );
			end;
		end;
	else
        rank_str = "";
        rank_col = Color( 255, 255, 255 );
	end;
	
	if text and text ~= "" then
		chat.AddText(bracket_col, bracket_col  and " [" or "", rank_col, rank_str, bracket_col, bracket_col and "] " or "", col1, name, col2, ": "..text)
		if IsValid(ply) then
			hook.Call("OnPlayerChat", nil, ply, text, false, not ply:Alive())
		end
	else
		chat.AddText(col1, name)
		hook.Call("ChatText", nil, "0", name, name, "none")
	end
	chat.PlaySound()
end

timer.Simple(1, function()
	usermessage.Hook("DarkRP_Chat", AddToChat);
end);

-- Add Prefixes (group, print name, rank color, bracket color).
AddPrefix( "owner", "Owner", Color(0, 0, 232), Color(0, 0, 232) );
AddPrefix( "developer", "DEV", Color(0, 0, 0), Color(0, 0, 0) );
AddPrefix( "superadmin", "Super-Admin", Color(232, 0, 0), Color(232, 0, 0) );
AddPrefix( "admin", "Admin", Color(25, 25, 112), Color(25, 25, 112) );
AddPrefix( "moderator", "Mod", Color(0, 101, 0), Color(0, 101, 0) );
AddPrefix( "donor", "Donor", Color(245 ,222 ,179), Color(245 ,222 ,179) );
AddPrefix( "golddonor", "Gold", Color(255, 215, 0), Color(255, 215, 0) );
AddPrefix( "silverdonor", "Silver", Color(128, 128, 128), Color(255, 215, 0) );
AddPrefix( "respected", "VIP", Color(219, 169, 18), Color(219, 169, 18) );
AddPrefix( "user", "Player", Color(255, 255, 255), Color(255, 255, 255) );


If someone can confirm that this works, I will use it!

I can :slight_smile:

It works a charm. Thank you mr men232 <3

Thank you for telling me what I want and need.

-Snip-

How do I install this?

Will this work on other gamemodes as well? or just DarkRP?

Eh, might give it a try to find out for myself.

Damnit, this is what you do when you bump an old thread.

[lua]

local RankOptions = {
[“owner”] = {
PrintName = “Owner”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“developer”] = {
PrintName = “DEV”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“superadmin”] = {
PrintName = “Super-Admin”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“admin”] = {
PrintName = “Admin”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“moderator”] = {
PrintName = “Mod”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“donor”] = {
PrintName = “Donor”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“golddonor”] = {
PrintName = “Gold”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“silverdonor”] = {
PrintName = “Silver”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“user”] = {
PrintName = “VIP”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
},
[“unknown”] = {
PrintName = “N/A”,
RankCol = Color(0,0,0),
BracketCol = Color(0,0,0)
}

}

local function AddToChat(msg)
local col1 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

local name = msg:ReadString()
local ply = msg:ReadEntity()
ply = IsValid(ply) and ply or LocalPlayer()

if name == "" or not name then
	name = ply:Nick()
	name = name ~= "" and name or ply:SteamName()
end

local col2 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

local text = msg:ReadString()
local OtherRank = table.Copy(RankOptions["unknown"]);
local rank_str, rank_col, bracket_col

	RankOptions["unknown"] = nil;
	
if ply then
	for k, v in pairs(RankOptions) do
		if ply:IsUserGroup(k) then
			rank_str, rank_col, bracket_col = v.PrintName, v.RankCol, v.BracketCol;
		end
	end
else
	rank_str, rank_col = OtherRank.PrintName, OtherRank.RankCol;
end	

if text and text ~= "" then
	chat.AddText(bracket_col, bracket_col  and " [" or "", rank_col, rank_str, bracket_col, bracket_col and "] " or "", col1, name, col2, ": "..text)
	if IsValid(ply) then
		hook.Call("OnPlayerChat", nil, ply, text, false, not ply:Alive())
	end
else
	chat.AddText(col1, name)
	hook.Call("ChatText", nil, "0", name, name, "none")
end
chat.PlaySound()

end
[/lua]