[lua] Tags
Requested by dinis.
This script is pretty much an ugly rewrite of
blam's new ignore script that lets you tag people.
Tags are shown behind the username in both the chat and the queue.
No need for clan tags or capitalization, the script handles that.
Commands are:
/tag add user tag (e.g. /tag add yoyo this is a tag)
/tag remove user - (e.g. /tag remove yoyo)
/tag list
Tags are saved and loaded automagically.
Don't put any semicolons (;) in the tags, that might break the script. I didn't really bother doing that much error handling since it was just a quick script for a friend, so please bare with that.
lua code:
local tag = {list = {}}
local w, h = get_window_size()
tag.add = function(name, tagstr)
tag.list[string.lower(name)] = tagstr
end
tag.remove = function(name)
tag.list[string.lower(name)] = nil
end
tag.save = function()
List = io.open("taglist.txt","w")
for k, v in pairs(tag.list) do
List:write(k .. ";" .. v .. "\n")
end
List:flush()
List:close()
end
tag.load = function()
listFile = io.open("taglist.txt","r")
if(listFile ~= nil) then
i = 0
while true do
line = listFile:read("*l")
if(line ~= nil) then
split = line:find(";")
if (split ~= nil) then
name = line:sub(0, split - 1)
tagstr = line:sub(split + 1)
tag.add(name, tagstr)
i = i + 1
end
else
break
end
end
echo("^08loaded ^02" .. i .. "^08 tags")
listFile:close()
end
end
tag.display = function()
local buf = " ^08* "
local alt = true
echo("^08taglist: ")
for k, v in pairs(tag.list) do
buf = buf .. (alt and "^23" or "^29") .. k .. ": " .. v
if(#buf >= 50) then
echo(buf)
buf = " ^08* "
else
buf = buf .. "^08, "
end
alt = not alt
end
if(#buf > 9) then
buf = buf:sub(0,-3)
echo(buf)
end
end
tag.load()
function stripColour(text)
return text:gsub("%^%d%d", "")
end
function split(str) --magic function that splits a string into words
local t = {}
local function helper(word) table.insert(t, word) return "" end
if not str:gsub("%w+", helper):find"%S" then return t end
end
add_hook("command", "y_tag_cmd",
function(cmd)
args = split(cmd)
if args[1] == "tag" then
local tagCmd = args[2]
if tagCmd == "add" then
tag.add(args[3], cmd:sub(10 + args[3]:len()))
tag.save()
echo("^08added ^02" .. args[3] .. "^08 to the tag list")
elseif tagCmd == "remove" then
tag.remove(args[3])
tag.save()
echo("^08removed ^02" .. args[3] .. "^08 from the tag list")
elseif tagCmd == "list" then
tag.display()
else
echo("^08unknown command")
end
return 1
end
end
)
add_hook("console", "y_tag_console",
function (so, i)
s = stripColour(so)
local tagEnd = string.find(s,"]",0)
if(tagEnd == nil) then
tagEnd = string.find(s, ")", 0)
end
nameEnd = string.find(s,">",0)
if(nameEnd ~= nil) then
if(tagEnd ~= nil and nameEnd > tagEnd) then
player = string.sub(s,tagEnd+1,nameEnd-1)
else
player = string.sub(s,2,nameEnd-1)
end
player = string.lower(player)
if(tag.list[player] ~= nil) then
echo("^07<" .. tag.list[player] .. " " .. so:sub(2))
return 1
end
end
end
)
add_hook("draw2d", "y_tag_draw2d",
function ()
i = -1
for k, bout in pairs(get_bouts()) do
i = i + 1
local tagEnd = string.find(bout, "]", 0)
if(tagEnd == nil) then
tagEnd = string.find(bout, ")", 0)
if (tagEnd == nil) then
tagEnd = -1
end
end
fixedbout = bout:sub(tagEnd + 1):lower()
if tag.list[fixedbout] ~= nil then
draw_text(tag.list[fixedbout], w - get_string_length(bout, 1) - get_string_length(tag.list[fixedbout], 1) - 45, 145 + 18*i, 1)
end
end
end
)
echo("^08tags.lua by yoyo rewritten from blam's new ignore script")
echo("^08cmds: /tag add user tag | /tag remove user | /tag list")
echo("^08don't use semicolons in tags")
Last edited by Yoyo; Sep 28, 2015 at 12:42 AM.