• Client-Side Title System
    6 replies, posted
OMYGOSH ANOTHER USELESS SCRIPT!!! -- Background info on this script -- After a few hours of toiling away at this big project i have been working on. I decided to implement a small 'title' like system. It's my first ever peice of script that i've ever saved values using txt files, and part of my first moderately sized project which will eventually be a compilation of shit. Atm i have: Radar, Material/Wall hack, Rear view mirror, Server crasher (Spams big towers very quickly like stacker), Flashlight spammer, Xray, Esp/Names above heads. Although my methods are very messy and may seem.. somewhat bad to advanced coders looking over, just note that this is my first real project. ---------------------------------------- All i am posting at the moment is just the title system. Commands - Radar_Titles_SetCustomTitle <Playername> <Title> - Draws a 'title' on the player. I find it good when i want to remember people i don't know that well. Radar_Titles_GetNamesAndTitles - Gets the names and titles of all players who you have assigned titles to that are in the current server in the format of "Name: John Smith Title: Anonymous " Radar_Titles_Updatenames - If a name on the list is not the same but the persons unique ID is, then it will automatically update the persons name and rewrite it to the table. (This command may not work) This is only beta so if you find any bugs please post. Don't critisize my work, but i will benefit from constructive critisizm. *Also note, it's got radar at the start because thats what i originally built this script up from (My radar script) and cbf'd changing the name. [code] ////////////////////////////////////////////////////// ///////// CUSTOM CLIENT-SIDE TITLES ////////////////// ////////////////////////////////////////////////////// function SetCustomTitle(ply,cmd,args) if args[1] then if args[2] then for m,p in pairs(player.GetAll()) do for k,v in pairs(CustomTitles) do if string.find(string.lower(tostring(v)),string.lower(p:UniqueID())) then table.remove(CustomTitles,m-1) end end if string.find(string.lower(p:Nick()),string.lower(args[1])) then table.insert(CustomTitles,p:UniqueID().."'"..args[2].."'"..p:Nick() ) SaveTitles() end end end end end concommand.Add("Radar_Titles_SetCustomTitle",SetCustomTitle) function SaveTitles() file.Write("titles/customtitles.txt",util.TableToKeyValues(CustomTitles)) end local function LoadTitles() CustomTitles = util.KeyValuesToTable(file.Read("titles/customtitles.txt")) end hook.Add("Initialize","Loadcustomtitles",LoadTitles) function DrawCustomTitles() if GetConVarNumber("Radar_CustomTitles")>=1 then for l,pl in pairs(player.GetAll()) do for k,v in pairs(CustomTitles) do if string.find(string.lower(tostring(v)),string.lower(pl:UniqueID())) then draw.SimpleText(tostring(string.Explode("'",v)[2]),"scoreboardtextscaled5",((pl:GetPos()+Vector(0,0,54)):ToScreen()).x,((pl:GetPos()+Vector(0,0,54)):ToScreen()).y+15, team.GetColor(pl:Team()),1,1) end end end end end hook.Add("HUDPaint","Drawcustomtitlestopeople",DrawCustomTitles) function GetNamesAndTitles() for k,v in pairs(player.GetAll()) do for m,p in pairs(CustomTitles) do if string.find(tostring(p),v:UniqueID()) then LocalPlayer():ChatPrint("Name: "..v:Nick().." \nTitle: "..string.Explode("'",tostring(p))[2]) end end end end concommand.Add("Radar_Titles_GetNamesAndTitles",GetNamesAndTitles) function UpdateNames() for k,v in pairs(player.GetAll()) do for m,p in pairs(CustomTitles) do if string.find(tostring(p),v:UniqueID()) and !string.find(tostring(p),v:Nick()) then table.insert(CustomTitles,v:UniqueID().."'"..string.Explode("'",p)[2].."'"..v:Nick()) table.remove(CustomTitles,m) SaveTitles() end end end end concommand.Add("Radar_Titles_Updatenames",UpdateNames) [/code] * Fixed titles doubling up in an edit.
Good job! You really should tab your code though, makes it easier to read for you and anyone else.. [editline]11:52AM[/editline] [lua] ////////////////////////////////////////////////////// ///////// CUSTOM CLIENT-SIDE TITLES ////////////////// ////////////////////////////////////////////////////// function SetCustomTitle(ply,cmd,args) if args[1] then if args[2] then for m,p in ipairs(player.GetAll()) do for k,v in pairs(CustomTitles) do if string.find(string.lower(tostring(v)),string.lower(p:UniqueID())) then table.remove(CustomTitles,m) end end if string.find(string.lower(p:Nick()),string.lower(args[1])) then table.insert(CustomTitles,p:UniqueID().."'"..args[2].."'"..p:Nick() ) SaveTitles() end end end end end concommand.Add("Radar_Titles_SetCustomTitle",SetCustomTitle) function SaveTitles() file.Write("titles/customtitles.txt",util.TableToKeyValues(CustomTitles)) end local function LoadTitles() CustomTitles = util.KeyValuesToTable(file.Read("titles/customtitles.txt")) end hook.Add("Initialize","Loadcustomtitles",LoadTitles) function DrawCustomTitles() if GetConVarNumber("Radar_CustomTitles")>=1 then for l,pl in pairs(player.GetAll()) do for k,v in pairs(CustomTitles) do if string.find(string.lower(tostring(v)),string.lower(pl:UniqueID())) then draw.SimpleText(tostring(string.Explode("'",v)[2]),"scoreboardtextscaled",((pl:GetPos()+Vector(0,0,54)):ToScreen()).x, ((pl:GetPos()+Vector(0,0,54)):ToScreen()).y+15, team.GetColor(pl:Team()),1,1) end end end end end hook.Add("HUDPaint","Drawcustomtitlestopeople",DrawCustomTitles) function GetNamesAndTitles() for k,v in pairs(player.GetAll()) do for m,p in pairs(CustomTitles) do if string.find(tostring(p),v:UniqueID()) then LocalPlayer():ChatPrint("Name: "..v:Nick().." Title: "..string.Explode("'",tostring(p))[2]) end end end end concommand.Add("Radar_Titles_GetNamesAndTitles",GetNamesAndTitles) function UpdateNames() for k,v in pairs(player.GetAll()) do for m,p in pairs(CustomTitles) do if string.find(tostring(p),v:UniqueID()) and !string.find(tostring(p),v:Nick()) then table.insert(CustomTitles,v:UniqueID().."'"..string.Explode("'",p)[2].."'"..v:Nick()) table.remove(CustomTitles,m) end end end end concommand.Add("Radar_Titles_Updatenames",UpdateNames) [/lua]
Thank you. I really don't feel the need to tab my code because i haven't released any of my stuff, and i understand it fine without it being tabbed. Truth be told though, it is messy and confusing so i think i will ^.^ Thanks
Ownage, if you do any professional coding laying stuff out properly will save you allot of grief, part of my course that I am studying, the teachers hammered in that we follow coding standards. None the less, very nice code for a first release keep up the good work.
Yeh im not really going into pro coding just yet. Im only 14 and i think im doing pretty good at lua so far. This is my first release but i've made alot of stuff before that i haven't (and probably will not) release.
Just saying :) I wasn't criticising. Its a good habbit which does help. What do you use to edit code??
Notepad++ Very easy, but i just cbf with tabbing Im going to do it now after hearing that.
Sorry, you need to Log In to post a reply to this thread.