Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to give More People Colored Chat in this Way?

Asked by 6 years ago

-- // FileName: ExtraDataInitializer.lua -- // Written by: Xsitsu -- // Description: Module that sets some basic ExtraData such as name color, and chat color.

local SpecialChatColors = { Groups = { { --- ROBLOX Interns group GroupId = 2868472, Rank = 100, ChatColor = Color3.new(175/255, 221/255, 1), }, { --- ROBLOX Admins group GroupId = 1200769, ChatColor = Color3.new(1, 215/255, 0), }, }, Players = { { --- Left as an example UserId = 275193222, ChatColor = Color3.fromRGB(39, 232, 5)

        UserId = 321133177,
        ChatColor = Color3.fromRGB(170, 0, 170)
    }
}

}

local function MakeIsInGroup(groupId, requiredRank) assert(type(requiredRank) == "nil" or type(requiredRank) == "number", "requiredRank must be a number or nil")

return function(player)
    if player and player.UserId then
        local userId = player.UserId

        local inGroup = false
        local success, err = pcall(function() -- Many things can error is the IsInGroup check
            if requiredRank then
                inGroup = player:GetRankInGroup(groupId) > requiredRank
            else
                inGroup = player:IsInGroup(groupId)
            end
        end)
        if not success and err then
            print("Error checking in group: " ..err)
        end

        return inGroup
    end

    return false
end

end

local function ConstructIsInGroups() if SpecialChatColors.Groups then for _, group in pairs(SpecialChatColors.Groups) do group.IsInGroup = MakeIsInGroup(group.GroupId, group.Rank) end end end ConstructIsInGroups()

local Players = game:GetService("Players")

function GetSpecialChatColor(speakerName) if SpecialChatColors.Players then local playerFromSpeaker = Players:FindFirstChild(speakerName) if playerFromSpeaker then for _, player in pairs(SpecialChatColors.Players) do if playerFromSpeaker.UserId == player.UserId then return player.ChatColor end end end end if SpecialChatColors.Groups then for _, group in pairs(SpecialChatColors.Groups) do if group.IsInGroup(Players:FindFirstChild(speakerName)) then return group.ChatColor end end end end

local function Run(ChatService) local NAME_COLORS = { Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color, Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color, Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color, BrickColor.new("Bright violet").Color, BrickColor.new("Bright orange").Color, BrickColor.new("Bright yellow").Color, BrickColor.new("Light reddish violet").Color, BrickColor.new("Brick yellow").Color, }

local function GetNameValue(pName)
    local value = 0
    for index = 1, #pName do
        local cValue = string.byte(string.sub(pName, index, index))
        local reverseIndex = #pName - index + 1
        if #pName%2 == 1 then
            reverseIndex = reverseIndex - 1
        end
        if reverseIndex%4 >= 2 then
            cValue = -cValue
        end
        value = value + cValue
    end
    return value
end

local color_offset = 0
local function ComputeNameColor(pName)
    return NAME_COLORS[((GetNameValue(pName) + color_offset) % #NAME_COLORS) + 1]
end

local function GetNameColor(speaker)
    local player = speaker:GetPlayer()
    if player then
        if player.Team ~= nil then
            return player.TeamColor.Color
        end
    end
    return ComputeNameColor(speaker.Name)
end

ChatService.SpeakerAdded:connect(function(speakerName)
    local speaker = ChatService:GetSpeaker(speakerName)
    if not speaker:GetExtraData("NameColor") then
        speaker:SetExtraData("NameColor", GetNameColor(speaker))
    end
    if not speaker:GetExtraData("ChatColor") then
        local specialChatColor = GetSpecialChatColor(speakerName)
        if specialChatColor then
            speaker:SetExtraData("ChatColor", specialChatColor)
        end
    end
    if not speaker:GetExtraData("Tags") then
        --// Example of how you would set tags
        --[[
        local tags = {
            {
                TagText = "VIP",
                TagColor = Color3.new(1, 215/255, 0)
            },
            {
                TagText = "Alpha Tester",
                TagColor = Color3.new(205/255, 0, 0)
            }
        }
        speaker:SetExtraData("Tags", tags)
        ]]
        speaker:SetExtraData("Tags", {})
    end
end)

local PlayerChangedConnections = {}
Players.PlayerAdded:connect(function(player)
    local changedConn = player.Changed:connect(function(property)
        local speaker = ChatService:GetSpeaker(player.Name)
        if speaker then
            if property == "TeamColor" or property == "Neutral" or property == "Team" then
                speaker:SetExtraData("NameColor", GetNameColor(speaker))
            end
        end
    end)
    PlayerChangedConnections[player] = changedConn
end)

Players.PlayerRemoving:connect(function(player)
    local changedConn = PlayerChangedConnections[player]
    if changedConn then
        changedConn:Disconnect()
    end
    PlayerChangedConnections[player] = nil
end)

end

return Run how i make now that More People can get Colored Chat?

0
I suggest you make your own code instead of using others so you learn how to script and won't get confused with scripts this huge. awesomeipod 607 — 6y

2 answers

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

local userColors = {
    ['275193222'] = Color3.fromRGB(170, 0, 170),
    --^this is the userid,
    ['321133177'] = Color3.fromRGB(255,0,0),
}

game:GetService("Players").PlayerAdded:connect(function(plr)
    if userColors[tostring(plr.UserId)] then
        ChatService:GetSpeaker(plr.Name):SetExtraData("ChatColor", userColors[tostring(plr.UserId)])
    end
end)
0
What folder then? mistergamer100 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Players = { { --- Left as an example UserId = 275193222, ChatColor = Color3.fromRGB(39, 232, 5)

        UserId = 321133177,
        ChatColor = Color3.fromRGB(170, 0, 170)

Please tell me How to do that , how more people could get that?

0
huh? fromRGB is a thing you know... greatneil80 2647 — 6y

Answer this question