Sorry if this is on the wiki already. I need to know how to load a folder of lua scripts and use AddCSLuaFile. i remember something about using a for loop and a table but i just can't remember.
[lua]
for k, v in pairs(file.FindInLua('directory/*.lua'))do
AddCSLuaFile(v);
end
[/lua]
i may be wrong
[editline]10th January 2011[/editline]
sorry, made a mistake in code, but it should work
[lua]
for k,v in pairs(file.FindInLua("directory/*.lua")) do
if not string.find(v,"cl_") == nil then
if SERVER then
AddCSLuaFile(v)
elseif CLIENT then
include(v)
end
elseif not string.find(v,"sv_") == nil then
if SERVER then
include(v)
end
end
end
[/lua]
Untested.
Add cl_ to clientside files and sv_ to serverside files.
Your code looks backwards, the first if statement is like... if its not a clientside file, AddCSLuaFile()... what? you just added serverside files to be downloaded to the client... i might be wrong I have a massive hangover
the first statement is checking to make sure its not nil
Well he did say untested. The concept looks solid though.
[QUOTE=Andriko1;27322857]Your code looks backwards, the first if statement is like... if its not a clientside file, AddCSLuaFile()... what? you just added serverside files to be downloaded to the client... i might be wrong I have a massive hangover[/QUOTE]
It's the same as.
[CODE]
if !(string.find(v,"cl_") == nil) then
[/CODE]
or
[CODE]
if(string.find(v,"cl_") != nil)then
[/CODE]
what would you do for the shared files?
[lua]
function AddDir(path , send , shared, recursive)
for k , v in pairs(file.FindInLua(path.."*")) do
if not file.IsDir(path..v) then
if send and SERVER then
AddCSLuaFile(path..v)
elseif not send then
include(path..v)
end
if shared then
include(path..v)
end
elseif recursive then
AddDir(path..v , send , shared , recursive)
end
end
end[/lua]
[lua]-- Shared
AddDir("shared/" , true , true , true)
-- Server
AddDir("server/" , false , false , true)
-- Client
AddDir("client/" , true , false , true)[/lua]
You need to have client/server/shared scripts in separate folders for this to be useful.
Sorry, you need to Log In to post a reply to this thread.