I have been working on this one for awhile now. When the initialization function (TagInit) is called it reads the contents of tagtable.txt into a string, but it is always nil, and yes it has information in it. I will include the whole lua file because i know you will probally need it. Please excuse the amateur level of my code and how disgusting you may find it.
[Lua]AddCSLuaFile("autorun/tagsv2.lua")
if (SERVER) then
taglist = {} -- Holds tags for reference
function TagInit()
local text = file.Read("tags/tagtable.txt")
taglist = string.Explode(" ", text) --string is split at spaces and added to gvar taglist
end
hook.Add( "InitPostEntity", "Tag Initialization", TagInit ) -- called when map loads
function TagQuery( uniqueid )
PrintTable(taglist)
local key = table.KeyFromValue(taglist, uniqueid) -- parses table for index of Unique id
umsg.Start("playertagsend") -- begins usermessage "playertagsend"
umsg.String(taglist[key+1])
umsg.Short(tonumber(taglist[key+2])) --converts text to number
umsg.Short(tonumber(taglist[key+3]))
umsg.Short(tonumber(taglist[key+4]))
umsg.End()
end
concommand.Add( "player_tag_query", TagQuery ) --links to console command to be called by the user
function TagSaveText( data ) -- called by console command from derma
local entry = string.split(data, " ")
local key = table.KeyFromValue(taglist, entry[1])
taglist[key+1] = table.concat(entry,".",2, table.maxn(entry))
local text = table.concat(taglist, " ")
file.Write("tags/tagtable.txt", text)
end
concommand.Add( "player_tag_text_set", TagSaveText )
function TagSaveColor( data ) -- called by console command from derma
local entry = string.split(data, " ")
local key = table.KeyFromValue(taglist, entry[1])
taglist[key+2] = entry[2]
taglist[key+3] = entry[3]
taglist[key+4] = entry[4]
local text = table.concat(taglist, " ")
file.Write("tags/tagtable.txt", text)
end
concommand.Add( "player_tag_color_set", TagSaveColor )
end
if (CLIENT) then
playerText = " " -- Using globals to avoid a variable function dive, I know its bad.
isPlayerDead = false
pl = nil
isTeamChat = false
-- Group Attributes you can add new groups to this table. They should follow this format:
-- ["<ulxgroupname>"] = {"<displayed tag text>", <red>, <green>, <blue>}
groupAttributes = {
["dev"] = {"(Developer)", 0, 0, 255},
["admin"] = {"(Admin)", 255, 0, 0},
["superadmin"] = {"(Super Admin)", 236, 88, 0},
["owner"] = {"(Owner)", 0, 0, 0},
["operator"] = {"(Operator)", 102, 255, 255},
["manager"] = {"(Manager)", 178, 34, 34}
}
-- function called to intercept chat and modify how I would like
-- code will determine group of player through ulx getusergroup
function InsertTags( ply, msg, teamChat, isDead )
if not ply:IsValid() then return end
local uniqueid = ply:SteamID()
local group = ply:GetUserGroup()
if group == "vip" then -- checks for group then updates gvars xfers hook values to gvars
playerText = msg
isPlayerDead = isDead
pl = ply
isTeamChat = teamChat
ply:ConCommand("player_tag_query "..uniqueid) -- asks server to send client vip information
return true -- exits this function as we no longer need to continue here
end
local tab = {}
if isDead then
table.insert(tab, Color(255,0,0,255))
table.insert(tab, "DEAD ")
end
groupCurrent = groupAttributes[group] --selects groupAttributes for the current group
local text = groupCurrent[1]
local red = groupCurrent[2]
local green = groupCurrent[3]
local blue = groupCurrent[4]
table.insert(tab, Color(red, green, blue)) --puts vip data into chattable
table.insert(tab, text.." ")
if teamChat then -- if team chat make yellow if not green
table.insert(tab, Color(204,204,0))
else
table.insert(tab, Color(0,255,0))
end
table.insert(tab, ply:Nick()) -- adds player nickname
table.insert(tab, Color(255,255,255)) --changes color back to white
table.insert(tab, ": ")
table.insert(tab, msg)
chat.AddText( unpack(tab) ) -- unpacks chat table
return true
end
hook.Add("OnPlayerChat", "InsertTags", InsertTags) -- called on client when player speaks
function recieveVipTag( um )
local tab = {}
--inteperets usermessage
local text = um:ReadString()
local red = um:ReadShort()
local green = um:ReadShort()
local blue = um:ReadShort()
-- Expands the text that was concatenated with periods IE: Bad.Ass.Magee
local newText = string.gsub(text, ".", " ")
-- See documentation in InsertTags(Im too lazy to do it again)
if isPlayerDead then
table.insert(tab, Color(255,0,0,255))
table.insert(tab, "DEAD ")
end
table.insert(tab, Color(red, green, blue))
table.insert(tab, text.." ")
if isTeamChat then
table.insert(tab, Color(204,204,0))
else
table.insert(tab, Color(0,255,0))
end
table.insert(tab, pl:Nick())
table.insert(tab, Color(255,255,255))
table.insert(tab, ": ")
table.insert(tab, playerText)
chat.AddText( unpack(tab) )
end
usermessage.Hook("playertagsend", recieveVipTag) --hooks into usermessage
end[/Lua]
and here is the only entry that is in the tagtable.txt:
STEAM_0:0:17494584 I.Am.The.Boss 0 100 100
I've narrowed it down to the file path. The end is near.
The file was accidentally called tagtable.txt.txt DAMN you text files...
Sorry, you need to Log In to post a reply to this thread.