Python1320

Python1320

Feb 24th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. if SERVER then AddCSLuaFile("autorun/sh_caddons.lua") return end
  2. require'glon'
  3. local TAG = "CAddons"
  4. module(TAG,package.seeall)
  5.  
  6.  
  7.     addons = {
  8.        
  9.         ["smartsnap"]={
  10.             name = "Smart Snap",
  11.             desc = [[A grid, makes building stuff easier.
  12. Snaps cursor to corners and so forth.]],
  13.             file = "caddons/smartsnap.lua",
  14.             --url= "http://code.google.com/p/garrysmod-addons/source/browse/trunk/smartsnap/lua/autorun/client.lua",
  15.             loadtype = 2,
  16.         },
  17.         ["picker2"]={
  18.             name = "Picker 2",
  19.             desc = [[Shows info about ents.
  20. Tons of uses.
  21. Usage: bind key picker2 (toggle picker)
  22. bind key +picker2_copy (Copies the highlighted entry to the clipboard.
  23. Hold down, move mouse over label, release.)
  24.  
  25. Console Variables being with picker2_
  26. ]],
  27.             file = "caddons/picker2.lua",
  28.             --url = "http://code.google.com/p/tldevtools/source/browse/trunk/picker/lua/autorun/client/rs_picker.lua",
  29.             loadtype = 1,
  30.         },
  31.        
  32.     }
  33.    
  34.    
  35.     function IncludeAddon(tag)
  36.         Msg"[CAddons] "print("Loading ", tag)
  37.         local data = addons[tag] or data
  38.         if data and !data.loaded then
  39.             if data.file then
  40.                 data.loaded = true
  41.                 include(data.file)
  42.             elseif data.url then
  43.                 ErrorNoHalt("CAddon load failed, url loading not implemented",url," ",tag,"\n")
  44.             else
  45.                 ErrorNoHalt("CAddon Could not load ",tag,"\n")
  46.             end
  47.         end
  48.     end
  49.    
  50.  
  51.    
  52.     -- Startup init
  53.     local autoloadinfo = {}
  54.     local glonfile = file.Read('caddons_data.txt')
  55.     if glonfile then
  56.         autoloadinfo = glon.decode( glonfile )
  57.     end
  58.  
  59.     function SetAutorun(tag,autorun)
  60.         local data = addons[tag]
  61.         data.autorun=autorun
  62.        
  63.         if autorun then
  64.             autorun=true
  65.         else
  66.             autorun=nil
  67.         end
  68.        
  69.         autoloadinfo[ tag ] = autorun
  70.  
  71.         file.Write('caddons_data.txt', glon.encode( autoloadinfo ) )
  72.        
  73.     end
  74.    
  75.    
  76.     for tag, data in pairs(addons) do
  77.         local info = autoloadinfo[tag]
  78.         if info==true then
  79.             data.autorun = true
  80.             Msg( "Autoloading enabled for " .. tostring( tag ) .. ".")
  81.         end
  82.     end
  83.        
  84.     hook.Add("PopulateToolMenu", TAG, function() spawnmenu.AddToolMenuOption("Utilities", "Clientside-Addons", "asd?", "Load", "", "", function(panel)
  85.  
  86.             for tag,data in pairs(addons) do
  87.            
  88.                 local button = panel:AddControl("DButton", {})
  89.                 button:SetText(data.name)
  90.                 button:SetToolTip(data.desc)
  91.                 local function loadfunc()
  92.                     local menu = DermaMenu()
  93.                        
  94.                         if not data.loaded then
  95.                             menu:AddOption("Load", function() IncludeAddon(tag) end )
  96.                         end
  97.                        
  98.                         if data.autorun then
  99.                             menu:AddOption("Disable Autorun", function() SetAutorun(tag,false) end )
  100.                         else
  101.                             menu:AddOption("Enable Autorun", function() SetAutorun(tag,true) end )
  102.                         end
  103.                        
  104.                     menu:Open()
  105.                 end
  106.                 button.DoClick = loadfunc
  107.                
  108.             end
  109.        
  110.     end) end)
  111.  
  112.     for tag, data in pairs(addons) do
  113.         if data.autorun and data.loadtype == 1 then
  114.             IncludeAddon( tag )
  115.         end
  116.     end
  117.    
  118.     hook.Add("InitPostEntity", TAG, function() hook.Remove("InitPostEntity", TAG) -- confusing, eh? :v
  119.         timer.Simple(5,function()
  120.             for tag, data in pairs(addons) do
  121.                 if data.autorun and data.loadtype == 2 then
  122.                     IncludeAddon( tag )
  123.                 end
  124.             end
  125.         end)
  126.     end)
Advertisement
Add Comment
Please, Sign In to add comment