Hey guys so I'm making a chat tag addon for TTT and it works perfectly so far but the problem is that I can't tell if it works for multiple players.
Let me explain what that means...
Basically the addon allows users to enter a custom chat tag that appears beside their name when they type in chat, and stores their tag in sv.db using PData.
I don't know how to test if the tags are actually visible to all players or only to the local player because I don't know how to port forward a server and I don't want to pay for a test server.
Could you guys tell me if you think this would work or not?
Client side:
-- [[ Custom Chat Tags ]] ----------------------------
-- [[ Created by: Wilks ]] ---------------------
-- Clientside File
--------------- [[ TO DO ]] ---------------
-- 1) Add working color mixer.
-- 2) Allow players to change rank color.
-- 3) Clean up derma and make it look nice.
-- 4) Restrict access to non-donators.
-------------------------------------------
local tag = {}
--fetch player tag info
net.Receive("CustomTagInfo", function(length)
tag.CustomTag = net.ReadString()
end)
--client gets message from server, deletes tag
net.Receive("CustomTagDeleted", function(length)
tag.CustomTag = nil
end)
local errorColor = Color(255, 0, 0, 255)
local ply = LocalPlayer()
local pMeta = FindMetaTable("Player")
function pMeta:MenuOpen()
local frame = vgui.Create("DFrame")
frame.width = 390
frame.height = 390
frame:SetSize(frame.width, frame.height)
frame:SetPos(400, 500)
frame:MakePopup()
frame:SetTitle("Boujee TTT Custom Tags")
-- Set Tag button
local tagButton = vgui.Create("DButton", frame)
tagButton.width = 110
tagButton.height = 25
tagButton.x = 25
tagButton.y = 50
tagButton:SetSize(tagButton.width, tagButton.height)
tagButton:SetPos(tagButton.x, tagButton.y)
tagButton:SetText("Set Tag")
--Tag text entry
local tagEntry = vgui.Create("DTextEntry", frame)
tagEntry.x = tagButton.x + 134
tagEntry.y = tagButton.y + 2
tagEntry:SetPos(tagEntry.x, tagEntry.y)
tagEntry:SetSize(180, 20)
tagEntry:SetUpdateOnType(true)
tagEntry:SetText("Enter Custom Tag")
tagEntry.OnValueChange = function(self)
tagEntry.value = self:GetValue()
end
--Remove tag button
local delTagButton = vgui.Create("DButton", frame)
delTagButton.width = 110
delTagButton.height = 25
delTagButton.x = tagButton.x + 66
delTagButton.y = tagButton.y + 50
delTagButton:SetSize(tagButton.width, tagButton.height)
delTagButton:SetPos(delTagButton.x, delTagButton.y)
delTagButton:SetText("Delete Tag")
-- Set tag button is pressed
tagButton.DoClick = function()
if tagEntry.value then
--send tag info to server
net.Start("tagButtonPressed")
net.WriteString(tagEntry.value)
net.SendToServer()
chat.AddText(errorColor, "[Tags] ", color_white, "You have set your tag to ", tagEntry.value, ".")
else
chat.AddText(errorColor, "[Tags] Error: ", color_white, "Please enter a valid tag.")
end
end
--deltag button is pressed
delTagButton.DoClick = function()
chat.AddText(errorColor, "[Tags] ", color_white, "You have removed your tag.")
net.Start("delTagButtonPressed")
net.WriteBool(true)
net.SendToServer()
end
end
--Playerchat Hook
hook.Add("OnPlayerChat", "PlayerChat", function( ply, text, Team, PlayerIsDead )
if text == "!tags" then
if ply == LocalPlayer() then -- check if the player who typed !text is local player
pMeta:MenuOpen() -- if yes then open the menu
end
return true
end
if tag.CustomTag then
for k, v in pairs(player.GetAll()) do
chat.AddText(color_white, "[", tag.CustomTag, "] ", ply:Nick(), ": ", text)
return true
end
else
for k, v in pairs(player.GetAll()) do
chat.AddText(color_white, ply:Nick(), ": ", text)
return true
end
end
end )
Server side:
-- Serverside File
util.AddNetworkString("tagButtonPressed")
util.AddNetworkString("CustomTagInfo")
util.AddNetworkString("delTagButtonPressed")
util.AddNetworkString("CustomTagDeleted")
--save player tag to database (sv.db)
net.Receive("tagButtonPressed", function(length, ply)
local plyTag = net.ReadString()
ply:SetPData("player_CustomTag", plyTag)
MsgC(Color(255, 0, 255, 255), "[CHAT-TAGS] ", color_white, ply:Nick(), "(", ply:SteamID(), ") has changed their custom chat tag to [", plyTag, "].\n") --print to server
end )
--remove player tag from the database (sv.db)
net.Receive("delTagButtonPressed", function(length, ply)
local removePlayerTag = net.ReadBool()
ply:RemovePData("player_CustomTag")
MsgC(Color(255, 0, 255, 255), "[CHAT-TAGS] ", color_white, ply:Nick(), "(", ply:SteamID(), ") has removed their custom chat tag.\n") --print to server
net.Start("CustomTagDeleted")
net.Send(ply)
end)
--send tag info to client on player chat
hook.Add("PlayerSay", "SendClientTagInfo", function(ply, textStr, teamChat)
local plyTag = ply:GetPData("player_CustomTag", nil)
if plyTag then
net.Start("CustomTagInfo")
net.WriteString(plyTag)
net.Send(ply)
end
end)
You just had to change the message string in the hook, why are you sending a net message?
Would it make more sense to use net.Broadcast() instead of net.Send(ply)?
It wouldn't make sense to have a net message at all.
Try Entity/SetNWString for the tag
hook.Add("OnPlayerChat", "tag_menu_command_listener", function(ply, text)
if not (text == "!tags" and ply == LocalPlayer()) then return false end
pMeta:MenuOpen()
return true
end)
hook.Add("OnPlayerChat", "implement_custom_tag", function(ply, text, isteamchat)
if not IsValid(ply) then return true end
local team = ""
if isteamchat then team = "(Group) " end
local custom_tag = ply:GetNWString("custom_chat_tag", "")
if custom_tag ~= "" then custom_tag = "[" .. custom_tag .. "] " end
local custom_tag_color = ply:GetNWVector("custom_chat_tag_color", Color(0, 0, 0))
if isvector(custom_tag_color) then custom_tag_color = Color(custom_tag_color.x, custom_tag_color.y, custom_tag_color.z) end
chat.AddText(Color(230, 230, 230), team, custom_tag_color, custom_tag, Color(230, 230, 230), ply:Nick() .. ": " .. text)
return true
end)
kind of a wild idea to use a networked vector as a replacement for the lack of networked color, but fuck it.
in case the website code viewer disappoints like always
Entity/SetNWVector
Entity/SetNWString
Fuck I thought there was a server-side hook for chat. That's weird. Ignore what I said.
Sorry, you need to Log In to post a reply to this thread.