Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then AddCSLuaFile("autorun/sh_caddons.lua") return end
- require'glon'
- local TAG = "CAddons"
- module(TAG,package.seeall)
- addons = {
- ["smartsnap"]={
- name = "Smart Snap",
- desc = [[A grid, makes building stuff easier.
- Snaps cursor to corners and so forth.]],
- file = "caddons/smartsnap.lua",
- --url= "http://code.google.com/p/garrysmod-addons/source/browse/trunk/smartsnap/lua/autorun/client.lua",
- loadtype = 2,
- },
- ["picker2"]={
- name = "Picker 2",
- desc = [[Shows info about ents.
- Tons of uses.
- Usage: bind key picker2 (toggle picker)
- bind key +picker2_copy (Copies the highlighted entry to the clipboard.
- Hold down, move mouse over label, release.)
- Console Variables being with picker2_
- ]],
- file = "caddons/picker2.lua",
- --url = "http://code.google.com/p/tldevtools/source/browse/trunk/picker/lua/autorun/client/rs_picker.lua",
- loadtype = 1,
- },
- }
- function IncludeAddon(tag)
- Msg"[CAddons] "print("Loading ", tag)
- local data = addons[tag] or data
- if data and !data.loaded then
- if data.file then
- data.loaded = true
- include(data.file)
- elseif data.url then
- ErrorNoHalt("CAddon load failed, url loading not implemented",url," ",tag,"\n")
- else
- ErrorNoHalt("CAddon Could not load ",tag,"\n")
- end
- end
- end
- -- Startup init
- local autoloadinfo = {}
- local glonfile = file.Read('caddons_data.txt')
- if glonfile then
- autoloadinfo = glon.decode( glonfile )
- end
- function SetAutorun(tag,autorun)
- local data = addons[tag]
- data.autorun=autorun
- if autorun then
- autorun=true
- else
- autorun=nil
- end
- autoloadinfo[ tag ] = autorun
- file.Write('caddons_data.txt', glon.encode( autoloadinfo ) )
- end
- for tag, data in pairs(addons) do
- local info = autoloadinfo[tag]
- if info==true then
- data.autorun = true
- Msg( "Autoloading enabled for " .. tostring( tag ) .. ".")
- end
- end
- hook.Add("PopulateToolMenu", TAG, function() spawnmenu.AddToolMenuOption("Utilities", "Clientside-Addons", "asd?", "Load", "", "", function(panel)
- for tag,data in pairs(addons) do
- local button = panel:AddControl("DButton", {})
- button:SetText(data.name)
- button:SetToolTip(data.desc)
- local function loadfunc()
- local menu = DermaMenu()
- if not data.loaded then
- menu:AddOption("Load", function() IncludeAddon(tag) end )
- end
- if data.autorun then
- menu:AddOption("Disable Autorun", function() SetAutorun(tag,false) end )
- else
- menu:AddOption("Enable Autorun", function() SetAutorun(tag,true) end )
- end
- menu:Open()
- end
- button.DoClick = loadfunc
- end
- end) end)
- for tag, data in pairs(addons) do
- if data.autorun and data.loadtype == 1 then
- IncludeAddon( tag )
- end
- end
- hook.Add("InitPostEntity", TAG, function() hook.Remove("InitPostEntity", TAG) -- confusing, eh? :v
- timer.Simple(5,function()
- for tag, data in pairs(addons) do
- if data.autorun and data.loadtype == 2 then
- IncludeAddon( tag )
- end
- end
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment