I simply want to make a module file that includes plugins/modules from a folder.
[CODE]gamemode/modules.lua
gamemode/modules/testmodule.lua[/CODE]
I suppose you will need testmodule.lua to call a module register function.
Can anyone give me a simply module system to start off with?
My current one dosen't work, but it has a register function that should
register the name, version and lua file of a module. It also includes if the
module is client side. It doesn't put the modules into a table.
So can sombody please give me the base code for a very simple module system?
Take a look at Deco's [url=http://www.facepunch.com/showthread.php?t=806666]interpolation module[/url], just to see how he set it up.
Thanks, I'll have a look at this.
[editline]07:21AM[/editline]
Oops, I didn't describe it properly.
A plugin system really, Like ASSMOD.
Anybody know how to do that?
I'll throw you some code from my admin mod that I was working on a while back..
This will load all the lua files in the plugins directory:
[lua]
Msg("||================PLUGINS=================||\n")
POAM.plugList = file.Find("../lua/plugins/*.lua")
for k,v in pairs(POAM.plugList) do
include("plugins/"..v)
end
Msg("||========================================||\n")
[/lua]
This will actually add the commands to be used:
[lua]
function POAM.Register(cmd)
if !POAM.Cmd[string.lower(cmd.Name)] then
local tName = string.lower(cmd.Name)
POAM.Cmd[tName] = {}
POAM.Cmd[tName].Name = cmd.Name
POAM.Cmd[tName].Flag = cmd.Flag
POAM.Cmd[tName].Desc = cmd.Desc
POAM.Cmd[tName].Command = cmd.Command
POAM.Cmd[tName].Args = cmd.Args
Msg("|| Loaded Plugin: "..cmd.Name.."\n")
end
end
[/lua]
This is an example command (kick):
[lua]
local COMMAND = {}
COMMAND.Name = "Kick"
COMMAND.Flag = "M"
COMMAND.Desc = "Kick a player for stuff and things."
COMMAND.Args = "Player - Reason(Optional)"
COMMAND.Reason = "Unspecified"
function COMMAND.Command(ply,args)
if args[3] then COMMAND.Reason = args[3] end
if ply:IsPlayer() then
COMMAND.ply = ply:Nick()
else
COMMAND.ply = "Console"
end
local plr = POAM.FindPlayer(ply,args[2])
if plr then
plr:Kick(COMMAND.Reason)
for k,v in ipairs(player.GetAll()) do
v:ChatPrint(COMMAND.ply.." has kicked "..plr:Nick().." for: "..COMMAND.Reason)
v:SendLua("chat.PlaySound()")
end
end
end
POAM.Register(COMMAND)
[/lua]
This is the findplayer command. I'm sure there's a better, faster way to do it. I made it a while ago:
[lua]
function POAM.FindPlayer(ply,name)
local lNames = {}
for k,v in ipairs(player.GetAll()) do
if string.find(string.lower(v:Nick()),string.lower(name)) != nil then
table.Add(lNames,{v})
end
end
if #lNames > 1 then
if ply:IsPlayer() then
ply:ChatPrint("There are more than one players with "..name.." in their name. Try being more specific!")
else
print("There are more than one players with "..name.." in their name. Try being more specific!")
end
return nil
elseif #lNames == 0 then
if ply:IsPlayer() then
ply:ChatPrint("No players found with "..name.." in their name!")
else
print("No players found with "..name.." in their name!")
end
return nil
else
return lNames[1]
end
end
[/lua]
Hope this helps :)
Hehehe. Poam.
Awsome, thanks. It works perefectly. You can take that as a question answered
It only worked when I got removed the POAM tags and added a few things.
Sorry, you need to Log In to post a reply to this thread.