shadowndacorner

Base code for plugins system

Apr 3rd, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. -- All of this is from my admin mod
  2.  
  3. -- RegisterPlugin
  4. -- Not really necessary, but helps to make it simpler to add shit
  5. function moderari.RegisterPlugin(name, tab)
  6.     name=name or tab.Name or nil
  7.     if !name then return end
  8.     moderari.Plugins[name]=tab
  9.     moderari.Plugins[name].ChatText=tab.ChatText or function() return nil end
  10.     --moderari.Plugins[name].Command=string.lower(moderari.Plugins[name].Command)
  11.     print("Plugin \""..name.."\" loaded!")
  12. end
  13. --Example plugin
  14. local PLUGIN={}
  15.  
  16. PLUGIN.Name="Ban"
  17. PLUGIN.Command="ban"
  18. PLUGIN.CallableOnPlayers=true
  19. PLUGIN.Immunity=40
  20. PLUGIN.Category="Administration"
  21.  
  22. PLUGIN.OverrideMenuSelect=function(ply, target)
  23.     --function here
  24. end
  25.  
  26. PLUGIN.OnCall=function(ply, players, args)
  27.     --function
  28. end
  29. moderari.RegisterPlugin("Ban", PLUGIN)
  30.  
  31. -- Loading files from a folder
  32. function moderari.LoadPlugins()
  33.     moderari.Plugins={}
  34.     for f, v in pairs(file.FindInLua("mr_plugins/*.lua")) do
  35.         if string.Left(v, 2)=="sh" or string.Left(v, 2)=="cl" then
  36.             if !moderari.InitPluginsLoaded then
  37.                 AddCSLuaFile("mr_plugins/"..v)
  38.                 print("mr_plugins/"..v.." loaded clientside.")
  39.                 moderari.InitPluginsLoaded=true
  40.             else
  41.                 SendLuaToClient("mr_plugins/"..v)
  42.                 print("mr_plugins/"..v.." loaded clientside.")
  43.             end
  44.         end
  45.         if SERVER then
  46.             if string.Left(v, 2)!="cl" then
  47.                 include("mr_plugins/"..v)
  48.             end
  49.         else
  50.             include("mr_plugins/"..v)
  51.         end
  52.     end
  53. end
  54. hook.Add("Initialize", "loadModerariPlugins", function()
  55.     MsgN("======================")
  56.     moderari.LoadPlugins()
  57.     MsgN("======================")
  58.     moderari.InitPluginsLoaded=true
  59. end)
Advertisement
Add Comment
Please, Sign In to add comment