Creating a plugin system

Im trying to create a plugin system for my gamemode so people can add there own mini games. Im trying to set it up so you have a folder in the main gamemode foler called plugins, so that the gamemode will scan and load the plugins depnding what is picked. I was thinking of doing it like Fretta where it does GM.canuseFlashllight = true and it knows what to do, but first things first im dont even know where to start, I have been looking at Ass mod but that seems over complicated for what I need, so can anyone give me a place to start or what to do. Thanks

A plugin system is not basic; face it, it will not be easy.

To get you started:
[lua]
local list = file.FindDir(“plugins/*”)
for _, dir in pairs(list) do
– do something with the directory
end[/lua]
This gets all the plugin directories. To get specific files, use **[File.Find

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=File.Find)**

well I know its not basic but hopfully it will improve my lua, thanks for the help

I personally do it like this.

[lua]function FlapMin.RegisterDirectory(path , client , shared)
for k , v in pairs(file.Find("…/lua/"…path…"/"…"*.lua")) do
if client and SERVER then
AddCSLuaFile(path…"/"…v)
elseif client then
include(path…"/"…v)
MsgN(“FlapMin: Loaded file '”…path…"/"…v…"’.")
elseif shared then
if SERVER then
AddCSLuaFile(path…"/"…v)
end
include(path…"/"…v)
MsgN(“FlapMin: Loaded file '”…path…"/"…v…"’.")
elseif not client and not shared and SERVER then
include(path…"/"…v)
MsgN(“FlapMin: Loaded file '”…path…"/"…v…"’.")
end
end
end

function FlapMin.RegisterSingleFile(path , client , shared)
if client and SERVER then
AddCSLuaFile(path)
elseif client then
include(path)
elseif shared then
if SERVER then
AddCSLuaFile(path)
end
include(path)
MsgN(“FlapMin: Loaded file '”…path…"/"…v…"’.")
elseif not client and not shared and SERVER then
include(path)
MsgN(“FlapMin: Loaded file '”…path…"/"…v…"’.")
end
end

FlapMin.RegisterDirectory(“FlapMin” , false , true)
FlapMin.RegisterDirectory(“FlapMin/Server”)
FlapMin.RegisterDirectory(“FlapMin/Client” , true , false)
FlapMin.RegisterDirectory(“FlapMin/Extensions” , false, true)[/lua]

Then you need to write register functions for plugin tables, and a generic format for plugin tables.